mobile_order_unpay_notify.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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=new WO();
  10. $work->name='notify to not pay user';
  11. $work->onWorkerStart=function ($conn){
  12. Timer::add(1,function (){
  13. $orders= MobileOrder::waitPay()
  14. ->where('type',1)
  15. ->where('create_time','<',time()-300)
  16. ->field('id')
  17. ->whereNotExists('select * from mobile_order_mind where mobile_order.id=mobile_order_mind.mobile_order_id')
  18. ->select()
  19. ->toArray();
  20. self::log(sprintf('%d条数据',count($orders)));
  21. foreach ($orders as $orderId){
  22. try {
  23. $order=MobileOrder::find($orderId);
  24. if(!$order){
  25. continue;
  26. }
  27. SmsSend::orderUnPay($order['phone'],$order['no']);
  28. $order->mind()->save([]);
  29. }catch (\Exception $e){
  30. self::logError($e);
  31. }
  32. }
  33. });
  34. };
  35. }
  36. public static function logname(){
  37. return class_basename(__CLASS__);
  38. }
  39. }
  40. MobileOrderUnPayNotify::run();