OrdersReminder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\cron;
  3. use app\common\model\Config;
  4. use app\common\model\Orders as OrderModel;
  5. use app\common\util\AppMsg;
  6. use think\Db;
  7. use yunwuxin\cron\Task;
  8. //订单超过三个小时未完成提醒
  9. class OrdersReminder extends Task
  10. {
  11. public function configure()
  12. {
  13. $this->spliceIntoPosition(1, '*/20'); //每20分钟执行一次
  14. }
  15. /**
  16. * 执行任务
  17. * @return mixed
  18. */
  19. protected function execute()
  20. {
  21. try{
  22. $this->push();
  23. }catch (\Exception $e){
  24. trace($e->getMessage());
  25. }
  26. }
  27. public function push(){
  28. $list= Db::name('orders')
  29. ->alias('a')
  30. ->join('todo b','a.id = b.order_id')
  31. ->where('a.del',0)
  32. ->where('b.del',0)
  33. ->where('order_mode',4)
  34. ->where('todo_mode','in',[1,2])
  35. ->field('b.create_time,b.to_user_id')
  36. ->select();
  37. $ids = [];
  38. foreach ($list as $k=>$v){
  39. $time = time();
  40. $cTime = strtotime($v['create_time']);
  41. $diff = $time - $cTime;
  42. if ($diff > 60*60*3){
  43. $ids[] = $v['to_user_id'];
  44. }
  45. }
  46. $ids = array_unique($ids);
  47. if(!empty($ids)){
  48. send_jpush($ids,AppMsg::PUSH_WORKER_ORDER_SEND,'您的订单未完成,请及时处理');
  49. }
  50. }
  51. }