| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace console\controllers;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\models\Purchase;
- use bizHd\purchase\services\PurchaseService;
- use common\components\dict;
- use common\components\noticeUtil;
- use yii\console\Controller;
- use Yii;
- class PurchaseController extends Controller
- {
- //采购订单到期期变成记欠款或者取消,零售店下单变成取消,商家自己下单变成记欠款 shish 2021.5.14
- // ./yii purchase/expire-order
- // /usr/local/nginx/html/huahuibao/yii purchase/expire-order
- public function actionExpireOrder()
- {
- $query = new \yii\db\Query();
- $query->from(Purchase::tableName());
- $date = date("Y-m-d H:i:s");
- $query->where(['status' => PurchaseClass::STATUS_UN_PAY])->andWhere(['<=', 'deadline', $date]);
- $query->orderBy('deadline ASC');
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
- //如果有报错,抛出异常
- Yii::$app->params['errorReport'] = 1;
- $arr = [];
- foreach ($query->batch() as $purchases) {
- foreach ($purchases as $purchase) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $id = $purchase['id'] ?? 0;
- $orderSn = $purchase['orderSn'] ?? '';
- try {
- $current = PurchaseClass::getById($id, true);
- $cgStyle = $current->cgStyle ?? dict::getDict('cgStyle', 'hd');
- $orderSn = $current->orderSn ?? '';
- if ($cgStyle == dict::getDict('cgStyle', 'hd')) {
- //花店采购的取消
- PurchaseService::expire($current);
- $transaction->commit();
- noticeUtil::push("【测试】采购单已经取消!订单号:{$orderSn}", '15280215347');
- } elseif ($cgStyle == dict::getDict('cgStyle', 'ghs')) {
- //供应商发起的记欠款
- PurchaseService::debt($current);
- $transaction->commit();
- noticeUtil::push("【测试】采购单已经记欠款!订单号:{$orderSn}", '15280215347');
- } else {
- noticeUtil::push("采购单类型没有找到 orderSn:" + $orderSn, '15280215347');
- }
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("【测试】采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
- }
- $log = "过期的采购单:{$id} json:" . json_encode($purchase);
- $arr[] = $log;
- }
- }
- if (!empty($arr)) {
- foreach ($arr as $item) {
- Yii::info($item);
- }
- }
- }
- }
|