RenderOrder.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\http\command;
  3. use app\common\model\GoodsOrder;
  4. use think\console\Input;
  5. use think\console\input\Argument;
  6. use think\console\input\Option;
  7. use think\console\Output;
  8. class RenderOrder 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:order')
  19. ->setDescription('render:order');
  20. }
  21. /**
  22. * 流程处理
  23. *
  24. * @author 许祖兴 < zuxing.xu@lettered.cn>
  25. * @date 2020/7/20 9:20
  26. *
  27. * @param Input $input
  28. * @param Output $output
  29. * @return int|void|null
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. protected function execute(Input $input, Output $output)
  35. {
  36. //1.产品订单处理 查询订单
  37. $orders = (new GoodsOrder)->whereTime('created_at','month')->select()->toArray();
  38. foreach ($orders as $order){
  39. // 已结束不处理
  40. if ($order['status'] == 4 || $order['status'] == 0) continue;
  41. switch ($order['status']){
  42. case 1:
  43. //待支付订单关闭处理
  44. // 读取配置 超时时间 (order_expired_at)小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
  45. $order_expired_at = $this->config['store']['order_expired_at'];
  46. // 流程开始
  47. if (($order['created_at'] + ($order_expired_at * 3600)) <= time()){
  48. //关闭订单
  49. model('common/GoodsOrder')->updateBy($order['id'], [
  50. 'status' => 0
  51. ]);
  52. }
  53. break;
  54. case 2:
  55. // 自动发货 等待
  56. break;
  57. case 3:
  58. // 待收获订单确认处理
  59. // 读取配置 自动确认时间 (order_confirm_at) 天数 (下单时间戳+天*时间戳 < 当前时间戳 超时)
  60. $order_confirm_at = $this->config['store']['order_confirm_at'];
  61. // 流程开始
  62. if (($order['created_at'] + ($order_confirm_at * 86400)) <= time()){
  63. // 奖励期权条件
  64. if ($order && $order['is_pin'] !== 1){
  65. // 用户期权
  66. // order_property_reward
  67. $order_property_reward = $this->config['store']['order_property_reward'];
  68. // 计算 交易金额 * order_property_reward
  69. $reward = round($order_property_reward * $order['total_price'],3);
  70. // 更新
  71. model('common/Users')->changeProperty(
  72. $order['user_id'],
  73. $reward,
  74. '订单完成,奖励资产【' . $reward . "】",
  75. true
  76. );
  77. }
  78. // 结束订单
  79. model('common/GoodsOrder')->updateBy($order['id'], [
  80. 'received_at' => time(),
  81. 'status' => 4 // 结束订单
  82. ]);
  83. }
  84. break;
  85. case 5:
  86. // 未开团结束处理
  87. // 读取配置 领取超时时间 (pin_expired_at) 小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
  88. $pin_expired_at = $this->config['store']['pin_expired_at'];
  89. // 流程开始
  90. if (($order['created_at'] + ($pin_expired_at * 3600)) <= time()){
  91. // todo 商品退钱
  92. model('common/Users')->changeBalance(
  93. $order['user_id'],
  94. $order['pay_price'],
  95. "参团失败,退还支付金额【" . $order['pay_price'] . '】',
  96. true
  97. );
  98. // 结束订单
  99. model('common/GoodsOrder')->updateBy($order['id'], [
  100. 'status' => 0 // 关闭订单
  101. ]);
  102. }
  103. break;
  104. case 6:
  105. // 待领取订单结束处理
  106. // 读取配置 领取超时时间 (pin_rebate_expired_at) 小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
  107. $pin_rebate_expired_at = $this->config['store']['pin_rebate_expired_at'];
  108. // 流程开始
  109. if (($order['created_at'] + ($pin_rebate_expired_at * 3600)) <= time()){
  110. // 结束订单
  111. model('common/GoodsOrder')->updateBy($order['id'], [
  112. 'status' => 4 // 结束订单
  113. ]);
  114. }
  115. break;
  116. }
  117. }
  118. // 其他订单处理
  119. }
  120. }