123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- use think\Db;
- use think\Cache;
- class Plantask extends Controller
- {
- //计划任务
- //定时清除用户关系,拒绝的
- public function auto_relation(){
- //拒绝七天后,可再次申请
- $lists = Db::name('user_relation')->where('status',2)->where('updatetime','lt',time()-604800)->delete();
- }
- //定时清除用户关系,过期的
- public function auto_relation_guoqi(){
- //24小时未处理,过期
- Db::startTrans();
- $lists = Db::name('user_relation')->where('status',0)->where('createtime','lt',time()-86400)->limit(10)->lock(true)->select();
- if(empty($lists)){
- Db::rollback();
- echo 'empty';
- exit;
- }
- foreach($lists as $key => $info){
- //退回关系卡
- $use_card = Db::name('user_decorate_relation')->where('user_id',$info['uid'])->where('is_using',1)->order('id desc')->find();
- if($use_card){
- $rs2 = Db::name('user_decorate_relation')->where('id',$use_card['id'])->update(['is_using'=>0,'updatetime'=>time()]);
- if($rs2 === false){
- Db::rollback();
- echo '退回关系卡失败';
- exit;
- }
- }
- }
- $ids = array_column($lists,'id');
- $rs = Db::name('user_relation')->where('id','IN',$ids)->delete();
- if(!$rs){
- Db::rollback();
- echo '清除失败';
- exit;
- }
- Db::commit();
- echo '完成';
- }
- //定时跑用户活跃,改成离线
- public function auto_user_active(){
- $actitime = time() - 172800;
- $sql = 'update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime < '.$actitime.')';
- db()->query($sql);
- }
- //vip过期的,三个隐私设置改成0
- public function auto_vipend(){
- $sql = 'update `mt_user_power` set yinsi = 0,yinshen = 0,wuhen = 0 where user_id in (select user_id from mt_user_wallet where vip_endtime > 0 and vip_endtime < '.time().')';
- db()->query($sql);
- }
- //禁言到期的,自动解禁
- public function auto_jinyan(){
- $sql = 'update `mt_user` set jinyantype = 1,jinyantime = 0 where jinyantype = 2 and jinyantime < '.time().'';
- db()->query($sql);
- }
- }
|