|
|
@@ -476,4 +476,69 @@ class OrderController extends BaseController
|
|
|
util::complete();
|
|
|
}
|
|
|
|
|
|
+ //退款 linqh 2021.6.25
|
|
|
+ public function actionRefund()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $id = isset($post['id']) ? $post['id'] : 0;
|
|
|
+ $order = OrderService::getOrderInfo($id, false, false, false, false);
|
|
|
+ OrderClass::valid($order, $this->shopId);
|
|
|
+ //状态 status = 4 已完成
|
|
|
+ if($order['status']!=OrderClass::ORDER_STATUS_COMPLETE){
|
|
|
+ util::fail("不能退款");
|
|
|
+ }
|
|
|
+ $infoProduct = $order['product'];
|
|
|
+ $productIds = array_unique(array_filter(array_column($infoProduct, 'productId')));
|
|
|
+ $productData = ProductClass::getProductByIds($productIds);
|
|
|
+ $productData = array_column($productData, NULL, 'id');
|
|
|
+ $orderProductMap = [];
|
|
|
+ foreach ($infoProduct as $v){
|
|
|
+ $orderProductMap[$v['productId']] = $v;
|
|
|
+ }
|
|
|
+
|
|
|
+ //[{productId:0,bigNum:1,smallNum:0}]
|
|
|
+ $productJson = $post['product'] ?? '';
|
|
|
+ if (empty($productJson)) {
|
|
|
+ util::fail('请选择花材');
|
|
|
+ }
|
|
|
+ $productList = json_decode($productJson, true);
|
|
|
+ if (!is_array($productList)) {
|
|
|
+ util::fail('花材格式不正确');
|
|
|
+ }
|
|
|
+ //合并
|
|
|
+ $productList = ProductClass::mergeItemInfo($productList);
|
|
|
+ if (empty($productList)) {
|
|
|
+ util::fail('请选择花材');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判定花材数不能大于原订单数
|
|
|
+ foreach ($productList as $v){
|
|
|
+ $orderProductNum = $orderProductMap[$v['productId']]['num']??0;
|
|
|
+ $productName = $productData[$v['productId']]['name']??'';
|
|
|
+ if(!$orderProductNum){
|
|
|
+ util::fail($productName."花材数量错误");
|
|
|
+ }
|
|
|
+ //数量
|
|
|
+ $bigNum = $v['bigNum']??0;
|
|
|
+ $smallNum = $v['smallNum']??0;
|
|
|
+ $ratio = $productData[$v['productId']]['ratio']??0;
|
|
|
+
|
|
|
+ $num = ProductClass::mergeItemNum($bigNum,$smallNum,$ratio);
|
|
|
+ if($num > $orderProductNum) {
|
|
|
+ util::fail($productName."花材错误错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ OrderService::refund($order,$productList);
|
|
|
+ $transaction->commit();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ Yii::info("退款操作报错:" . $exception->getMessage());
|
|
|
+ util::fail('操作失败');
|
|
|
+ }
|
|
|
+ util::complete();
|
|
|
+ }
|
|
|
}
|