GhsOrderController.php 3.3 KB

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