Plantask.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. foreach($lists as $key => $info){
  25. //退回关系卡
  26. $use_card = Db::name('user_decorate_relation')->where('user_id',$info['uid'])->where('is_using',1)->order('id desc')->find();
  27. if($use_card){
  28. $rs2 = Db::name('user_decorate_relation')->where('id',$use_card['id'])->update(['is_using'=>0,'updatetime'=>time()]);
  29. if($rs2 === false){
  30. Db::rollback();
  31. echo '退回关系卡失败';
  32. exit;
  33. }
  34. }
  35. }
  36. $ids = array_column($lists,'id');
  37. $rs = Db::name('user_relation')->where('id','IN',$ids)->delete();
  38. if(!$rs){
  39. Db::rollback();
  40. echo '清除失败';
  41. exit;
  42. }
  43. Db::commit();
  44. echo '完成';
  45. }
  46. //定时跑用户活跃,改成离线
  47. public function auto_user_active(){
  48. $actitime = time() - 172800;
  49. $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.')';
  50. db()->query($sql);
  51. }
  52. //vip过期的,三个隐私设置改成0
  53. public function auto_vipend(){
  54. $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().')';
  55. db()->query($sql);
  56. }
  57. //禁言到期的,自动解禁
  58. public function auto_jinyan(){
  59. $sql = 'update `mt_user` set jinyantype = 1,jinyantime = 0 where jinyantype = 2 and jinyantime < '.time().'';
  60. db()->query($sql);
  61. }
  62. }