Complain.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\cron;
  3. use app\common\model\Config;
  4. use app\common\util\AppMsg;
  5. use think\Db;
  6. use yunwuxin\cron\Task;
  7. class Complain extends Task
  8. {
  9. public function configure()
  10. {
  11. $this->everyMinute(); //每分钟执行一次
  12. }
  13. /**
  14. * 执行任务
  15. * @return mixed
  16. */
  17. protected function execute()
  18. {
  19. try{
  20. $this->complain();
  21. }catch (\Exception $e){
  22. trace($e->getMessage());
  23. }
  24. trace('attendance');
  25. }
  26. public function complain(){
  27. $lists = Db::name('config_org')
  28. ->alias('a')
  29. ->join('config b','a.config_id = b.id')
  30. ->where('b.name','org_complain_hour')
  31. ->field('a.org_id,a.value')
  32. ->select();
  33. $lists = $lists?$lists:[];
  34. foreach ($lists as $k=>$v){
  35. if($v['value'] > 0){
  36. // 获取当前组织是否设置人员,设置人员才发送超时提醒
  37. $users = (new Config())->getConfig('org_complain_user',$v['org_id']);
  38. if($users){
  39. $uids = Db::name('user')->where('id','in',$users)->where('del',0)->where('enable')->column('id');
  40. if($uids){
  41. // 检查是否有超时未处理投诉
  42. $map = [];
  43. $endTime = date('Y-m-d H:i:s',time() - $v['value']*60*60);
  44. $map[] = ['create_time','<',$endTime];
  45. $map[] = ['status','=',0];
  46. $map[] = ['org_id','=',$v['org_id']];
  47. $map[] = ['del','=',0];
  48. $ret = Db::name('complain')
  49. ->where($map)
  50. ->field('id,content,create_time,status,order_id')
  51. ->find();
  52. if($ret){
  53. send_jpush($uids,AppMsg::PUSH_COMPLAIN_TIMEOUT);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }