GhsOrderController.php 3.4 KB

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