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