From fa6a543227c0ca317cedd22b66e7b5d6e0010084 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Tue, 8 Feb 2022 14:32:23 +0800 Subject: [PATCH] bsetter --- app/controller/api/Business.php | 2 +- app/controller/api/Coupon.php | 109 ++++++++++++++++++------------ app/controller/manager/Coupon.php | 15 +++- app/model/CouponMain.php | 3 + app/validate/CouponRelease.php | 2 +- 5 files changed, 84 insertions(+), 47 deletions(-) diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index f20d27c..774a8f2 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -800,7 +800,7 @@ class Business extends Base } /** - * 商家查看 + * 商家查看流水 * */ public function businessBill() { diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 0b38906..6d4416e 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -454,7 +454,7 @@ class Coupon extends Base } else { $distanceText = $distance . "米"; } - return $this->json(4001, "您距离商家位置距离超过规定距离{$distanceText}"); + return $this->json(4001, "您距离商家位置距离超过规定距离"); } } @@ -494,10 +494,10 @@ class Coupon extends Base "using_count" => Db::raw("using_count - 1"),//进行中数量-1 ]); + $deductionMoney = $coupon->couponMain->deduction_money; //可分配金额 如果是普通商家 if($business->model == BusinessModel::model_ordinary) { - $deductionMoney = $coupon->couponMain->deduction_money; $agencyMoney = (($deductionMoney/100) * $coupon->couponMain->commission_agency); $adminMoney = (($deductionMoney/100) * $coupon->couponMain->commission_admin); $consumerMoney = (($deductionMoney/100) * $coupon->couponMain->commission_consumer); @@ -505,7 +505,6 @@ class Coupon extends Base $adminMoney = round($adminMoney,2); //四舍五入 精确到分 $consumerMoney = round($consumerMoney,2); //四舍五入 精确到分 }else{ - $deductionMoney = $coupon->couponMain->deduction_money; $adminMoney = 0; $consumerMoney = round($deductionMoney,2) ; $agencyMoney = 0; //四舍五入 精确到分 @@ -560,47 +559,67 @@ class Coupon extends Base //如果付款过一次了 就查询付款状态 if(isset($coupon->redpack) && $coupon->redpack){ - $result = $payment->transfer->queryBalanceOrder($coupon->redpack->mch_billno); - //var_dump($result); - //企业付款成功 - if(isset($result["status"]) && $result["status"]=="SUCCESS"){ - Db::commit(); - return $this->json( - 0, - "优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱", - [ - "redpack" =>$consumerMoney - ]); - } - Log::info("查询企业付款失败:".json_encode($result,JSON_UNESCAPED_UNICODE)); + $mch_billno = $coupon->redpack->mch_billno; +// $result = $payment->transfer->queryBalanceOrder($coupon->redpack->mch_billno); +// //var_dump($result); +// //企业付款成功 +// if(isset($result["status"]) && $result["status"]=="SUCCESS"){ +// Db::commit(); +// return $this->json( +// 0, +// "优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱", +// [ +// "redpack" =>$consumerMoney +// ]); +// } +// Log::info("查询企业付款失败:".json_encode($result,JSON_UNESCAPED_UNICODE)); }else{ $mch_billno = createUuid(); - $amount = $consumerMoney * 100; - $toBalanceData = [ - 'partner_trade_no' => $mch_billno,// 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) - 'openid' => $account->open_id, - 'check_name' => 'NO_CHECK',// NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 - 'amount' => $amount, //单位为分,不小于100 - 'desc' => '验证优惠券签到', - ]; - //发起支付 - $result = $payment->transfer->toBalance($toBalanceData); - - //var_dump($result); - - //付款成功才提交!!!!!伪装成功 - if(isset($result['payment_no']) ){ - Db::commit(); - return $this->json( - 0, - "优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱", - [ - "redpack" =>$consumerMoney - ]); - } - Log::info("企业发起付款失败:" . json_encode($result,JSON_UNESCAPED_UNICODE)); } + $amount = $consumerMoney * 100; + + $toBalanceData = [ + 'partner_trade_no' => $mch_billno,// 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) + 'openid' => $account->open_id, + 'check_name' => 'NO_CHECK',// NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 + 'amount' => $amount, //单位为分,不小于100 + 'desc' => '验证优惠券签到', + ]; + + // 写入红包 + $redpackData = [ + "coupon_id" =>$coupon->id, + "mch_billno" =>$mch_billno, + "openid" =>$account->open_id, + "user_code" =>$account->user_code, + "money" =>$amount, + "create_time" => date("Y-m-d H:i:s",$time), + "pay_time" => '0000-00-00 00:00:00', + ]; + $redpack = Redpack::create($redpackData); + + //发起支付 + $result = $payment->transfer->toBalance($toBalanceData); + + //var_dump($result); + + //付款成功才提交!!!!!伪装成功 + if(isset($result['payment_no']) ){ + $redpack->pay_time = date("Y-m-d H:i:s",$time); + $redpack->save(); + + Db::commit(); + return $this->json( + 0, + "优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱", + [ + "redpack" =>$consumerMoney + ]); + } + Log::info("企业发起付款失败:" . json_encode($result,JSON_UNESCAPED_UNICODE)); + + //默认回滚 Db::rollback(); return $this->json(5003, "验证失败,发放红包失败"); @@ -612,7 +631,7 @@ class Coupon extends Base Db::rollback(); return $this->json(5001, "Repository服务器错误"); }catch (\Exception $e){ - //echo $e->getMessage(); + echo $e->getMessage(); Db::rollback(); return $this->json(5002, "服务器错误"); } @@ -682,7 +701,7 @@ class Coupon extends Base "white_list" => $data['white_list'] ?? '', "status" => CouponMain::status_on, "on_shelf" => CouponMain::on_shelf_off,//默认下架 后台审核上架 - "on_screen" => $data['on_screen'] ?? 1, + "on_screen" => CouponMain::on_screen_yes, "commission_agency" => $distributionProportion['agency'], "commission_admin" => $distributionProportion['admin'], "commission_consumer" => $distributionProportion['consumer'], @@ -723,6 +742,12 @@ class Coupon extends Base $couponMain['deduction_money'] = floor($couponMain['deduction_money'] * 100) / 100; $totalMoney = $couponMain['deduction_money'] * $couponMain['count']; + //检测消费者部分是否最少1元 + $consumerMoney = ($data['commission_consumer']/100) * $data['deduction_money']; + if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_consumer_money) { + return $this->json(4002, "消费者红包最低" . CouponMain::min_consumer_money . "元"); + } + //未领取的优惠券 $NotClaimedMoney = CouponRepository::getInstance()->getBusinessNotClaimedCoupon($account->business["code"]); if($account->business["model"] == BusinessModel::model_ordinary) { diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index e1987ba..1487aa5 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -222,9 +222,9 @@ class Coupon extends Base - $data['commission_agency'] = input("item.commission_agency/d", 0); - $data['commission_admin'] = input("item.commission_admin/d", 0); - $data['commission_consumer'] = input("item.commission_consumer/d", 0); + $data['commission_agency'] = input("item.commission_agency/d", 0,"abs"); + $data['commission_admin'] = input("item.commission_admin/d", 0,"abs"); + $data['commission_consumer'] = input("item.commission_consumer/d", 0,"abs"); $totalC = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; if ($totalC != 100) { @@ -234,6 +234,13 @@ class Coupon extends Base //保留两位小数 $data['deduction_money'] = floor($data['deduction_money'] * 100) / 100; + //检测消费者部分是否最少1元 + $consumerMoney = ($data['commission_consumer']/100) * $data['deduction_money']; + if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_consumer_money) { + return $this->json(4002, "消费者红包最低" . CouponMain::min_consumer_money . "元"); + } + + $totalMoney = $data['deduction_money'] * $data['count']; //未领取的优惠券 @@ -246,6 +253,8 @@ class Coupon extends Base } + + $date = date("Y-m-d H:i:s"); $data['create_time'] = $date; $data['update_time'] = $date; diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index 88a4e7f..0d41a49 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -21,6 +21,9 @@ class CouponMain extends Base const on_shelf_off = 1;//下架状态 const on_screen_yes = 1;//展示到商圈大屏 + const on_screen_no = 0;//不展示到商圈大屏 + + const min_consumer_money = 0.3;//红包最小金额 public function business() { diff --git a/app/validate/CouponRelease.php b/app/validate/CouponRelease.php index 2c60433..2aecb1f 100644 --- a/app/validate/CouponRelease.php +++ b/app/validate/CouponRelease.php @@ -17,7 +17,7 @@ class CouponRelease extends Validate 'end_time|结束时间' => 'require|date|checkEndTime', 'name|优惠券名称' => 'require|chsAlphaNum|length:3,32', //'money|金额' => 'require|>:0|<=:5000', - 'deduction_money|扣除金额' => 'require|>=:0.1|<=:5000', + 'deduction_money|扣除金额' => 'require|>=:0|<=:100000', 'image_url|预览图' => 'require', //'using_rule|使用规则' => '', //'punishing_rule|处罚规则' => '',