RefundController.php 3.6 KB

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