Plantask.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Cache;
  6. class Plantask extends Controller
  7. {
  8. //计划任务
  9. //定时清除用户关系,拒绝的
  10. public function auto_relation(){
  11. //拒绝七天后,可再次申请
  12. $lists = Db::name('user_relation')->where('status',2)->where('updatetime','lt',time()-604800)->delete();
  13. }
  14. //定时清除用户关系,过期的
  15. public function auto_relation_guoqi(){
  16. //24小时未处理,过期
  17. Db::startTrans();
  18. $lists = Db::name('user_relation')->where('status',0)->where('createtime','lt',time()-86400)->limit(10)->lock(true)->select();
  19. if(empty($lists)){
  20. Db::rollback();
  21. echo 'empty';
  22. exit;
  23. }
  24. dump($lists);
  25. foreach($lists as $key => $info){
  26. //退回关系卡
  27. $use_card = Db::name('user_decorate_relation')->where('user_id',$info['uid'])->where('is_using',1)->order('id desc')->find();
  28. if($use_card){
  29. $rs2 = Db::name('user_decorate_relation')->where('id',$use_card['id'])->update(['is_using'=>0,'updatetime'=>time()]);
  30. if($rs2 === false){
  31. Db::rollback();
  32. echo '退回关系卡失败';
  33. exit;
  34. }
  35. }
  36. }
  37. $ids = array_column($lists,'id');
  38. $rs = Db::name('user_relation')->where('id','IN',$ids)->delete();
  39. if(!$rs){
  40. Db::rollback();
  41. echo '清除失败';
  42. exit;
  43. }
  44. Db::commit();
  45. echo '完成';
  46. }
  47. //定时跑用户活跃,改成离线
  48. public function auto_user_active(){
  49. $actitime = time() - 7200;
  50. $sql = 'update `mt_user` set is_active = 0 where id in (select user_id from mt_user_active where requesttime < '.$actitime.')';
  51. db()->query($sql);
  52. }
  53. //vip过期的,三个隐私设置改成0
  54. public function auto_vipend(){
  55. $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().')';
  56. db()->query($sql);
  57. }
  58. }