From 17239d39e84b80babded41e3193e62e875bb65a3 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 18 Jun 2024 15:27:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=BF=81=E7=A7=BBvip=E4=B8=BA1=E5=BE=97?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=BE=97=E5=86=BB=E7=BB=93=E9=87=91=E9=A2=9D?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=BE=97=E5=B8=A6=E8=BF=94=E5=9B=9E=E5=86=BB=E7=BB=93=E9=87=91?= =?UTF-8?q?=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/user/UserLogic.php | 6 ++-- app/common/logic/PayNotifyLogic.php | 43 ++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index bdbd73512..e6b493914 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -15,6 +15,8 @@ use app\common\{logic\BaseLogic, model\user\UserRecharge, model\user\UserShip, service\wechat\WeChatMnpService}; +use think\facade\Db; + /** * 会员逻辑层 @@ -90,8 +92,8 @@ class UserLogic extends BaseLogic $data['store_id'] = $check['store_id']; } } - $data['return_money'] = StoreFinanceFlow:: - where(['user_id'=>$uid,'status'=>0,'financial_pm'=>0]) + $data['return_money'] = Db::name('vip_flow')-> + where(['user_id'=>$uid,'status'=>0]) ->sum('number'); }else{ diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index a9c5d72c0..f7923921f 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -10,6 +10,7 @@ use app\common\model\finance\PayNotifyLog; use app\common\model\pay\PayNotify; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\system_store\SystemStore; use app\common\model\user\User; use app\common\model\user\UserAddress; @@ -114,7 +115,7 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'],'',1,$order['store_id']); if ($user['user_ship'] == 1) { - VipLogic::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); + self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); } // self::afterPay($order); @@ -311,6 +312,11 @@ class PayNotifyLogic extends BaseLogic //商户应该获得的钱 每个商品的price-ot_price 利润 // if (isset($order->profit) && $order->profit > 0) { if ($order['uid'] > 0) { + //用户下单该用户等级为1得时候才处理冻结金额 + $user = User::where('id', $order['uid'])->find(); + if ($user['user_ship'] == 1) { + self::dealVipAmount($order, $order['pay_type']); + } $user_number = bcmul($order['pay_price'], '0.10', 2); $sing = [ 'uid' => $order['uid'], @@ -460,4 +466,39 @@ class PayNotifyLogic extends BaseLogic ]; PayNotify::create($data); } + + + /** + * 处理用户为vip1时得冻结资金 + * @param $order + * @param $pay_type + * @param $transaction_id + * @return true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function dealVipAmount($order,$pay_type =1, $transaction_id = 0) + { + $detail = StoreOrderCartInfo::where('oid',$order['id'])->select()->toArray(); + $total_vip = 0; + foreach ($detail as $value){ + $total_vip +=$value['cart_info']['vip_frozen_price']; + } + $data=[ + 'order_id' => $order['id'], + 'transaction_id' => $transaction_id??0, + 'order_sn' =>$order['order_id'], + 'user_id' => $order['uid'], + 'number' => $total_vip, + 'pay_type' => $pay_type??1, + 'status' => 0, + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], + 'create_time'=>time() + ]; + Db::name('vip_flow')->insert($data); + return true; + } + } From b23cafcb64a9d4b19adb2e851dff330ee40850d6 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 18 Jun 2024 16:18:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E4=B8=BA1=E6=97=B6=E6=83=85=E5=86=B5=E4=B8=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=87=91=E9=A2=9D=E4=B8=BA=E6=94=AF=E4=BB=98=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E5=87=8F=E5=8E=BB=E5=86=BB=E7=BB=93=E9=87=91=E9=A2=9D?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 43 ++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index f7923921f..748971e67 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -304,14 +304,10 @@ class PayNotifyLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $user_sing = new UserSign(); - $financeLogic->order = $order; - $financeLogic->user = ['uid' => $order['uid']]; - // if ($order->pay_type != 9 || $order->pay_type != 10) { - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 - $count_frees = 0; - //商户应该获得的钱 每个商品的price-ot_price 利润 - // if (isset($order->profit) && $order->profit > 0) { if ($order['uid'] > 0) { + // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 + $vipFrozenAmount = self::dealFrozenPrice($order['id']); + $order['pay_price'] = bcsub($order['pay_price'],$vipFrozenAmount,2); //用户下单该用户等级为1得时候才处理冻结金额 $user = User::where('id', $order['uid'])->find(); if ($user['user_ship'] == 1) { @@ -329,6 +325,12 @@ class PayNotifyLogic extends BaseLogic User::where('id', $order['uid'])->inc('integral', $user_number)->update(); } + $financeLogic->order = $order; + $financeLogic->user = ['uid' => $order['uid']]; + // if ($order->pay_type != 9 || $order->pay_type != 10) { + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $count_frees = 0; + //平台手续费 $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); $count_frees = bcadd($count_frees, $fees, 2); @@ -467,6 +469,25 @@ class PayNotifyLogic extends BaseLogic PayNotify::create($data); } + /** + * 冻结金额 + * @param $oid + * @return int|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + + public static function dealFrozenPrice($oid) + { + $detail = StoreOrderCartInfo::where('oid',$oid)->select()->toArray(); + $total_vip = 0; + foreach ($detail as $value){ + $total_vip +=$value['cart_info']['vip_frozen_price']; + } + return $total_vip; + } + /** * 处理用户为vip1时得冻结资金 @@ -478,13 +499,9 @@ class PayNotifyLogic extends BaseLogic * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function dealVipAmount($order,$pay_type =1, $transaction_id = 0) + public static function dealVipAmount($order,$pay_type =1,$transaction_id = 0) { - $detail = StoreOrderCartInfo::where('oid',$order['id'])->select()->toArray(); - $total_vip = 0; - foreach ($detail as $value){ - $total_vip +=$value['cart_info']['vip_frozen_price']; - } + $total_vip = self::dealFrozenPrice($order['id']); $data=[ 'order_id' => $order['id'], 'transaction_id' => $transaction_id??0, From 479de5cc419bb4c067d97af79c29418d411b2486 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 18 Jun 2024 16:57:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=89=A3=E9=99=A4=E9=87=91=E9=A2=9D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 31 ++++++++++--------- .../logic/store_order/StoreOrderLogic.php | 13 ++++++-- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 1728473f1..6f66fd902 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -85,23 +85,32 @@ class OrderLogic extends BaseLogic $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 -// if ($user && $user['user_ship'] == 4) { -// $deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2); -// $cart_select[$k]['deduction_price'] =$deduction_price_count; -// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); -// } + if ($user && $user['user_ship'] == 1) { + //更新 会员为1的时候原价减去会员价 + $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + } + if ($user && $user['user_ship'] == 4) { + //更新 为4商户的时候减去商户价格 + $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + } + //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价 + $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价 + $cart_select[$k]['product_id'] = $find['product_id']; $cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; //vip1待返回金额 - - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],2); + $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2); // d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] ); $cartInfo = $cart_select[$k]; $cartInfo['name'] = $find['store_name']; @@ -119,13 +128,7 @@ class OrderLogic extends BaseLogic self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格 // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } - $preferential_amount = 0;//差价(用户为UserShipEnum::DISCOUNT_ARRAY 的时候的优惠差价) - $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 - if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){ - $pay_price =bcsub(self::$store_price, self::$activity_price, 2); //减去活动优惠金额 - $preferential_amount = bcsub(self::$pay_price,self::$store_price,2); - } $vipPrice = 0; //成本价 收益 @@ -148,8 +151,6 @@ class OrderLogic extends BaseLogic 'activities' => self::$activity_price>0?1:0, 'deduction_price' => self::$activity_price, 'is_vip' => 0, - 'preferential_amount' => $preferential_amount, - ]; $order['default_delivery'] = 0; if ($params['store_id']) { diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index bbb40ea62..00f2c5150 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -62,8 +62,16 @@ class StoreOrderLogic extends BaseLogic $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 + if ($user && $user['user_ship'] == 1) { + //更新 会员为1的时候原价减去会员价 + $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + } + if ($user && $user['user_ship'] == 4) { - $deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2); + //更新 为4商户的时候减去商户价格 + $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); $cart_select[$k]['deduction_price'] =$deduction_price_count; self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); } @@ -72,13 +80,14 @@ class StoreOrderLogic extends BaseLogic $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价 + $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价 $cart_select[$k]['product_id'] = $find['product_id']; $cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; //vip1待返回金额 - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],2); + $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2); $cartInfo = $cart_select[$k]; $cartInfo['name'] = $find['store_name']; $cartInfo['image'] = $find['image']; From f00ca73aa97b0e74bf6540e7761d9fa0280f0f26 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 18 Jun 2024 17:27:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9C=80=E8=BF=91=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 8 +++++++- app/api/logic/order/OrderLogic.php | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 0d6e336ff..27553902d 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -366,12 +366,18 @@ class OrderController extends BaseApiController public function detail() { $order_id = (int)$this->request->get('order_id'); + $lat = $this->request->get('lat',''); + $lng = $this->request->get('long',''); $where = [ 'id' => $order_id, 'uid' => $this->userId, ]; $url = 'https://'.$this->request->host(true); - $order = OrderLogic::detail($where,$url); + $parm = [ + 'lat'=>$lat, + 'long'=>$lng + ]; + $order = OrderLogic::detail($where,$url,$parm); if ($order) { return $this->data($order); } else { diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 6f66fd902..38ce2fe1d 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -338,7 +338,7 @@ class OrderLogic extends BaseLogic } - public static function detail($params,$url=''): array + public static function detail($params,$url='',$param=[]): array { $find = StoreOrder::where($params)->findOrEmpty()->toArray(); if ($find) { @@ -360,6 +360,24 @@ class OrderLogic extends BaseLogic if($find['verify_img']){ $find['verify_img'] = $url.$find['verify_img']; } + //处理返回最近的店铺 + if($param['lat'] && $param['long']){ + $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); + $nearestStore = null; + $minDistance = PHP_FLOAT_MAX; + foreach ($storeAll as $value){ + $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$param['lat'] ,$param['long']); + if ($value['distance'] < $minDistance) { + $minDistance = $value['distance']; + $nearestStore = $value; + } + } + if ($nearestStore) { + $find['near_store'] =$nearestStore; + + } + + } } return $find; } From e200cdcd67c1f8669bc0db12d271d44504668b16 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 18 Jun 2024 17:33:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=94=B6=E9=93=B6=E5=8F=B0=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/controller/store_order/StoreOrderController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index d4213a31a..70d8173e4 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -82,7 +82,8 @@ class StoreOrderController extends BaseAdminController $cartId = (array)$this->request->post('cart_id', []); $params = $this->request->post(); $params['store_id'] = $this->adminInfo['store_id']; - $res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, null, $params); + $user=User::where('id',$params['uid'])->find(); + $res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, $user, $params); if ($res == false) { $msg = StoreOrderLogic::getError(); if ($msg == '购物车为空') {