1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\api\controller;
- use app\common\model\PartnerLevel;
- use app\common\model\User;
- use app\common\model\UserCouponList;
- use app\common\model\UserExpLog;
- use app\common\model\UserGrowthLog;
- use app\common\model\UserIntegralLog;
- use app\common\model\UserLevel;
- use app\common\model\UserWallet;
- use app\common\service\UserIdentity;
- /**
- * @title 定时任务
- * Class Task
- * @controller Task
- * @group base
- */
- class Task extends Base
- {
- // 会员等级
- public function checkUserLevel()
- {
- $user_level = UserLevel::column('id,name,growth','id');
- $partner_level = PartnerLevel::column('id,name,growth','id');
- $last_year = date('Y-m-d H:i:s',strtotime('-1 year'));
- $user_list = User::field('id,level_id,partner_lev,is_partner')
- ->with('wallet')
- ->where('create_at','> time',$last_year)
- ->select()->toArray();
- foreach ($user_list as $v)
- {
- // 一年内获得的经验值
- $exp = UserExpLog::where('create_at','> time',$last_year)
- ->where('user_id','=',$v['id'])
- ->where('is_deleted','=',0)
- ->where('exp','>',0)
- ->sum('exp');
- // 经验过期
- if($exp < $v['wallet']['level_exp']) {
- UserWallet::userExpChange($v['id'],$v['wallet']['level_exp']-$exp,'经验过期',-1);
- $v['wallet']['level_exp'] = $exp;
- // 更新会员等级
- UserIdentity::userLevel($v,$user_level,$v['id']);
- }
- //近一年获得的积分
- $integral = UserIntegralLog::where('create_at','> time',$last_year)
- ->where('user_id','=',$v['id'])
- ->where('type','in',[5,6,7])
- ->where('is_deleted','=',0)
- ->where('integral','>',0)
- ->sum('integral');
- // 积分过期
- if($integral < $v['wallet']['integral']) UserWallet::userIntegralChange($v['id'],$v['wallet']['integral']-$integral,'积分过期',8,-1);
- // 不是分销商跳过
- if(!$v['is_partner']) continue;
- // 成长值
- $growth = UserGrowthLog::where('create_at','> time',$last_year)
- ->where('user_id','=',$v['id'])
- ->where('growth','>',0)
- ->sum('growth');
- // 成长值 过期
- if($growth < $v['wallet']['growth']) {
- UserWallet::userGrowthChange($v['id'],$v['wallet']['growth']-$growth,8,'成长值过期',-1);
- $v['wallet']['growth'] = $growth;
- // 更新会员
- UserIdentity::userPartnerLevel($v,$partner_level,$v['id']);
- }
- }
- $this->success('执行'.count($user_list).'条数据');
- }
- // 会员优惠券过期定时
- public function couponOverTime()
- {
- UserCouponList::where([['type','=',1],['end','< time',date('Y-m-d')],['status','=',0]])->update(['status'=>2]);
- }
- }
|