RefundController.php 3.7 KB

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