parent
ad8905312f
commit
f32ae1f28a
@ -0,0 +1,36 @@ |
||||
<?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\DepositRecord; |
||||
use app\common\model\user\DepositRecordDaily; |
||||
use app\common\model\user\UserAssets; |
||||
use app\common\model\user\UserRecharge; |
||||
use app\common\repositories\store\order\StoreOrderRepository; |
||||
|
||||
class DepositRecordDailyDao extends BaseDao |
||||
{ |
||||
protected function getModel(): string |
||||
{ |
||||
return DepositRecordDaily::class; |
||||
} |
||||
|
||||
public function createOrderId($uid) |
||||
{ |
||||
$count = (int)DepositRecord::getDB()->where('uid', $uid)->where('create_time', '>=', date("Y-m-d"))->where('create_time', '<', date("Y-m-d", strtotime('+1 day')))->count(); |
||||
return StoreOrderRepository::TYPE_SN_USER_DEPOSIT . date('YmdHis', time()) . ($uid . $count); |
||||
} |
||||
|
||||
public function getSum($uid, $field){ |
||||
return DepositRecord::where('uid', $uid)->where('status', 1)->sum($field); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?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\UserGroupDaily; |
||||
|
||||
class UserGroupDailyDao extends BaseDao |
||||
{ |
||||
protected function getModel(): string |
||||
{ |
||||
return UserGroupDaily::class; |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?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 DepositRecordDaily extends BaseModel |
||||
{ |
||||
|
||||
public static function tablePk(): string |
||||
{ |
||||
return 'id'; |
||||
} |
||||
|
||||
public static function tableName(): string |
||||
{ |
||||
return 'deposit_record_daily'; |
||||
} |
||||
} |
@ -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\model\user; |
||||
|
||||
use app\common\model\BaseModel; |
||||
|
||||
|
||||
class UserGroupDaily extends BaseModel |
||||
{ |
||||
|
||||
public static function tablePk(): string |
||||
{ |
||||
return 'id'; |
||||
} |
||||
|
||||
public static function tableName(): string |
||||
{ |
||||
return 'user_group_daily'; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,93 @@ |
||||
<?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\repositories\user; |
||||
|
||||
use app\common\dao\user\DepositRecordDailyDao; |
||||
use app\common\dao\user\DepositRecordDao; |
||||
use app\common\model\user\DepositRecord; |
||||
use app\common\model\user\DepositRecordDaily; |
||||
use app\common\model\user\User; |
||||
use app\common\model\user\UserRecharge; |
||||
use app\common\repositories\BaseRepository; |
||||
use app\common\repositories\store\DepositRepository; |
||||
use crmeb\jobs\SendSmsJob; |
||||
use crmeb\services\PayService; |
||||
use think\facade\Db; |
||||
use think\facade\Queue; |
||||
|
||||
/** |
||||
* Class DepositRecordDailyRepository |
||||
* @package app\common\repositories\user |
||||
* @author xaboy |
||||
* @day 2020/6/2 |
||||
* @mixin DepositRecordDaily |
||||
*/ |
||||
class DepositRecordDailyRepository extends BaseRepository |
||||
{ |
||||
/** |
||||
* UserRechargeRepository constructor. |
||||
* @param DepositRecordDailyDao $dao |
||||
*/ |
||||
public function __construct(DepositRecordDailyDao $dao) |
||||
{ |
||||
$this->dao = $dao; |
||||
} |
||||
|
||||
/** |
||||
* notes 用户等级每日分发钻石 |
||||
* @create 2024/4/18 14:08 |
||||
* @update 2024/4/18 14:08 |
||||
* @author zhangkxiang |
||||
* @editor |
||||
*/ |
||||
public function runDaily() |
||||
{ |
||||
$depositList = app(DepositRepository::class)->selectWhere([]); |
||||
if($depositList->isEmpty()) return; |
||||
$depositList = array_column($depositList->toArray(), null, 'id'); |
||||
|
||||
$where = array(); |
||||
$where[] = array('status', 'in', [1,2]); |
||||
$recordList = app(DepositRecordRepository::class)->selectWhere($where); |
||||
|
||||
$userAssets = app(UserAssetsRepository::class); |
||||
|
||||
foreach ($recordList as $record) { |
||||
$item = $this->getItem($record['uid'], $record['id']); |
||||
$currentDeposit = $depositList[$record['deposit_id']]; |
||||
|
||||
if(time() - strtotime($record['create_time']) > 86400 * $currentDeposit['cycle'] and $record['status'] == 1){ |
||||
$record->status = 2; |
||||
$record->save(); |
||||
} |
||||
|
||||
if ($item['diamond'] < $currentDeposit['diamond_max']) { |
||||
$count = min($currentDeposit['diamond'], $currentDeposit['diamond_max'] - $item['diamond']); |
||||
$item->diamond = $item['diamond'] + $count; |
||||
$item->save(); |
||||
$userAssets->daily($record['uid'], $count, UserAssetsLogRepository::DIAMOND_DEPOSIT); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public function getItem($uid, $recordId) |
||||
{ |
||||
return $this->dao->findOrCreate([ |
||||
'uid' => $uid, |
||||
'record_id' => $recordId |
||||
]); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,74 @@ |
||||
<?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\repositories\user; |
||||
|
||||
use app\common\dao\user\UserGroupDailyDao; |
||||
use app\common\model\user\DepositRecordDaily; |
||||
use app\common\repositories\BaseRepository; |
||||
|
||||
/** |
||||
* Class UserGroupDailyRepository |
||||
* @package app\common\repositories\user |
||||
* @author xaboy |
||||
* @day 2020/6/2 |
||||
* @mixin DepositRecordDaily |
||||
*/ |
||||
class UserGroupDailyRepository extends BaseRepository |
||||
{ |
||||
/** |
||||
* UserGroupDailyRepository constructor. |
||||
* @param UserGroupDailyDao $dao |
||||
*/ |
||||
public function __construct(UserGroupDailyDao $dao) |
||||
{ |
||||
$this->dao = $dao; |
||||
} |
||||
|
||||
/** |
||||
* notes 用户等级每日分发钻石 |
||||
* @create 2024/4/18 14:08 |
||||
* @update 2024/4/18 14:08 |
||||
* @author zhangkxiang |
||||
* @editor |
||||
*/ |
||||
public function runDaily(){ |
||||
$userList = app(UserRepository::class)->selectAllGroupUser(); |
||||
$groupList = app(UserGroupRepository::class)->getList([], 0, 10); |
||||
$groupList = $groupList['list']->toArray(); |
||||
$groupList = array_column($groupList, null, 'group_id'); |
||||
|
||||
$userAssets = app(UserAssetsRepository::class); |
||||
|
||||
foreach ($userList as $user){ |
||||
$item = $this->getItem($user['uid'], $user['group_id']); |
||||
$currentGroup = $groupList[$user['group_id']]; |
||||
if($item['diamond'] < $currentGroup['diamond_max']){ |
||||
$count = min($currentGroup['diamond'], $currentGroup['diamond_max'] - $item['diamond']); |
||||
$item->diamond = $item['diamond'] + $count; |
||||
$item->save(); |
||||
$userAssets->daily($user['uid'], $count); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public function getItem($uid, $groupId){ |
||||
return $this->dao->findOrCreate([ |
||||
'uid' => $uid, |
||||
'group_id' => $groupId |
||||
]); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,44 @@ |
||||
<?php |
||||
/** |
||||
* CustomizePaySuccess.php |
||||
* 文件描述 |
||||
* Created on 2024/3/13 23:02 |
||||
* Created by zhangkaixiang |
||||
*/ |
||||
|
||||
namespace crmeb\listens\task; |
||||
|
||||
|
||||
use app\common\repositories\user\DepositRecordDailyRepository; |
||||
use app\common\repositories\user\UserGroupDailyRepository; |
||||
use crmeb\interfaces\ListenerInterface; |
||||
use crmeb\services\TimerService; |
||||
use think\facade\Log; |
||||
|
||||
class CustomizeTask extends TimerService implements ListenerInterface |
||||
{ |
||||
|
||||
public function handle($event): void |
||||
{ |
||||
$this->tick(1000 * 60, function () { |
||||
if(date('i') == 00){ |
||||
Log::info('整点任务开始执行'); |
||||
} |
||||
if (date('H:i') == '00:10') { |
||||
/** |
||||
* @var UserGroupDailyRepository $groupAssets |
||||
*/ |
||||
$groupAssets = app()->make(UserGroupDailyRepository::class); |
||||
$groupAssets->runDaily(); |
||||
|
||||
/** |
||||
* @var DepositRecordDailyRepository $deposit |
||||
*/ |
||||
$deposit = app()->make(DepositRecordDailyRepository::class); |
||||
$deposit->runDaily(); |
||||
} |
||||
}); |
||||
|
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue