| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- //退款退货
- namespace hd\controllers;
- use bizHd\order\classes\OrderClass;
- use bizHd\refund\classes\HdRefundClass;
- use bizHd\refund\classes\HdRefundGoodsClass;
- use bizHd\refund\classes\HdRefundItemClass;
- use bizHd\refund\services\HdRefundService;
- use Yii;
- use common\components\util;
- class RefundController extends BaseController
- {
- //列表
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $orderSn = $get['orderSn'] ?? '';
- if (!empty($orderSn)) {
- $where['orderSn'] = $orderSn;
- }
- $list = HdRefundClass::getOrderList($where);
- util::success($list);
- }
- //退款单详情 ssh 20220427
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $refund = HdRefundClass::getById($id, true);
- HdRefundClass::valid($refund, $this->mainId);
- $refundSn = $refund->refundSn ?? '';
- $itemList = HdRefundItemClass::getItemListBySn($refundSn);
- $goodsList = HdRefundGoodsClass::getGoodsListBySn($refundSn);
- util::success(['info' => $refund, 'itemList' => $itemList, 'goodsList' => $goodsList]);
- }
- //退款 ssh 20220427
- public function actionCreateOrder()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
- util::fail('超管才能操作退款');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) ? $post['id'] : 0;
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->mainId);
- if ($order->status != OrderClass::ORDER_STATUS_COMPLETE) {
- util::fail("完成的订单才能发起退款");
- }
- $addTime = $order->addTime ?? '';
- $current = time();
- if ((strtotime($addTime) + 3 * 30 * 24 * 60 * 60) < $current) {
- util::fail('历史订单,不能再发起退款');
- }
- if (strtotime($addTime) <= strtotime('2022-03-30 00:00:00')) {
- util::fail('历史订单,不能发起退款哦');
- }
- //退款类型 1退货并退款 2 仅退款
- $refundType = $post['refundType'] ?? 1;
- if ($refundType == HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
- //商品花材结构 property 0商品 1花材
- //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
- $productJson = $post['product'] ?? '';
- if (empty($productJson)) {
- util::fail('请选择商品');
- }
- $productList = json_decode($productJson, true);
- if (!is_array($productList)) {
- util::fail('请选择商品哦');
- }
- $post['product'] = $productList;
- } else {
- //仅退款商品花材直接设置为空
- $post['product'] = [];
- }
- $post['price'] = $post['price'] ?? 0;
- if ($post['price'] <= 0) {
- util::fail("退款金额不能小于0");
- }
- if (bccomp($post['price'], $order['orderPrice'], 2) == 1) {
- util::fail("退款金额超过订单金额");
- }
- $post['shopId'] = $this->shopId;
- $post['sjId'] = $this->sjId;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['mainId'] = $this->mainId;
- $shopAdmin = $this->shopAdmin;
- $adminName = $shopAdmin['name'] ?? '';
- $post['shopAdminName'] = $adminName;
- HdRefundService::addRefund($post,$order);
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("出错了:" . $exception->getMessage());
- util::fail('操作失败');
- }
- util::complete();
- }
- }
|