AutoWithMTS.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\http\command;
  3. use think\console\Input;
  4. use think\console\Output;
  5. // M MissionOrder
  6. // T TaxiOrder
  7. // S SkillOrder
  8. class AutoWithMTS extends BaseCommand
  9. {
  10. /**
  11. *
  12. * @author 许祖兴 < zuxing.xu@lettered.cn>
  13. * @date 2020/7/14 15:41
  14. *
  15. */
  16. protected function configure()
  17. {
  18. $this->setName('render:mts')
  19. ->setDescription('render:mts');
  20. }
  21. /**
  22. * 流程处理
  23. *
  24. * @param Input $input
  25. * @param Output $output
  26. * @return int|void|null
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. * @author 许祖兴 < zuxing.xu@lettered.cn>
  31. * @date 2020/7/20 9:20
  32. *
  33. */
  34. protected function execute(Input $input, Output $output)
  35. {
  36. // 分别处理
  37. foreach (['MissionOrder','TaxiOrder','SkillOrder','RescueOrder'] as $args){
  38. //1.产品订单处理 查询订单
  39. $orders = model('common/'. $args)->whereTime('created_at', 'month')->select()->toArray();
  40. foreach ($orders as $order) {
  41. // 已结束或者已关闭不处理
  42. if ($order['status'] == 4 || $order['status'] == 0) continue;
  43. // 按类型处理
  44. switch ($order['status']) {
  45. case 1:
  46. // 待支付订单处理
  47. // 读取配置 超时时间 (order_expired_at)小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
  48. $order_expired_at = $this->config['store']['order_expired_at'];
  49. // 流程开始
  50. if (($order['created_at'] + ($order_expired_at * 3600)) <= time()){
  51. //关闭订单
  52. model('common/'. $args)->updateBy($order['id'], [
  53. 'status' => 0
  54. ]);
  55. }
  56. break;
  57. case 2:
  58. // 自动服务
  59. break;
  60. case 3:
  61. // 待确认处理
  62. // 读取配置 自动确认时间 (order_confirm_at) 天数 (下单时间戳+天*时间戳 < 当前时间戳 超时)
  63. $order_confirm_at = $this->config['store']['order_confirm_at'];
  64. // 流程开始
  65. if (($order['created_at'] + ($order_confirm_at * 86400)) <= time()) {
  66. // 结束订单
  67. model('common/'. $args)->updateBy($order['id'], [
  68. 'status' => 4 // 结束订单
  69. ]);
  70. }
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. }