| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace console\controllers;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\models\Order;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\models\Purchase;
- use common\components\noticeUtil;
- use yii\console\Controller;
- use Yii;
- class OrderController extends Controller
- {
- //【重要脚本,不能删除】到时间没发货,进行确认收货 ssh 20231122
- public function actionUnFhConfirmTake()
- {
- $query = new \yii\db\Query();
- $query->from(\bizGhs\order\models\Order::tableName());
- if (getenv('YII_ENV') == 'production') {
- $endTime = strtotime('-5 days');
- } else {
- $endTime = strtotime('-1 hour');
- }
- $startTime = strtotime('-30 days');
- $startDate = date("Y-m-d H:i:s", $startTime);
- $endDate = date("Y-m-d H:i:s", $endTime);
- //查询已经过期10天的订单
- $query->where(['status' => 2])->andWhere(['>', 'payTime', $startDate])->andWhere(['<=', 'payTime', $endDate]);
- $query->orderBy('deadline ASC');
- foreach ($query->batch() as $batchOrder) {
- foreach ($batchOrder as $order) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $orderSn = $order['orderSn'] ?? '';
- try {
- $cgId = $order['purchaseId'] ?? 0;
- $info = PurchaseClass::getById($cgId, true);
- if (!empty($info)) {
- //没发货的预订单不能自动确认收货
- if ($info->book == 1) {
- continue;
- }
- PurchaseClass::confirmTake($info);
- }
- $transaction->commit();
- noticeUtil::push("销售单号:{$orderSn}已自动确认收货");
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("销售单号:{$orderSn}自动确认收货出错,{$msg}", '15280215347');
- }
- }
- }
- }
- //【重要脚本,不能删除】到时间没确认收货,进行确认收货 ssh 20231122
- public function actionConfirmTake()
- {
- $query = new \yii\db\Query();
- $query->from(Purchase::tableName());
- if (getenv('YII_ENV') == 'production') {
- $endTime = strtotime('-5 days');
- } else {
- $endTime = strtotime('-1 hour');
- }
- $startTime = strtotime('-30 days');
- $startDate = date("Y-m-d H:i:s", $startTime);
- $endDate = date("Y-m-d H:i:s", $endTime);
- //查询已经过期10天的订单
- $query->where(['status' => 3])->andWhere(['>', 'fhTime', $startDate])->andWhere(['<=', 'fhTime', $endDate]);
- $query->orderBy('deadline ASC');
- foreach ($query->batch() as $batchCg) {
- foreach ($batchCg as $cg) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $orderSn = $cg['orderSn'] ?? '';
- $id = $cg['id'] ?? 0;
- try {
- $info = PurchaseClass::getById($id, true);
- if (!empty($info)) {
- PurchaseClass::confirmTake($info);
- }
- $transaction->commit();
- noticeUtil::push("采购单号:{$orderSn}已自动确认收货");
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("采购单号:{$orderSn}自动确认收货出错,{$msg}", '15280215347');
- }
- }
- }
- }
- //【重要脚本,不能删除】花店订单脚本
- public function actionExpire()
- {
- $query = new \yii\db\Query();
- $query->from(Order::tableName());
- $endTime = time();
- $startTime = strtotime('-10 days');
- //查询已经过期10天的订单
- $query->where(['status' => 1])->andWhere(['>', 'deadline', $startTime])->andWhere(['<=', 'deadline', $endTime]);
- $query->orderBy('deadline ASC');
- foreach ($query->batch() as $batchOrder) {
- foreach ($batchOrder as $orderItem) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $id = $orderItem['id'] ?? 0;
- $orderSn = $orderItem['orderSn'] ?? '';
- try {
- $order = OrderClass::getById($id, true);
- //暂时只考虑花材库存的回滚
- OrderClass::setExpire($order);
- $transaction->commit();
- //noticeUtil::push("零售订单未付款,库存已回滚,单号:{$orderSn}");
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
- }
- }
- }
- }
- }
|