diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 34307b5c..41431281 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -116,40 +116,7 @@ class StoreOrderController extends BaseAdminController if(empty($detail)){ return $this->fail('无该订单请检查'); } - //微信支付 - if(in_array($detail['pay_type'],[PayEnum::WECHAT_PAY_MINI,PayEnum::WECHAT_PAY_BARCODE])){ - $money = (int)bcmul($detail['pay_price'],100); - $refund = (new \app\common\logic\store_order\StoreOrderLogic()) - ->refund($params['order_id'],$money,$money); - if($refund){ -// $arr = [ -// 'amount'=>[ -// 'refund'=>$money -// ] -// ]; -// PayNotifyLogic::refund($params['order_id'],$arr); - return $this->success(); - } - } - //余额支付 采购款支付 - if (in_array($detail['pay_type'] ,[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){ - $money = bcmul($detail['pay_price'],100); - $arr = [ - 'amount'=>[ - 'refund'=>$money - ] - ]; - PayNotifyLogic::refund($params['order_id'],$arr); - return $this->success(); - - } - //现金支付 - if($detail['pay_type'] = PayEnum::CASH_PAY){ - PayNotifyLogic::cash_refund($params['order_id']); - return $this->success(); - } - //todo 支付包支付 - + StoreOrderLogic::refund($detail,$params); return $this->fail('退款失败'); } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 23379ef9..96ded6ae 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -2,9 +2,10 @@ namespace app\admin\logic\store_order; - +use app\common\enum\PayEnum; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; +use app\common\logic\PayNotifyLogic; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use think\facade\Db; @@ -29,9 +30,7 @@ class StoreOrderLogic extends BaseLogic { Db::startTrans(); try { - StoreOrder::create([ - - ]); + StoreOrder::create([]); Db::commit(); return true; @@ -54,9 +53,7 @@ class StoreOrderLogic extends BaseLogic { Db::startTrans(); try { - StoreOrder::where('id', $params['id'])->update([ - - ]); + StoreOrder::where('id', $params['id'])->update([]); Db::commit(); return true; @@ -90,11 +87,42 @@ class StoreOrderLogic extends BaseLogic */ public static function detail($params): array { - $data= StoreOrder::findOrEmpty($params['id']); - if($data){ - $data['status_name']=$data->status_name_text; - $data['pay_time']=date('Y-m-d H:i:s',$data['pay_time']); + $data = StoreOrder::findOrEmpty($params['id']); + if ($data) { + $data['status_name'] = $data->status_name_text; + $data['pay_time'] = date('Y-m-d H:i:s', $data['pay_time']); } return $data?->toArray(); } -} \ No newline at end of file + + public static function refund($detail, $params) + { + //微信支付 + if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { + $money = (int)bcmul($detail['pay_price'], 100); + $refund = (new \app\common\logic\store_order\StoreOrderLogic()) + ->refund($params['order_id'], $money, $money); + if ($refund) { + return '退款成功'; + } + } + //余额支付 采购款支付 + if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + $money = bcmul($detail['pay_price'], 100); + $arr = [ + 'amount' => [ + 'refund' => $money + ] + ]; + PayNotifyLogic::refund($params['order_id'], $arr); + return '退款成功'; + } + //现金支付 + if ($detail['pay_type'] = PayEnum::CASH_PAY) { + PayNotifyLogic::cash_refund($params['order_id']); + return '退款成功'; + } + return false; + //todo 支付包支付 + } +} diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index a72a2206..f88ec318 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -2,6 +2,7 @@ namespace app\api\controller\order; +use app\admin\logic\store_order\StoreOrderLogic; use app\api\logic\order\OrderLogic; use app\api\controller\BaseApiController; use app\api\lists\order\OrderList; @@ -413,15 +414,9 @@ class OrderController extends BaseApiController } } - // #[ - // ApiDoc\Title('核销'), - // ApiDoc\url('/api/order/order/writeoff_order'), - // ApiDoc\Method('POST'), - // ApiDoc\Param(name: "verify_code", type: "string", require: true, desc: "验证码"), - // ApiDoc\NotHeaders(), - // ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), - // ApiDoc\ResponseSuccess("data", type: "array"), - // ] + /** + * 核销 + */ public function writeoff_order() { $params = (new OrderValidate())->post()->goCheck('check'); @@ -453,25 +448,19 @@ class OrderController extends BaseApiController } - // #[ - // ApiDoc\Title('订单退款申请'), - // ApiDoc\url('/api/order/order/apply_refund'), - // ApiDoc\Method('POST'), - // ApiDoc\Param(name: "refund_message", type: "string", require: true, desc: "退款原因"), - // 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"), - // ] + /** + * 订单退款申请 + */ public function apply_refund() { $params = (new OrderValidate())->post()->goCheck('add'); $uid = $this->userId; //拆单逻辑 OrderLogic::dealRefund($uid, $params); + $detail = StoreOrder::where('id', $params['id'])->where('refund_type',1)->where('status','in',[0,1])->find(); + if($detail){ + StoreOrderLogic::refund($detail,['order_id'=>$detail['order_id']]); + } return $this->success('申请成功'); } diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index f5982542..fae9c37f 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -102,6 +102,11 @@ class LoginLogic extends BaseLogic //返回登录信息 $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar'); $avatar = FileService::getFileUrl($avatar); + if($user->store_id){ + $share_name=SystemStore::where('id',$user->store_id)->value('abbreviation'); + }else{ + $share_name=SystemStore::where('id',4)->value('abbreviation'); + } return [ 'avatar' => $avatar, 'id'=>$userInfo['user_id'], @@ -113,6 +118,7 @@ class LoginLogic extends BaseLogic // 'sn' => $userInfo['sn'], 'token' => $userInfo['token'], 'real_name' => $userInfo['real_name'], + 'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']), ]; } catch (\Exception $e) { self::setError($e->getMessage()); diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index ef5a9590..8eb727c1 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -86,7 +86,7 @@ class UserLogic extends BaseLogic { $data = User::with(['userShip'])->where('id',$uid) ->field('id,avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship - ,purchase_funds,integral,pay_password,label_id') + ,purchase_funds,integral,pay_password,label_id,store_id') ->find(); //判断是不是员工 if($data){ @@ -101,12 +101,10 @@ class UserLogic extends BaseLogic $data['next_limit'] = $new['limit'] - $data['total_recharge_amount']; } $data['is_staff'] = 0; - $data['store_id'] = 0; if(isset($data['mobile']) && $data['mobile']){ $check = DeliveryService::where('phone',$data['mobile'])->find()??[]; if ($check){ $data['is_staff'] = 1; - $data['store_id'] = $check['store_id']; } } $data['label_name']=UserLabel::where('label_id',$data['label_id'])->value('label_name'); @@ -125,6 +123,12 @@ class UserLogic extends BaseLogic $number = UserSign::where('uid',$uid)->where(['status'=>0])->sum('number'); $data['number'] =bcadd($number,0,2); $data['GetNumber'] =bcadd($GetNumber,0,2); + if($data['store_id']){ + $share_name=SystemStore::where('id',$data['store_id'])->value('abbreviation'); + }else{ + $share_name=SystemStore::where('id',4)->value('abbreviation'); + } + $data['share_name']= $share_name.'No.'.preg_replace('/4/','*', $data['id']); }else{ $data = []; }