RefundController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatRefundClass;
  5. use bizGhs\order\classes\RefundOrderClass;
  6. use yii\console\Controller;
  7. use Yii;
  8. class RefundController extends Controller
  9. {
  10. //退款数据更新 ./yii refund/update
  11. public function actionUpdate()
  12. {
  13. $list = RefundOrderClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true);
  14. if (!empty($list)) {
  15. foreach ($list as $item) {
  16. $orderSn = $item->orderSn ?? '';
  17. $shopId = $item->shopId ?? 0;
  18. $addTime = $item->addTime ?? '';
  19. $connection = Yii::$app->db;
  20. $transaction = $connection->beginTransaction();
  21. $refundPrice = $item->refundPrice ?? 0;
  22. try {
  23. $shop = ShopClass::getLockById($shopId);
  24. if (empty($shop)) {
  25. echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
  26. continue;
  27. }
  28. $totalRefund = bcadd($refundPrice, $shop->totalRefund, 2);
  29. $shop->totalRefund = $totalRefund;
  30. $shop->save();
  31. $date = date("Ymd", strtotime($addTime));
  32. StatRefundClass::replace($shop, $payWay, $refundPrice, $date);
  33. $transaction->commit();
  34. } catch (\Exception $e) {
  35. $transaction->rollBack();
  36. $msg = $e->getMessage();
  37. echo "报错了:" . $msg . "\n";
  38. }
  39. }
  40. }
  41. }
  42. }