RefundController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatRefundClass;
  5. use bizGhs\cg\classes\CgRefundClass;
  6. use bizGhs\order\classes\RefundOrderClass;
  7. use bizGhs\order\classes\RefundOrderItemClass;
  8. use bizGhs\order\models\RefundOrder;
  9. use bizHd\cg\classes\CgRefundItemClass;
  10. use yii\console\Controller;
  11. use Yii;
  12. class RefundController extends Controller
  13. {
  14. public function actionStatus()
  15. {
  16. $query = new \yii\db\Query();
  17. $query->from(RefundOrder::tableName());
  18. $query->where(['>', 'id', 0]);
  19. $query->orderBy('addTime ASC');
  20. foreach ($query->batch() as $batchOrder) {
  21. foreach ($batchOrder as $refund) {
  22. $connection = Yii::$app->db;
  23. $transaction = $connection->beginTransaction();
  24. try {
  25. $orderSn = $refund['orderSn'] ?? '';
  26. $status = $refund['status'] ?? 0;
  27. RefundOrderItemClass::updateByCondition(['orderSn' => $orderSn], ['status' => $status]);
  28. $cgRefundId = $refund['cgRefundId'] ?? 0;
  29. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  30. $cgRefundStatus = $cgRefund->status;
  31. $cgOrderSn = $cgRefund->orderSn ?? '';
  32. CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['status' => $cgRefundStatus]);
  33. $transaction->commit();
  34. echo "ok\n";
  35. } catch (\Exception $e) {
  36. $transaction->rollBack();
  37. $msg = $e->getMessage();
  38. echo "报错 {$msg}\n";
  39. }
  40. }
  41. }
  42. }
  43. //退款数据更新 ./yii refund/update
  44. public function actionUpdate()
  45. {
  46. $list = RefundOrderClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true);
  47. if (!empty($list)) {
  48. foreach ($list as $item) {
  49. $orderSn = $item->orderSn ?? '';
  50. $shopId = $item->shopId ?? 0;
  51. $addTime = $item->addTime ?? '';
  52. $connection = Yii::$app->db;
  53. $transaction = $connection->beginTransaction();
  54. $refundPrice = $item->refundPrice ?? 0;
  55. try {
  56. $shop = ShopClass::getLockById($shopId);
  57. if (empty($shop)) {
  58. echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
  59. continue;
  60. }
  61. $totalRefund = bcadd($refundPrice, $shop->totalRefund, 2);
  62. $shop->totalRefund = $totalRefund;
  63. $shop->save();
  64. $date = date("Ymd", strtotime($addTime));
  65. StatRefundClass::replace($shop, $payWay, $refundPrice, $date);
  66. $transaction->commit();
  67. } catch (\Exception $e) {
  68. $transaction->rollBack();
  69. $msg = $e->getMessage();
  70. echo "报错了:" . $msg . "\n";
  71. }
  72. }
  73. }
  74. }
  75. }