| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use bizGhs\order\classes\OrderClass;
- use common\components\noticeUtil;
- use Yii;
- use yii\console\Controller;
- class GhsOrderController extends Controller
- {
- public function actionBcId()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = OrderClass::getAllByCondition(['mainId' => 0], null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $order) {
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- $mainId = $shop->mainId ?? 0;
- if (!empty($mainId)) {
- $order->mainId = $mainId;
- $order->save();
- }
- }
- }
- }
- // 脚本一:每天 03:20 执行,处理付款时间 7~10 天前订单
- public function actionAutoSetOrderToFinish()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $minPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
- $maxPayTime = date('Y-m-d H:i:s', strtotime('-7 day'));
- $extraCondition = [
- 'status' => ['in', [2, 3]],
- 'payTime' => ['between', [$minPayTime, $maxPayTime]],
- ];
- $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
- $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
- if (empty($orders)) {
- continue;
- }
- foreach ($orders as $order) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClass::confirmReach($order, $params);
- $transaction->commit();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $orderId = $order->id ?? 0;
- noticeUtil::push("批发订单自动完结失败 orderId={$orderId}, message={$e->getMessage()}", '15280215347');
- }
- }
- Yii::info('批发订单自动完结脚本成功执行');
- }
- // 脚本二:历史补偿,处理付款超过 10 天未完结订单
- public function actionSetOldOrderToFinish()
- {
- $maxPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
- $extraCondition = [
- 'status' => ['in', [2, 3]],
- 'payTime<' => $maxPayTime,
- ];
- $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
- $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
- if (empty($orders)) {
- continue;
- }
- foreach ($orders as $order) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClass::confirmReach($order, $params);
- $transaction->commit();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $orderId = $order->id ?? 0;
- noticeUtil::push("批发订单自动完结失败 orderId={$orderId}, message={$e->getMessage()}", '15280215347');
- }
- }
- Yii::info('批发订单自动完结历史补偿脚本成功执行');
- }
- }
|