| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use biz\stat\classes\StatRefundClass;
- use bizGhs\cg\classes\CgRefundClass;
- use bizGhs\order\classes\RefundOrderClass;
- use bizGhs\order\classes\RefundOrderItemClass;
- use bizGhs\order\models\RefundOrder;
- use bizHd\cg\classes\CgRefundItemClass;
- use yii\console\Controller;
- use Yii;
- class RefundController extends Controller
- {
- public function actionStatus()
- {
- $query = new \yii\db\Query();
- $query->from(RefundOrder::tableName());
- $query->where(['>', 'id', 0]);
- $query->orderBy('addTime ASC');
- foreach ($query->batch() as $batchOrder) {
- foreach ($batchOrder as $refund) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $orderSn = $refund['orderSn'] ?? '';
- $status = $refund['status'] ?? 0;
- $addTime = $refund['addTime'] ?? '';
- $updateTime = $refund['updateTime'] ?? '';
- RefundOrderItemClass::updateByCondition(['orderSn' => $orderSn], ['status' => $status, 'addTime' => $addTime, 'updateTime' => $updateTime]);
- $cgRefundId = $refund['cgRefundId'] ?? 0;
- $cgRefund = CgRefundClass::getById($cgRefundId, true);
- if (empty($cgRefund)) {
- echo "{$orderSn} 没有找到采购的退款信息\n";
- RefundOrderItemClass::deleteByCondition(['orderSn'=>$orderSn]);
- RefundOrderClass::deleteByCondition(['orderSn'=>$orderSn]);
- continue;
- }
- $cgRefundStatus = $cgRefund->status;
- $cgOrderSn = $cgRefund->orderSn ?? '';
- $addTime = $cgRefund->addTime;
- $updateTime = $cgRefund->updateTime;
- CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['status' => $cgRefundStatus, 'addTime' => $addTime, 'updateTime' => $updateTime]);
- $transaction->commit();
- echo "ok\n";
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- echo "报错 {$msg}\n";
- }
- }
- }
- }
- //退款数据更新 ./yii refund/update
- public function actionUpdate()
- {
- $list = RefundOrderClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true);
- if (!empty($list)) {
- foreach ($list as $item) {
- $orderSn = $item->orderSn ?? '';
- $shopId = $item->shopId ?? 0;
- $addTime = $item->addTime ?? '';
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $refundPrice = $item->refundPrice ?? 0;
- try {
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
- continue;
- }
- $totalRefund = bcadd($refundPrice, $shop->totalRefund, 2);
- $shop->totalRefund = $totalRefund;
- $shop->save();
- $date = date("Ymd", strtotime($addTime));
- StatRefundClass::replace($shop, $payWay, $refundPrice, $date);
- $transaction->commit();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- echo "报错了:" . $msg . "\n";
- }
- }
- }
- }
- }
|