RefundController.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $addTime = $refund['addTime'] ?? '';
  28. $updateTime = $refund['updateTime'] ?? '';
  29. RefundOrderItemClass::updateByCondition(['orderSn' => $orderSn], ['status' => $status, 'addTime' => $addTime, 'updateTime' => $updateTime]);
  30. $cgRefundId = $refund['cgRefundId'] ?? 0;
  31. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  32. $cgRefundStatus = $cgRefund->status;
  33. $cgOrderSn = $cgRefund->orderSn ?? '';
  34. $addTime = $cgRefund->addTime;
  35. $updateTime = $cgRefund->updateTime;
  36. CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['status' => $cgRefundStatus, 'addTime' => $addTime, 'updateTime' => $updateTime]);
  37. $transaction->commit();
  38. echo "ok\n";
  39. } catch (\Exception $e) {
  40. $transaction->rollBack();
  41. $msg = $e->getMessage();
  42. echo "报错 {$msg}\n";
  43. }
  44. }
  45. }
  46. }
  47. //退款数据更新 ./yii refund/update
  48. public function actionUpdate()
  49. {
  50. $list = RefundOrderClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true);
  51. if (!empty($list)) {
  52. foreach ($list as $item) {
  53. $orderSn = $item->orderSn ?? '';
  54. $shopId = $item->shopId ?? 0;
  55. $addTime = $item->addTime ?? '';
  56. $connection = Yii::$app->db;
  57. $transaction = $connection->beginTransaction();
  58. $refundPrice = $item->refundPrice ?? 0;
  59. try {
  60. $shop = ShopClass::getLockById($shopId);
  61. if (empty($shop)) {
  62. echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
  63. continue;
  64. }
  65. $totalRefund = bcadd($refundPrice, $shop->totalRefund, 2);
  66. $shop->totalRefund = $totalRefund;
  67. $shop->save();
  68. $date = date("Ymd", strtotime($addTime));
  69. StatRefundClass::replace($shop, $payWay, $refundPrice, $date);
  70. $transaction->commit();
  71. } catch (\Exception $e) {
  72. $transaction->rollBack();
  73. $msg = $e->getMessage();
  74. echo "报错了:" . $msg . "\n";
  75. }
  76. }
  77. }
  78. }
  79. }