RefundController.php 2.4 KB

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