From 06bdfacbe567007c724d3fb1ac880089c7610fd2 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 09:43:24 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=94=AE=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 52 ++++++++++++++++++++ app/api/logic/order/OrderLogic.php | 13 +++++ app/common/enum/OrderEnum.php | 10 ++++ 3 files changed, 75 insertions(+) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 431c3568f..fc7a1bf70 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -7,8 +7,10 @@ use app\api\controller\BaseApiController; use app\api\lists\order\OrderList; use app\api\validate\OrderValidate; use app\common\enum\PayEnum; +use app\common\enum\YesNoEnum; use app\common\logic\PaymentLogic; use app\common\logic\PayNotifyLogic; +use app\common\model\dict\DictData; use app\common\model\store_order\StoreOrder; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\UserAddress; @@ -18,6 +20,7 @@ use hg\apidoc\annotation as ApiDoc; #[ApiDoc\title('订单')] class OrderController extends BaseApiController { + public $notNeedLogin = ['refund_reason']; /** * 订单列表 @@ -350,6 +353,15 @@ class OrderController extends BaseApiController return $this->fail('支付失败'); } + + #[ + ApiDoc\Title('订单详情'), + ApiDoc\url('/api/order/order/detail'), + ApiDoc\Method('GET'), + ApiDoc\Param(name: "order_id", type: "int", require: true, desc: "订单id"), + ApiDoc\NotHeaders(), + ApiDoc\ResponseSuccess("data", type: "array"), + ] public function detail() { $order_id = (int)$this->request->get('order_id'); @@ -496,6 +508,46 @@ class OrderController extends BaseApiController OrderLogic::dealRefund($uid,$params); return $this->success('申请成功'); } + + #[ + ApiDoc\Title('订单退款原因'), + ApiDoc\url('/api/order/order/refund_reason'), + ApiDoc\Method('GET'), + ApiDoc\Param(), + ApiDoc\NotHeaders(), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function refund_reason() + { + return DictData::where('type_value','reason')->where('status',YesNoEnum::YES) + ->select()->toArray(); + + } + + + #[ + ApiDoc\Title('取消售后'), + ApiDoc\url('/api/order/order/cancel_sale'), + ApiDoc\Method('GET'), + ApiDoc\Param(name: "order_id", type: "int", require: true, desc: "订单id"), + ApiDoc\NotHeaders(), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function cancel_sale() + { + $order_id = (int)$this->request->get('order_id'); + $where = [ + 'id' => $order_id, + 'uid' => $this->userId, + ]; + $order = OrderLogic::cancelSell($where); + if ($order) { + return $this->success(); + } else { + return $this->fail('取消失败'); + } + + } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 42e288ea3..259efe60a 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -445,6 +445,19 @@ class OrderLogic extends BaseLogic return $find; } + //取消售后 + public static function cancelSell($where) + { + return StoreOrder::where($where)->update( + [ + 'refund_status'=>OrderEnum::CANCEL_SALE, + 'status'=>OrderEnum::CANCEL_ORDER, + ] + ); + + + } + //核销 diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 1234e32e3..747e3ae55 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -95,9 +95,19 @@ class OrderEnum const SUPPLIER = 3; const SYSTEM = 4; + + + /** + * 订单状态 + * @CANCEL_ORDER 取消售后 + */ + const CANCEL_ORDER = 5; + + //退款状态 const REFUND_STATUS_NO = 0; const REFUND_STATUS_YES = 1; const REFUND_STATUS_FINISH = 2; + const CANCEL_SALE = 3; /** * @notes 获取支付类型 From 8299b9b428d50b164e279b4a319cf0c122bdf463 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 09:59:25 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_order/StoreOrderLogic.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index dc4fe74f9..ae108de1c 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -11,6 +11,9 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\UserAddress; +use app\common\service\pay\PayService; +use Exception; +use support\Cache; use think\facade\Db; class StoreOrderLogic extends BaseLogic @@ -165,4 +168,47 @@ class StoreOrderLogic extends BaseLogic return StoreOrder::where($where)->sum('pay_price'); } + + /** + * 退款 + * @param $order_sn + * @param $refund_money + * @param $total + * @return bool + * @throws Exception + */ + public function refund($order_sn,$refund_money,$total) + { + try { + $wechat = new PayService(1); + $time = time(); + $order = [ + 'out_trade_no' => $order_sn, + 'out_refund_no' => 'BO'.$time, + 'amount' => [ + 'refund' => $refund_money, + 'total' => $total, + 'currency' => 'CNY', + ], + // '_action' => 'jsapi', // jsapi 退款,默认 + // '_action' => 'app', // app 退款 + // '_action' => 'combine', // 合单退款 + // '_action' => 'h5', // h5 退款 + // '_action' => 'miniapp', // 小程序退款 + // '_action' => 'native', // native 退款 + + ]; + + $res = $wechat->wechat->refund($order); + if($res['status'] == 'PROCESSING'){ + return true; + } + return false; + } catch (Exception $e) { + \support\Log::info($e->extra['message']?? $e->getMessage()); + throw new \Exception($e->extra['message']?? $e->getMessage()); + } + + } + } From da2f12b219cfd170947b23f6e1d1aa0fc29e8a4d Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:10:00 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E4=B8=8B=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E4=B8=BA=E5=95=86=E5=93=81=E7=9A=84=E5=B8=82=E5=9C=BA=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 259efe60a..dcb768d8f 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -57,11 +57,15 @@ class OrderLogic extends BaseLogic try { self::$total = 0; /** 计算价格 */ + $check = DictType::where('type','activities')->find(); foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price')->find(); + $find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price,product_id')->find(); if (!$find) { continue; } + if(isset($check) && $check['status'] == 1){ + $find['price'] = StoreProduct::where('product_id',$find['product_id'])->value('ot_price'); + } $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['price'] = $find['price']; $cart_select[$k]['product_id'] = $v['goods']; @@ -87,7 +91,6 @@ class OrderLogic extends BaseLogic //TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 $pay_price = self::$total; // $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑 - $check = DictType::where('type','activities')->find(); $vipPrice = 0; if(isset($check) && $check['status'] == 1){ // $discountRate = '0.99';//首单逻辑 From ac2c11ba4598e60b39e2af8c79f14319f62d982d Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:15:17 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/product/ProductLists.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index bb6dc9537..e43bdd698 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -4,6 +4,7 @@ namespace app\api\lists\product; use app\admin\lists\BaseAdminDataLists; +use app\common\model\dict\DictType; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; @@ -134,7 +135,11 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface ->toArray(); } + $check = DictType::where('type','activities')->find(); foreach ($data as &$value){ + if(isset($check) && $check['status'] == 1){ + $value['price'] = StoreProduct::where('product_id',$value['product_id'])->value('ot_price'); + } $value['is_default'] = 0; if($store_id == 2){ $value['is_default'] = 1; From 5eed480215d4ee9ca041fff733237008336b9a02 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:30:37 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/order/OrderList.php | 11 ++++++++++- app/api/logic/order/OrderLogic.php | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index d4d9f4e3a..10c6bf001 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -44,7 +44,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface { $userId=$this->request->userId; if(!$userId) return []; - return StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId) + $data = StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() @@ -55,6 +55,15 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface $item['goods_count']=count(explode(',',$item['cart_id'])); }) ->toArray(); + foreach ($data as &$value){ + if($value['refund_reason_time']){ + $value['refund_reason_time'] = date('Y-m-d H:i:s',$value['refund_reason_time']); + } + if($value['pay_time']){ + $value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']); + } + } + return $data; } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index dcb768d8f..0131ba697 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -756,6 +756,7 @@ class OrderLogic extends BaseLogic $order['vip_price'] = number_format($totalVipPrices, 2); $order['refund_price'] = number_format($totalPrice, 2); $order['verify_code'] = verificationCode(); + $order['refund_reason_time'] = time(); $order['create_time'] = time()+1; $order['update_time'] = null; $order['delete_time'] = null; From 6ad936237b8ad77d0f76116e01fb005dd7791ffe Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:34:20 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=94=AE=E5=90=8E?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 0131ba697..3d2b1990f 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -455,6 +455,7 @@ class OrderLogic extends BaseLogic [ 'refund_status'=>OrderEnum::CANCEL_SALE, 'status'=>OrderEnum::CANCEL_ORDER, + 'refund_cancle_time'=>date('Y-m-d H:i:s',time()) ] ); From 9299f52210b763b4e77c5b7596ab980efbc60f9a Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:42:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/order/OrderList.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index 10c6bf001..482b38719 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists; use app\common\lists\ListsSearchInterface; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product_unit\StoreProductUnit; /** * 零售订单列表 @@ -62,6 +63,9 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface if($value['pay_time']){ $value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']); } + foreach ($value['goods_list'] as &$vv){ + $vv['unit'] =StoreProductUnit::where('id',$vv['unit'])->value('name')??''; + } } return $data; } From e0f8caf64a833c724ca1678b5a20eb7bed8be9c2 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 10:52:56 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index fc7a1bf70..858ec8e5f 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -519,9 +519,9 @@ class OrderController extends BaseApiController ] public function refund_reason() { - return DictData::where('type_value','reason')->where('status',YesNoEnum::YES) + $data = DictData::where('type_value','reason')->where('status',YesNoEnum::YES) ->select()->toArray(); - + return $this->success('ok',$data); } From 7742312d73ac8491d9e1e05fc8e7746fda90e746 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 11:07:10 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E9=80=80=E6=AC=BE=E6=96=B0=E5=8A=A0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 1 + app/api/logic/order/OrderLogic.php | 6 ++++-- app/api/validate/OrderValidate.php | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 858ec8e5f..66e1f40d2 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -496,6 +496,7 @@ class OrderController extends BaseApiController ApiDoc\Param(name: "refund_num", type: "int", require: true, desc: "退款数量"), ApiDoc\Param(name: "id", type: "int", require: true, desc: "订单id"), ApiDoc\Param(name: "old_cart_id", type: "int", require: true, desc: "购物车id"), + ApiDoc\Param(name: "refund_type", type: "int", require: true, desc: "退款申请类型"), ApiDoc\NotHeaders(), ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), ApiDoc\ResponseSuccess("data", type: "array"), diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 3d2b1990f..f61c16aed 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -636,6 +636,7 @@ class OrderLogic extends BaseLogic $price =bcsub($price, $onePrice); } $order->refund_price = $price; + $order->refund_type = $params['refund_type']; $order->save(); }else{ // 多单的情况 拆主订单为新的2单 修改新的2单的核销码 修改cart_info的核销码 和订单id 退款直接退一单的钱 @@ -648,7 +649,7 @@ class OrderLogic extends BaseLogic ->whereNotIn('old_cart_id',$params['old_cart_id']) ->select()->toArray(); if($cart_info){ - $leftOrder = self::dealCreateLeftOrder($order,$cart_info); + $leftOrder = self::dealCreateLeftOrder($order,$cart_info,$params); self::dealChangeCartInfo($leftOrder); } $refundOrder = self::dealCreateRefundOrder($order,$params); @@ -683,7 +684,7 @@ class OrderLogic extends BaseLogic - public static function dealCreateLeftOrder($order,$cart_info) + public static function dealCreateLeftOrder($order,$cart_info,$params) { //查出不在这个退货中的数据 $order['order_id'] = $order['order_id'].'-2'; @@ -711,6 +712,7 @@ class OrderLogic extends BaseLogic } $order['cart_id'] = implode(',',$allOldCartIds); $order['total_num'] = count($cart_info); + $order['refund_type'] = $params['refund_type']; $order['total_price'] = number_format($totalTotal, 2); $order['pay_price'] = number_format($totalPrice, 2); $order['vip_price'] = number_format($totalVipPrice, 2); diff --git a/app/api/validate/OrderValidate.php b/app/api/validate/OrderValidate.php index b1bb8a593..f7e076323 100644 --- a/app/api/validate/OrderValidate.php +++ b/app/api/validate/OrderValidate.php @@ -22,6 +22,7 @@ class OrderValidate extends BaseValidate 'refund_num' => 'require|number', 'id' => 'require|number', 'old_cart_id' => 'require|array', + 'refund_type' => 'require|number', ]; @@ -35,6 +36,7 @@ class OrderValidate extends BaseValidate 'refund_num' => '退款数量', 'id' => '订单id', 'old_cart_id' => '购物车id', + 'refund_type' => '退款申请类型', ]; @@ -55,7 +57,7 @@ class OrderValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['refund_message','refund_num','id','old_cart_id']); + return $this->only(['refund_message','refund_num','id','old_cart_id','refund_type']); }