EvevtRun.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\push\controller;
  12. use app\wap\model\live\LiveUser;
  13. use GatewayWorker\Lib\Gateway;
  14. /*
  15. * 定时任务
  16. *
  17. * */
  18. class EvevtRun
  19. {
  20. /*
  21. * 默认定时器执行事件
  22. * */
  23. public function run()
  24. {
  25. }
  26. /*
  27. * 每隔6秒执行
  28. * */
  29. public function task_6()
  30. {
  31. $list = LiveUser::where('is_open_ben',0)->whereOr('is_online',1)->whereOr('is_ban',1)->field('is_ban,ban_time,is_open_ben,open_ben_time,is_online,uid')->select();
  32. foreach ($list as $item){
  33. $uid=$item['uid'];
  34. unset($item['uid']);
  35. $isUpdate = false;
  36. $is_online=Gateway::isUidOnline($uid);
  37. if($item['is_online'] != $is_online) $isUpdate = true;
  38. $item['is_online'] = $is_online;
  39. if($item['is_ban'] && $item['ban_time'] && $item['ban_time'] < time()){
  40. $isUpdate = true;
  41. $item['is_ban'] = 0;
  42. $item['ban_time'] = 0;
  43. if($item['is_online']){
  44. Gateway::sendToUid($uid,json_encode([
  45. 'type'=>'ban',
  46. 'value'=>0
  47. ]));
  48. }
  49. }
  50. if($item['is_open_ben'] && $item['open_ben_time'] && $item['open_ben_time'] < time()){
  51. $isUpdate = true;
  52. $item['is_open_ben'] = 0;
  53. $item['open_ben_time'] = 0;
  54. }
  55. $isUpdate && LiveUser::where(['uid'=>$uid])->update([
  56. 'is_open_ben'=>$item['is_open_ben'],
  57. 'open_ben_time'=>$item['open_ben_time'],
  58. 'is_ban'=>$item['is_ban'],
  59. 'ban_time'=>$item['ban_time'],
  60. 'is_online'=>$item['is_online'],
  61. ]);
  62. unset($uid);
  63. }
  64. }
  65. /*
  66. * 每隔10秒执行
  67. * */
  68. public function task_10()
  69. {
  70. }
  71. /*
  72. * 每隔30秒执行
  73. * */
  74. public function task_30()
  75. {
  76. }
  77. /*
  78. * 每隔60秒执行
  79. * */
  80. public function task_60()
  81. {
  82. }
  83. /*
  84. * 每隔180秒执行
  85. * */
  86. public function task_180()
  87. {
  88. }
  89. /*
  90. * 每隔300秒执行
  91. * */
  92. public function task_300()
  93. {
  94. }
  95. }