计算惠通增值

main
fengxinyhyl 9 months ago
parent a628d16511
commit b9678e445b
  1. 4
      app/common/dao/user/UserAssetsDao.php
  2. 49
      app/common/repositories/system/HuitongRepository.php
  3. 28
      app/common/repositories/user/UserAssetsRepository.php
  4. 7
      crmeb/listens/task/CustomizeTask.php

@ -38,4 +38,8 @@ class UserAssetsDao extends BaseDao
} }
return array('total'=>0, 'list'=>[]); return array('total'=>0, 'list'=>[]);
} }
public function getTotalHuitong(){
return UserAssets::sum('huitong');
}
} }

@ -14,6 +14,8 @@ namespace app\common\repositories\system;
use app\common\dao\store\order\StoreOrderDao; use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\system\HuitongDao; use app\common\dao\system\HuitongDao;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderBaseRepository;
use app\common\repositories\user\UserAssetsRepository;
/** /**
@ -34,4 +36,51 @@ class HuitongRepository extends BaseRepository
$this->dao = $dao; $this->dao = $dao;
} }
public function dayStatistics()
{
/**
* @var UserAssetsRepository $userAssets
*/
$userAssets = app()->make(UserAssetsRepository::class);
$config = $userAssets->getConfig();
/**
* @var StoreOrderBaseRepository $orderBase
*/
$orderBase = app()->make(StoreOrderBaseRepository::class);
$count = $orderBase->getTotalBase();
if (empty($count)) {
return;
}
$base = round($config['huitong_add'] * $count / 100, 2);
if ($base < 0.01) {
$base = 0.01;
}
$last = $this->dao->getLastHuitong();
if (empty($last)) {
$huitong = 1;
} else {
$huitong = $last['current'];
}
$totalHuitong = $userAssets->getTotalHuitong();
$add = round($base / $totalHuitong, 2);
if ($add < 0.01) {
$add = 0.01;
}
$this->dao->create([
'date' => date('Y-m-d'),
'current' => $huitong + $add,
'ext' => json_encode(array(
'base' => $base,
'huitong' => $huitong,
'total' => $totalHuitong,
)),
]);
}
} }

@ -33,13 +33,14 @@ class UserAssetsRepository extends BaseRepository
$this->dao = $dao; $this->dao = $dao;
} }
public function getConfig(){ public function getConfig()
{
// 配置信息 // 配置信息
/** /**
* @var GroupDataRepository $groupDataRepository * @var GroupDataRepository $groupDataRepository
*/ */
$groupDataRepository = app()->make(GroupDataRepository::class); $groupDataRepository = app()->make(GroupDataRepository::class);
$config = $groupDataRepository->getGroupDataLst(0, 100, 1, 100); $config = $groupDataRepository->getGroupDataLst(0, 100, 1, 100);
return array_column($config['list'], "value", 'key'); return array_column($config['list'], "value", 'key');
} }
@ -153,33 +154,34 @@ class UserAssetsRepository extends BaseRepository
* @author zhangkxiang * @author zhangkxiang
* @editor * @editor
*/ */
public function sharePoint(){ public function sharePoint()
{
$config = $this->getConfig(); $config = $this->getConfig();
/** /**
* @var StoreOrderBaseRepository $orderBase * @var StoreOrderBaseRepository $orderBase
*/ */
$orderBase = app()->make(StoreOrderBaseRepository::class); $orderBase = app()->make(StoreOrderBaseRepository::class);
$count = $orderBase->getTotalBase(date('Y-m-d', strtotime('-1day'))); $count = $orderBase->getTotalBase(date('Y-m-d', strtotime('-1day')));
if(empty($count)){ if (empty($count)) {
return ; return;
} }
$shareData = $this->dao->getShareData(); $shareData = $this->dao->getShareData();
if(!$shareData['total']){ if (!$shareData['total']) {
return ; return;
} }
$base = round($config['share_award'] * $count / 100, 2); $base = round($config['share_award'] * $count / 100, 2);
if($base < 0.01){ if ($base < 0.01) {
$base = 0.01; $base = 0.01;
} }
$logList = array(); $logList = array();
foreach ($shareData['list'] as $item){ foreach ($shareData['list'] as $item) {
$welfare = $base / $shareData['total'] * $item['share_point']; $welfare = $base / $shareData['total'] * $item['share_point'];
if($welfare < 0.01){ if ($welfare < 0.01) {
$welfare = 0.01; $welfare = 0.01;
} }
$logList[] = array( $logList[] = array(
'uid' => $item['uid'], 'uid' => $item['uid'],
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_WELFARE, 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_WELFARE,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_GET, 'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_GET,
@ -187,7 +189,7 @@ class UserAssetsRepository extends BaseRepository
'count' => $welfare, 'count' => $welfare,
); );
// 增加福利积分 // 增加福利积分
$this->changeEvent($item['uid'],UserAssetsLogRepository::STATUS_SUCCESS, array('welfare' => $welfare)); $this->changeEvent($item['uid'], UserAssetsLogRepository::STATUS_SUCCESS, array('welfare' => $welfare));
} }

@ -9,6 +9,7 @@
namespace crmeb\listens\task; namespace crmeb\listens\task;
use app\common\repositories\system\HuitongRepository;
use app\common\repositories\user\UserAssetsRepository; use app\common\repositories\user\UserAssetsRepository;
use crmeb\interfaces\ListenerInterface; use crmeb\interfaces\ListenerInterface;
use crmeb\services\TimerService; use crmeb\services\TimerService;
@ -29,5 +30,11 @@ class CustomizeTask implements ListenerInterface
*/ */
$userAssets = app()->make(UserAssetsRepository::class); $userAssets = app()->make(UserAssetsRepository::class);
$userAssets->sharePoint(); $userAssets->sharePoint();
/**
* @var HuitongRepository $huitong
*/
$huitong = app()->make(HuitongRepository::class);
$huitong->dayStatistics();
} }
} }

Loading…
Cancel
Save