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 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. if (empty($cgRefund)) {
  33. echo "{$orderSn} 没有找到采购的退款信息\n";
  34. RefundOrderItemClass::deleteByCondition(['orderSn'=>$orderSn]);
  35. RefundOrderClass::deleteByCondition(['orderSn'=>$orderSn]);
  36. continue;
  37. }
  38. $cgRefundStatus = $cgRefund->status;
  39. $cgOrderSn = $cgRefund->orderSn ?? '';
  40. $addTime = $cgRefund->addTime;
  41. $updateTime = $cgRefund->updateTime;
  42. CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['status' => $cgRefundStatus, 'addTime' => $addTime, 'updateTime' => $updateTime]);
  43. $transaction->commit();
  44. echo "ok\n";
  45. } catch (\Exception $e) {
  46. $transaction->rollBack();
  47. $msg = $e->getMessage();
  48. echo "报错 {$msg}\n";
  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. }