添加定时任务

main
fengxinyhyl 10 months ago
parent ad8905312f
commit f32ae1f28a
  1. 36
      app/common/dao/user/DepositRecordDailyDao.php
  2. 22
      app/common/dao/user/UserGroupDailyDao.php
  3. 28
      app/common/model/user/DepositRecordDaily.php
  4. 30
      app/common/model/user/UserGroupDaily.php
  5. 93
      app/common/repositories/user/DepositRecordDailyRepository.php
  6. 4
      app/common/repositories/user/LotteryRecordRepository.php
  7. 4
      app/common/repositories/user/UserAssetsLogRepository.php
  8. 16
      app/common/repositories/user/UserAssetsRepository.php
  9. 74
      app/common/repositories/user/UserGroupDailyRepository.php
  10. 6
      app/common/repositories/user/UserRepository.php
  11. 24
      app/controller/api/Auth.php
  12. 57
      app/controller/api/user/User.php
  13. 1
      app/event.php
  14. 44
      crmeb/listens/task/CustomizeTask.php
  15. 3
      route/api.php

@ -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
]);
}
}

@ -43,9 +43,7 @@ class LotteryRecordRepository extends BaseRepository
*/
public function create($data)
{
if($data['type'] == 1){
app(UserAssetsRepository::class)->lottery($data['uid'], $data['count']);
}
return $this->dao->create($data);
}

@ -55,7 +55,7 @@ class UserAssetsLogRepository extends BaseRepository
const DIAMOND_SHARE = 24; //分享奖返佣
const DIAMOND_SERVE = 25; //服务奖返佣
const DIAMOND_DEPOSIT = 26; //预存奖返佣
const DIAMOND_LOTTERY = 27; //幸运大转盘奖励
const DIAMOND_LOTTERY = 27; //幸运大转盘
const STOCK = 30; //钻石兑换
@ -110,7 +110,7 @@ class UserAssetsLogRepository extends BaseRepository
self::DIAMOND_SHARE => '分享奖返佣',
self::DIAMOND_SERVE => '服务奖返佣',
self::DIAMOND_DEPOSIT => '预存奖返佣',
self::DIAMOND_LOTTERY => '幸运大转盘奖励',
self::DIAMOND_LOTTERY => '幸运大转盘',
self::STOCK => '钻石兑换',
);
}

@ -45,6 +45,7 @@ class UserAssetsRepository extends BaseRepository
* diamondToStock 钻石兑本票
* withdrawRate 提现手续费
* transferRate 转让手续费
* lotteryPayDiamond 抽奖消耗钻石
*/
return array_column($config['list'], "value", 'key');
}
@ -114,6 +115,21 @@ class UserAssetsRepository extends BaseRepository
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND,
'type' => UserAssetsLogRepository::DIAMOND_LOTTERY,
'status' => $count >0 ? UserAssetsLogRepository::STATUS_GET : UserAssetsLogRepository::STATUS_USE,
'count' => $count,
);
$assets = $this->assets($uid);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('diamond' => $assets['diamond'] + $count));
}
public function daily($uid, $count, $type = UserAssetsLogRepository::DIAMOND_SERVE){
$logList = array();
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND,
'type' => $type,
'status' => UserAssetsLogRepository::STATUS_GET,
'count' => $count,
);

@ -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
]);
}
}

@ -201,6 +201,12 @@ class UserRepository extends BaseRepository
return compact('count', 'list');
}
public function selectAllGroupUser(){
$where = array();
$where[] = array('group_id', '>', 0);
return $this->dao->selectWhere($where, 'uid, group_id');
}
public function getUserByPhone($phone){
return $this->dao->getWhere(['phone' => $phone]);

@ -15,6 +15,7 @@ namespace app\controller\api;
use app\common\repositories\store\DepositRepository;
use app\common\repositories\user\DepositRecordDailyRepository;
use app\common\repositories\user\LotteryRecordRepository;
use app\common\repositories\store\LotteryRepository;
use app\common\repositories\store\order\StoreGroupOrderRepository;
@ -25,6 +26,7 @@ use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\system\notice\SystemNoticeRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserAssetsRepository;
use app\common\repositories\user\UserGroupDailyRepository;
use app\common\repositories\user\UserGroupRepository;
use app\common\repositories\user\UserOrderRepository;
use app\common\repositories\user\UserRechargeRepository;
@ -81,7 +83,7 @@ class Auth extends BaseController
// }
// app(UserAssetsLogRepository::class)->shareAward(1);
event('order.take', array('order' => array('order_id' => 3)));
app(DepositRecordDailyRepository::class)->runDaily();
return app('json')->success();
}
@ -208,26 +210,6 @@ class Auth extends BaseController
return app('json')->success(app(LotteryRepository::class)->getList([]));
}
public function lotteryTry(){
$list = app(LotteryRepository::class)->getList([]);
$rand = $try = rand(1,100);
$current = null;
foreach ($list as $item){
$try = $try - $item['rate'];
if($try <= 0){
$current = $item;
break;
}
}
app(LotteryRecordRepository::class)->create([
'uid' => 10,
'type' => $current['type'],
'lottery_id' => $current['id'],
'count' => $current['value'],
]);
return app('json')->success(array('try' => $rand, 'item' => $current));
}
public function depositData(){
$ret = app(DepositRepository::class)->getList(['status' => 1], 1, 10);
return app('json')->success($ret['list']);

@ -15,8 +15,10 @@ namespace app\controller\api\user;
use app\common\repositories\store\IntegralRepository;
use app\common\repositories\store\LotteryRepository;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\CacheRepository;
use app\common\repositories\user\LotteryRecordRepository;
use app\common\repositories\user\MemberinterestsRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserAssetsRepository;
@ -46,6 +48,61 @@ class User extends BaseController
$this->user = $this->request->userInfo();
}
public function lotteryTry(){
$user = $this->request->userInfo();
$uid = $user->uid;
/**
* @var LotteryRecordRepository $recordRepository
*/
$recordRepository = app(LotteryRecordRepository::class);
/**
* @var UserAssetsRepository $assetsRepository
*/
$assetsRepository = app(UserAssetsRepository::class);
$where = array();
$where[] = array('uid', '=', $uid);
$where[] = array('create_time', '>=', date('Y-m-d 00:00:00'));
$where[] = array('type', 'in', [1, 2]);
$list = $recordRepository->selectWhere($where);
$config = $assetsRepository->getConfig();
if($list && count($list) >= 1){
$assets = $assetsRepository->assets($uid);
if($assets['diamond'] < $config['lotteryPayDiamond']){
return app('json')->fail('钻石不足');
}
}
$list = app(LotteryRepository::class)->getList([]);
$rand = $try = rand(1,100);
$current = null;
foreach ($list as $item){
$try = $try - $item['rate'];
if($try <= 0){
$current = $item;
break;
}
}
if($list && count($list) >= 1 && $current['type'] != 3){
$assetsRepository->lottery($uid, -$config['lotteryPayDiamond']);
}
if($current['type'] == 1){
$assetsRepository->lottery($uid, $current['value']);
}
$recordRepository->create([
'uid' => $uid,
'type' => $current['type'],
'lottery_id' => $current['id'],
'count' => $current['value'],
]);
return app('json')->success(array('try' => $rand, 'item' => $current));
}
public function assetsLog(){
$user = $this->request->userInfo();

@ -56,6 +56,7 @@ return [
\crmeb\listens\SendSvipCouponListen::class,
\crmeb\listens\SyncMerchantMarginStatusListen::class,
\crmeb\listens\SyncQueueStatusListen::class,
\crmeb\listens\task\CustomizeTask::class,
] : [],
'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class],
'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class],

@ -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();
}
});
}
}

@ -29,7 +29,6 @@ Route::group('api/', function () {
Route::get('lottery/data', 'api.Auth/lotteryData');
Route::post('lottery/try', 'api.Auth/lotteryTry');
Route::get('deposit/data', 'api.Auth/depositData');
@ -119,6 +118,8 @@ Route::group('api/', function () {
Route::post('user/cancel', 'api.Auth/cancel');
//用户
Route::group('user', function () {
//用户抽奖
Route::post('lottery/try', 'User/lotteryTry');
//用户资产明细
Route::get('assetsLog', 'User/assetsLog');
//积分兑换钻石

Loading…
Cancel
Save