分红点获得奖励积分超过配置值后减少

main
fengxinyhyl 7 months ago
parent 4b0283071a
commit 1f65e5c2d4
  1. 30
      app/common/dao/user/UserAssetsShareDao.php
  2. 31
      app/common/model/user/UserAssetsShare.php
  3. 19
      app/common/repositories/user/UserAssetsRepository.php

@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\UserAssetsShare;
class UserAssetsShareDao extends BaseDao
{
protected function getModel(): string
{
return UserAssetsShare::class;
}
public function add($uid, $spread_uid, $old_spread_uid, $admin_id = 0)
{
$this->create(compact('uid', 'spread_uid', 'admin_id', 'old_spread_uid'));
}
}

@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\user;
use app\common\model\BaseModel;
class UserAssetsShare extends BaseModel
{
public static function tablePk(): ?string
{
return 'uid';
}
public static function tableName(): string
{
return 'user_assets_share';
}
}

@ -14,6 +14,7 @@ namespace app\common\repositories\user;
use app\common\dao\user\UserAssetsDao;
use app\common\dao\user\UserAssetsShareDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderBaseRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
@ -27,11 +28,12 @@ use think\db\exception\ModelNotFoundException;
*/
class UserAssetsRepository extends BaseRepository
{
protected $shareDao = null;
public function __construct(UserAssetsDao $dao)
public function __construct(UserAssetsDao $dao, UserAssetsShareDao $shareDao)
{
$this->dao = $dao;
$this->shareDao = $shareDao;
}
public function getConfig()
@ -41,7 +43,7 @@ class UserAssetsRepository extends BaseRepository
* @var GroupDataRepository $groupDataRepository
*/
$groupDataRepository = app()->make(GroupDataRepository::class);
$config = $groupDataRepository->getGroupDataLst(0, 100, 1, 100);
$config = $groupDataRepository->getGroupDataLst(0, 100, 1, 200);
return array_column($config['list'], "value", 'key');
}
@ -196,6 +198,17 @@ class UserAssetsRepository extends BaseRepository
// 增加福利积分
$assets = $this->assets($item['uid']);
$this->update($item['uid'], array('welfare' => $assets['welfare'] + $welfare));
// 计算分红点获取积分统计
$shareStatistics = $this->shareDao->findOrCreate(['uid' => $item['uid']]);
$shareStatistics->current = $shareStatistics->current + $welfare;
$shareStatistics->save();
if($shareStatistics->current - $shareStatistics->last_point > $config['share_get_welfare_limit'] and $config['share_get_welfare_limit']){
$share = floor(($shareStatistics->current - $shareStatistics->last_point) / $config['share_get_welfare_limit']);
$shareStatistics->last_point = $shareStatistics->last_point + $config['share_get_welfare_limit'] * $share;
$shareStatistics->save();
$this->update($item['uid'], array('share_point' => $assets['share_point'] - $share));
}
}
// 增加记录

Loading…
Cancel
Save