From 1f65e5c2d46c6798cbc740f01d721dfa645f93ed Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Tue, 23 Apr 2024 14:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=BA=A2=E7=82=B9=E8=8E=B7=E5=BE=97?= =?UTF-8?q?=E5=A5=96=E5=8A=B1=E7=A7=AF=E5=88=86=E8=B6=85=E8=BF=87=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=80=BC=E5=90=8E=E5=87=8F=E5=B0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/UserAssetsShareDao.php | 30 ++++++++++++++++++ app/common/model/user/UserAssetsShare.php | 31 +++++++++++++++++++ .../user/UserAssetsRepository.php | 19 ++++++++++-- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 app/common/dao/user/UserAssetsShareDao.php create mode 100644 app/common/model/user/UserAssetsShare.php diff --git a/app/common/dao/user/UserAssetsShareDao.php b/app/common/dao/user/UserAssetsShareDao.php new file mode 100644 index 0000000..bf2a69e --- /dev/null +++ b/app/common/dao/user/UserAssetsShareDao.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + + +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')); + } +} diff --git a/app/common/model/user/UserAssetsShare.php b/app/common/model/user/UserAssetsShare.php new file mode 100644 index 0000000..b3d6b91 --- /dev/null +++ b/app/common/model/user/UserAssetsShare.php @@ -0,0 +1,31 @@ + +// +---------------------------------------------------------------------- + + +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'; + } + +} diff --git a/app/common/repositories/user/UserAssetsRepository.php b/app/common/repositories/user/UserAssetsRepository.php index 454ad65..a3dd79c 100644 --- a/app/common/repositories/user/UserAssetsRepository.php +++ b/app/common/repositories/user/UserAssetsRepository.php @@ -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)); + } } // 增加记录