From d8f6fce0a4cf15070f344b9160656a109e7c76d9 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 22 Jun 2024 16:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=A4=BC=E5=93=81=E5=88=B8?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0,=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E4=B8=8B=E5=8D=95=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 48 ++++++++++++++++- app/common/enum/PayEnum.php | 2 + app/common/logic/PayNotifyLogic.php | 52 ++++++++++++++++++- .../logic/store_order/StoreOrderLogic.php | 12 ++--- .../store_order/StoreOrderController.php | 35 ++++++++++--- .../store_order/StoreOrderValidate.php | 4 +- 6 files changed, 137 insertions(+), 16 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 66a0edb63..e415982ba 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -131,7 +131,7 @@ class OrderLogic extends BaseLogic } //加支付方式限制 $pay_type = isset($params['pay_type'])?$params['pay_type']:0; - if ($user && $user['user_ship'] == 1 && $pay_type ==17) { + if ($user && $user['user_ship'] == 1 && $pay_type !=17) { $pay_price = self::$pay_price; }else{ $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 @@ -399,7 +399,6 @@ class OrderLogic extends BaseLogic //核销 - /** * @param $params * @return bool @@ -452,6 +451,51 @@ class OrderLogic extends BaseLogic } } + //不走二次分钱的核销 + public static function lessWriteOff($params): bool + { + $data = StoreOrder::with('store')->where([ + 'verify_code' => $params['verify_code'] + ])->find(); + if (empty($data)) { + return false; + } + Db::startTrans(); + try { + StoreOrder::update([ + 'verify_code'=>$params['verify_code'].'-1', + 'status' => OrderEnum::RECEIVED_GOODS, + 'is_writeoff' => OrderEnum::IS_OK, + 'update_time' => time(), + 'store_id' => $params['store_id'], + 'staff_id' => $params['staff_id']??0, + ], ['id' => $data['id']]); + (new StoreOrderCartInfo())->update([ + 'verify_code'=>$params['verify_code'].'-1', + 'writeoff_time' => time(), + 'is_writeoff' => YesNoEnum::YES, + 'store_id' => $params['store_id'], + 'staff_id' => $params['staff_id']??0, + 'update_time' => time(), + ], ['oid' => $data['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']); + // } + $order=StoreOrder::where('id',$data['id'])->find(); + PayNotifyLogic::descStock($order['id']); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + public static function write_count($info, $params) { diff --git a/app/common/enum/PayEnum.php b/app/common/enum/PayEnum.php index 7cf6e2364..9bdd5dfaa 100644 --- a/app/common/enum/PayEnum.php +++ b/app/common/enum/PayEnum.php @@ -32,6 +32,7 @@ class PayEnum * @CORPORATE_TRANSFER 对公转账 * @CASH_PAY 现金支付 * @PURCHASE_FUNDS 采购款收银 + * @GIFT_FUNDS 礼品券收银 */ const BALANCE_PAY = 3; const WECHAT_PAY = 1; @@ -51,6 +52,7 @@ class PayEnum const CORPORATE_TRANSFER = 16; const CASH_PAY = 17; const PURCHASE_FUNDS = 18;//采购款收银 + const GIFT_FUNDS = 19;//礼品券收银 //支付状态 const UNPAID = 0; //未支付 const ISPAID = 1; //已支付 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index b46de930e..198915e16 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -37,7 +37,7 @@ class PayNotifyLogic extends BaseLogic { Db::startTrans(); try { - if ($action != 'cash_pay' && $action != 'balancePay' && $action != 'purchase_funds') { + if ($action != 'cash_pay' && $action != 'balancePay' && $action != 'purchase_funds' && $action != 'gift_pay') { $payNotifyLogLogic = new PayNotifyLogLogic(); if ($action == 'refund') { $payNotifyLogLogic->insert($action, $extra, PayNotifyLog::TYPE_REFUND); @@ -98,6 +98,56 @@ class PayNotifyLogic extends BaseLogic // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } + /** + * 礼品券支付 + * @param $orderSn + * @param $extra + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + + public static function gift_pay($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + $user = User::where('id', $order['uid'])->find(); + if ($user['integral'] < $order['pay_price']) { + throw new \Exception('礼品券不足'); + } + $order->money = $order['pay_price']; + $order->paid = 1; + $order->pay_time = time(); + if (!$order->save()) { + throw new \Exception('订单保存出错'); + } + // 减去礼品券 + $user->integral = bcsub($user['integral'], $order['pay_price'], 2); + $user->save(); + //入礼品券表扣款记录 + $sing[] = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '订单扣除兑换券', + 'store_id' => $order['store_id'], + 'number' => $order['pay_price'], + 'financial_pm' => 0, + 'user_ship' => $user['user_ship'], + ]; + (new UserSign())->saveAll($sing); + + if($extra && $extra['store_id']){ + $params = [ + 'verify_code'=>$order['verify_code'], + 'store_id'=>$extra['store_id'], + 'staff_id'=>$extra['staff_id'] + ]; + OrderLogic::lessWriteOff($params); + } + self::dealProductLog($order); + + } + /** * 采购款支付 diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 05f2af497..71277f06e 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -356,14 +356,14 @@ class StoreOrderLogic extends BaseLogic throw new \Exception('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); - if($type){ - $check =(new SmsService())->client($phone,$template,$code,1); - }else{ - $check =(new SmsService())->client($phone,$template,$code); - } + $check =(new SmsService())->client($phone,$template,$code); if($check){ - $remark = $param['uid'].'_smsPay'; + if($type == 1){ + $remark = $param['uid'].'_smsPay'; + }else{ + $remark = $param['uid'].'_giftPay'; + } Cache::set($remark,$code,5*60); return true; }else{ diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 486fab101..6cf10d97d 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -109,10 +109,17 @@ class StoreOrderController extends BaseAdminController if (!$order) { return $this->fail(StoreOrderLogic::getError()); } - if ($order['order']['pay_price'] > $user['purchase_funds']) { - return $this->fail('当前用户采购款不足支付'); + if($params['type'] == 1){ + if ($order['order']['pay_price'] > $user['purchase_funds']) { + return $this->fail('当前用户采购款不足支付'); + } + }elseif ($params['type'] == 2){ + if ($order['order']['pay_price'] > $user['integral']) { + return $this->fail('当前用户礼品券不足支付'); + } } - $res = (new StoreOrderLogic())->dealSendSms($params); + + $res = (new StoreOrderLogic())->dealSendSms($params,$params['type']); if ($res) { return $this->success('发送成功', [], 1, 0); } else { @@ -132,7 +139,8 @@ class StoreOrderController extends BaseAdminController $auth_code = $this->request->post('auth_code'); //微信支付条码 $uid=$this->request->post('uid'); $params = $this->request->post(); - if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY && $pay_type != PayEnum::PURCHASE_FUNDS) { + if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY && $pay_type != PayEnum::PURCHASE_FUNDS + && $pay_type != PayEnum::GIFT_FUNDS) { return $this->fail('支付条码不能为空'); } if (count($cartId) > 100) { @@ -141,10 +149,19 @@ class StoreOrderController extends BaseAdminController if($pay_type == PayEnum::PURCHASE_FUNDS){ $remark = $uid.'_smsPay'; $code = Cache::get($remark); - if ($code && isset($params['code']) && $code !== $params['code']) { + if ($code && isset($params['code']) && $code != $params['code']) { throw new Exception('验证码错误'); } } + + if($pay_type == PayEnum::GIFT_FUNDS){ + $remark = $uid.'_giftPay'; + $code = Cache::get($remark); + if ($code && isset($params['code']) && $code != $params['code']) { + throw new Exception('验证码错误'); + } + } + $user = null; if ($uid) { $user = User::where('id', $uid)->find(); @@ -160,7 +177,13 @@ class StoreOrderController extends BaseAdminController 'staff_id'=>$this->request->adminInfo['admin_id'] ]); return $this->success('采购款支付成功', ['id' => $order['id']]); - + case PayEnum::GIFT_FUNDS: + //礼品券支付 + PayNotifyLogic::handle('gift_pay', $order['order_id'],[ + 'store_id'=>$this->request->adminInfo['store_id'], + 'staff_id'=>$this->request->adminInfo['admin_id'] + ]); + return $this->success('礼品券支付成功', ['id' => $order['id']]); case PayEnum::CASH_PAY: //现金支付 PayNotifyLogic::handle('cash_pay', $order['order_id']); diff --git a/app/store/validate/store_order/StoreOrderValidate.php b/app/store/validate/store_order/StoreOrderValidate.php index 928c46581..adf8b8f9b 100644 --- a/app/store/validate/store_order/StoreOrderValidate.php +++ b/app/store/validate/store_order/StoreOrderValidate.php @@ -23,6 +23,7 @@ class StoreOrderValidate extends BaseValidate 'verify_code' => 'requireWithout:id', 'uid' => 'require|number', 'cart_id' => 'require|array', + 'type' => 'require|number', ]; @@ -33,6 +34,7 @@ class StoreOrderValidate extends BaseValidate protected $field = [ 'id' => 'id', 'verify_code' => '核销码', + 'type' => '发送短信类型', ]; @@ -85,7 +87,7 @@ class StoreOrderValidate extends BaseValidate public function sceneCheck() { - return $this->only(['uid','cart_id']); + return $this->only(['uid','cart_id','type']); } }