mobile_order_unpay_notify.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. use app\common\model\MobileOrder;
  3. use app\common\service\SmsSend;
  4. use Workerman\Lib\Timer;
  5. use Workerman\Worker as WO;
  6. class MobileOrderUnPayNotify extends Com{
  7. public static function run()
  8. {
  9. $work=self::newWorker();
  10. $work->onWorkerStart=function ($conn){
  11. Timer::add(1,function (){
  12. $orders= MobileOrder::waitPay()
  13. ->where('type',1)
  14. ->where('create_time','<',time()-300)
  15. ->field('id')
  16. ->whereNotExists('select * from mobile_order_mind where mobile_order.id=mobile_order_mind.mobile_order_id')
  17. ->select()
  18. ->toArray();
  19. self::log(sprintf('%d条数据',count($orders)));
  20. foreach ($orders as $orderId){
  21. try {
  22. $order=MobileOrder::find($orderId);
  23. if(!$order){
  24. continue;
  25. }
  26. SmsSend::orderUnPay($order['phone'],$order['no']);
  27. $order->mind()->save([]);
  28. }catch (\Exception $e){
  29. self::logError($e);
  30. }
  31. }
  32. });
  33. };
  34. }
  35. public static function logname(){
  36. return class_basename(__CLASS__);
  37. }
  38. }
  39. MobileOrderUnPayNotify::run();