GhsOrderController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\order\classes\OrderClass;
  5. use Yii;
  6. use yii\console\Controller;
  7. class GhsOrderController extends Controller
  8. {
  9. public function actionBcId()
  10. {
  11. ini_set('memory_limit', '2045M');
  12. set_time_limit(0);
  13. $list = OrderClass::getAllByCondition(['mainId' => 0], null, '*', null, true);
  14. if (!empty($list)) {
  15. foreach ($list as $order) {
  16. $shopId = $order->shopId ?? 0;
  17. $shop = ShopClass::getById($shopId, true);
  18. $mainId = $shop->mainId ?? 0;
  19. if (!empty($mainId)) {
  20. $order->mainId = $mainId;
  21. $order->save();
  22. }
  23. }
  24. }
  25. }
  26. // 脚本一:每天 03:20 执行,处理付款时间 7~10 天前订单
  27. public function actionAutoSetOrderToFinish()
  28. {
  29. $minPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
  30. $maxPayTime = date('Y-m-d H:i:s', strtotime('-7 day'));
  31. $condition = [
  32. 'payStatus' => 1,
  33. 'status' => ['in', [2, 3]],
  34. 'payTime' => ['between', [$minPayTime, $maxPayTime]],
  35. ];
  36. $this->batchConfirmReachByMainId($condition);
  37. Yii::info('批发订单自动完结脚本成功执行');
  38. }
  39. // 脚本二:历史补偿,处理付款超过 10 天未完结订单
  40. public function actionSetOldOrderToFinish()
  41. {
  42. $maxPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
  43. $condition = [
  44. 'payStatus' => 1,
  45. 'status' => ['in', [2, 3]],
  46. 'payTime <' => $maxPayTime,
  47. ];
  48. $this->batchConfirmReachByMainId($condition);
  49. Yii::info('批发订单自动完结历史补偿脚本成功执行');
  50. }
  51. /**
  52. * 按批发店 mainId 分批处理订单自动收货完结
  53. * @param array $extraCondition
  54. */
  55. private function batchConfirmReachByMainId($extraCondition)
  56. {
  57. $ghsShops = ShopClass::getAllByCondition(['ptStyle' => 2, 'live' => 1], null, 'mainId');
  58. if (empty($ghsShops)) {
  59. return;
  60. }
  61. $mainIds = array_unique(array_filter(array_column($ghsShops, 'mainId')));
  62. if (empty($mainIds)) {
  63. return;
  64. }
  65. $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
  66. foreach ($mainIds as $mainId) {
  67. $condition = array_merge(['mainId' => $mainId], $extraCondition);
  68. $orders = OrderClass::getAllByCondition($condition, 'id asc', '*', null, true);
  69. if (empty($orders)) {
  70. continue;
  71. }
  72. foreach ($orders as $order) {
  73. try {
  74. OrderClass::confirmReach($order, $params);
  75. } catch (\Exception $e) {
  76. $orderId = $order->id ?? 0;
  77. Yii::error(
  78. "批发订单自动完结失败 mainId={$mainId}, orderId={$orderId}, message={$e->getMessage()}",
  79. 'ghsOrderAutoFinish'
  80. );
  81. }
  82. }
  83. }
  84. }
  85. }