From 51df5a3a94e81a054a7556aa45f7004863d0a78b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 28 Jun 2024 18:38:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=A0=B8=E9=94=80=E9=80=BB=E8=BE=91=E5=92=8C=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E9=80=9A=E7=9F=A5=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 | 73 ++----------------- app/common/logic/PayNotifyLogic copy.php | 2 +- app/common/logic/StoreFinanceFlowLogic.php | 61 +++++++++------- .../store_order/StoreOrderController.php | 4 +- 4 files changed, 42 insertions(+), 98 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index f67932394..2393ae4d6 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -432,17 +432,14 @@ class OrderLogic extends BaseLogic 'staff_id' => $params['staff_id']??0, 'update_time' => time(), ], ['oid' => $order['id']]); - // $financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']); - // if (!empty($financeFlow)) { - // $capitalFlowLogic = new CapitalFlowLogic($data->store, 'store'); - // $capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']); - // } PayNotifyLogic::descStock($order['id']); $financeFlow=new StoreFinanceFlow(); $financeFlowLogic=new StoreFinanceFlowLogic(); - $select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15],'other_uid'=>['>'=>0]])->select(); + $select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15,16]])->select(); foreach($select_1 as $k=>$v){ - $financeFlowLogic->updateStatusUser($v['id'],$v['other_uid'],$v['number'],$v['order_id']); + if($v['other_uid']>0){ + $financeFlowLogic->updateStatusUser($v['id'],$v['other_uid'],$v['number'],$v['order_id']); + } } if($order['uid'] && $order['pay_price'] >= 500){ $user_number = bcmul($order['pay_price'], '0.10', 2); @@ -455,67 +452,9 @@ class OrderLogic extends BaseLogic $financeFlowLogic->updateStatusUser($spread_find['id'],$order['spread_uid'],$spread_find['number'],$order['order_id']); } } - $deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number'); - $money=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>2])->value('number'); + $deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number')??0; + $money=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>2])->value('number')??0; $financeFlowLogic->updateStatusStore($order['id'],$order['store_id'],$money,$deposit); - - /* $check = Db::name('user_sign_log')->where('order_id',$order['order_id']) - ->where(['status'=>0]) - ->find();//$check['number']扣的 - if($check){ -// User::where('id',$order['uid'])->inc('purchase_funds',$check['number'])->update(); -// $user_number = bcmul($order['pay_price'], '0.10', 2); - - $base = UserSign::where([ - 'uid'=>$order['uid'], - 'type'=>1, - 'status'=>1 - ])->find(); - $user_sing = new UserSign(); - if($base['number'] > 0 && $base['number'] >= $check['number']){ - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'].'-b', - 'title' => '返还兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'status' => 1, - ]; - $sing['number'] = $check['number']; - $user_sing->save($sing); - User::where('id',$order['uid'])->inc('integral',$check['number'])->update(); - //减少 - UserSign::where('id',$check['sid'])->dec('number',$check['number'])->update(); - if($base['number'] == $check['number']){ - UserSign::where([ - 'id'=>$order['sid'] - ])->update(['status'=>1]); - } - } - if($base['number'] < $check['number']){ - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'].'-b', - 'title' => '返还兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'status' => 1, - ]; - $sing['number'] = $base['number']; - $user_sing->save($sing); - - UserSign::where('id',$check['sid'])->dec('number',$base['number'])->update(); - User::where('id',$order['uid'])->inc('integral',$base['number'])->update(); - - - UserSign::where([ - 'id'=>$order['sid'] - ])->update(['status'=>1]); - } - - Db::name('user_sign_log')->where('order_id',$order['order_id'])->update(['status'=>1]); - }*/ - Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/PayNotifyLogic copy.php b/app/common/logic/PayNotifyLogic copy.php index a03f8fd3e..3f641cfbc 100644 --- a/app/common/logic/PayNotifyLogic copy.php +++ b/app/common/logic/PayNotifyLogic copy.php @@ -36,7 +36,7 @@ use Webman\RedisQueue\Redis; * Class PayNotifyLogic * @package app\api\logic */ -class PayNotifyLogic extends BaseLogic +class PayNotifyLogicaaa extends BaseLogic { public static function handle($action, $orderSn, $extra = [], $type = 'wechat') diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 534ce5091..3d63b48d5 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -27,9 +27,9 @@ class StoreFinanceFlowLogic extends BaseLogic * @param $staffId * @param $status */ - public function out($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7) + public function out($transaction_id, $number, $financialType, $storeId = 0, $staffId = 0, $status = 1, $pay_type = 7) { - $this->setData($number, $financialType, 0, $storeId, $staffId, $status,$transaction_id,$pay_type); + $this->setData($number, $financialType, 0, $storeId, $staffId, $status, $transaction_id, $pay_type); } /** @@ -41,22 +41,22 @@ class StoreFinanceFlowLogic extends BaseLogic * @param $staffId * @param $status */ - public function in($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7) + public function in($transaction_id, $number, $financialType, $storeId = 0, $staffId = 0, $status = 1, $pay_type = 7) { - $this->setData($number, $financialType, 1, $storeId, $staffId, $status,$transaction_id,$pay_type); + $this->setData($number, $financialType, 1, $storeId, $staffId, $status, $transaction_id, $pay_type); } - public function setData($number, $financialType, $pm, $storeId, $staffId, $status,$transaction_id,$pay_type=7) + public function setData($number, $financialType, $pm, $storeId, $staffId, $status, $transaction_id, $pay_type = 7) { if (empty($this->financeSn)) { $this->financeSn = $this->getSn(); } - $data=[ + $data = [ 'order_id' => $this->order['id'], 'transaction_id' => $transaction_id, 'order_sn' => $this->order['order_id'], - 'user_id' => $this->user['uid']??0, - 'other_uid' => $this->other_arr['vip_uid']??0, + 'user_id' => $this->user['uid'] ?? 0, + 'other_uid' => $this->other_arr['vip_uid'] ?? 0, 'financial_type' => $financialType, 'financial_pm' => $pm, 'number' => $number, @@ -65,22 +65,22 @@ class StoreFinanceFlowLogic extends BaseLogic 'store_id' => $storeId !== '' ? $storeId : $this->order['store_id'], 'staff_id' => $staffId !== '' ? $staffId : $this->order['staff_id'], 'financial_record_sn' => $this->financeSn . ($this->index++), - 'create_time'=>time() + 'create_time' => time() ]; - switch($financialType){ + switch ($financialType) { case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户 case OrderEnum::ORDER_MARGIN: // 商户保证金 - $data['type'] =OrderEnum::MERCHANT; + $data['type'] = OrderEnum::MERCHANT; break; case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台 case OrderEnum::ORDER_HANDLING_FEES: // 手续费 - $data['type'] =OrderEnum::PLATFORM; + $data['type'] = OrderEnum::PLATFORM; break; - case OrderEnum::SUPPLIER_ORDER_OBTAINS: // 供应链 - $data['type'] =OrderEnum::SUPPLIER; + case OrderEnum::SUPPLIER_ORDER_OBTAINS: // 供应链 + $data['type'] = OrderEnum::SUPPLIER; break; default: // 用户 - $data['type'] =OrderEnum::USER; + $data['type'] = OrderEnum::USER; break; } $this->list[] = $data; @@ -131,30 +131,35 @@ class StoreFinanceFlowLogic extends BaseLogic /** * 核销后更新用户余额 */ - public function updateStatusUser($id,$uid,$money,$order_id){ + public function updateStatusUser($id, $uid, $money, $order_id) + { StoreFinanceFlow::where('id', $id)->update(['status' => 1]); - $find=User::where('id',$uid)->find(); + $find = User::where('id', $uid)->find(); $capitalFlowDao = new CapitalFlowLogic($find); $capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money); - $find->inc('now_money',$money)->update(); + $find->inc('now_money', $money)->update(); } /** * 核销后更新门店余额 */ - public function updateStatusStore($order_id,$store_id,$money,$deposit){ - StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>11])->update(['status' => 1]); - StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>2])->update(['status' => 1]); - if($money){ + public function updateStatusStore($order_id, $store_id, $money, $deposit) + { + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 11])->update(['status' => 1]); + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2])->update(['status' => 1]); + if ($money>0) { SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); } - if($deposit){ + if ($deposit>0) { SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); } - $find=StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>16])->find(); - if($find){ - $find->update(['status' => 1]); - SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); + + $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16])->find(); + if ($find) { + $find->status=1; + $find->save(); + if ($find['number'] > 0) { // 核销后更新库存 + SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); + } } } - } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 6527e6e78..e1ea16893 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -310,8 +310,8 @@ class StoreOrderController extends BaseAdminController public function writeoff_order() { $params = (new OrderValidate())->post()->goCheck('check'); - $count = StoreOrder::where('verify_code', $params['verify_code'])->count(); - if (empty($count)) { + $count = StoreOrder::where('verify_code', $params['verify_code'])->find(); + if (!$count) { return $this->fail('无该核销码请检查'); } $params['store_id'] = $this->adminInfo['store_id'];