diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 52d5970..d52d234 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -384,6 +384,7 @@ class Business extends Base $data["lat"] = $couponMain->lat; $data["lng"] = $couponMain->lng; $data["money"] = $couponMain->money; + $data["is_distribution"] = $couponMain->is_distribution; $data["usingRule"] = DictionaryRepository::getInstance()->getUsingRuleByCouponMainId($couponMain->id); $data["punishRule"] = '';//处罚规则 已取消 diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 9546429..0685f16 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -287,9 +287,10 @@ class Coupon extends Base * */ public function receiveCoupon() { - $accountId = $this->request->user['user_id'] ?? 0; - $lat = input("lat/f",0); - $lng = input("lng/f",0); + $accountId = $this->request->user['user_id'] ?? 0; + $lat = input("lat/f",0); + $lng = input("lng/f",0); + $distributionUserCode = input("distribution_user_code/s",''); $account = AccountRepository::getInstance()->findById($accountId, [], function ($q) { return $q->with(['business', 'parent']); }); @@ -336,22 +337,23 @@ class Coupon extends Base try { //写入领取记录 $data = [ - "coupon_id" =>$couponMain->id, - "name" =>$couponMain->name, - "type_id" =>$couponMain->type, - "type_name" =>$couponMain->type_name, - "business_code" =>$couponMain->business_code, - "business_name" =>$couponMain->business?$couponMain->business->business_name:'', - "consumer_code" =>$account->user_code, - "consumer_name" =>$account->nick_name, - "money" => $couponMain->money, - "content" => createUuid(),//未知作用 - "received_time" => date("Y-m-d H:i:s",$time), - "lat" => $lat, - "lng" => $lng, - "end_time" => date($couponMain->end_time . " 00:00:00"), - "edition" => couponMain::COMMON_ON,//版本 未知作用 - "is_verificated" => couponMain::COMMON_OFF,//版本 未知作用 + "coupon_id" =>$couponMain->id, + "name" =>$couponMain->name, + "type_id" =>$couponMain->type, + "type_name" =>$couponMain->type_name, + "business_code" =>$couponMain->business_code, + "business_name" =>$couponMain->business?$couponMain->business->business_name:'', + "consumer_code" =>$account->user_code, + "consumer_name" =>$account->nick_name, + "money" => $couponMain->money, + "content" => createUuid(),//未知作用 + "received_time" => date("Y-m-d H:i:s",$time), + "lat" => $lat, + "lng" => $lng, + "end_time" => date($couponMain->end_time . " 00:00:00"), + "edition" => couponMain::COMMON_ON,//版本 未知作用 + "is_verificated" => couponMain::COMMON_OFF,//版本 未知作用 + "distribution_user_code" => $distributionUserCode,//分销人user_code ]; CouponRepository::getInstance()->receiveCoupon($data); $couponMain->save(["received_count"=>Db::raw("received_count + 1")]); @@ -666,7 +668,9 @@ class Coupon extends Base $data = input(); Config::load("extra/distribution_proportion","distribution_proportion"); - $distributionProportion = config("distribution_proportion"); + Config::load("extra/distribution_proportion_user","distribution_proportion_user"); + $distributionProportion = config("distribution_proportion"); + $distributionProportionUser = config("distribution_proportion_user"); $totalC = $distributionProportion['agency'] + $distributionProportion['admin'] + $distributionProportion['consumer']; if ($totalC != 100) { @@ -687,25 +691,31 @@ class Coupon extends Base //验证通过 不管是商家还是工作人员 都可以发布优惠券 $couponMain = [ - "name" => $data['name'] ?? '', - "business_code" => $account->business->code, + "name" => $data['name'] ?? '', + "business_code" => $account->business->code, //"money" => $data['money'] ?? 0, - "type" => $data['type'] ?? 0, - "count" => $data['count'] ?? 0, - "type_name" => $data['type_name'] ?? '', - "start_time" => $data['start_time'] ?? '', - "end_time" => $data['end_time'] ?? '', - "deduction_money" => $data['deduction_money'] ?? '', - "image_url" => $data['image_url'] ?? '', - "intro" => $data['intro'] ?? '', - "content" => $data['content'] ?? '', - "white_list" => $data['white_list'] ?? '', - "status" => CouponMain::status_on, - "on_shelf" => CouponMain::on_shelf_off,//默认下架 后台审核上架 - "on_screen" => CouponMain::on_screen_yes, - "commission_agency" => $distributionProportion['agency'], - "commission_admin" => $distributionProportion['admin'], - "commission_consumer" => $distributionProportion['consumer'], + "type" => $data['type'] ?? 0, + "count" => $data['count'] ?? 0, + "type_name" => $data['type_name'] ?? '', + "start_time" => $data['start_time'] ?? '', + "end_time" => $data['end_time'] ?? '', + "deduction_money" => $data['deduction_money'] ?? '', + "image_url" => $data['image_url'] ?? '', + "intro" => $data['intro'] ?? '', + "content" => $data['content'] ?? '', + "white_list" => $data['white_list'] ?? '', + "status" => CouponMain::status_on, + "on_shelf" => CouponMain::on_shelf_off,//默认下架 后台审核上架 + "on_screen" => CouponMain::on_screen_yes, + "is_distribution" => CouponMain::COMMON_OFF,//默认关闭分销 + + //下面是分配比例 + "commission_agency" => $distributionProportion['agency'], + "commission_admin" => $distributionProportion['admin'], + "commission_consumer" => $distributionProportion['consumer'], + "commission_dis_admin" => $distributionProportionUser['admin'], + "commission_dis_distribution" => $distributionProportionUser['distribution'], + "commission_dis_distributed" => $distributionProportionUser['distributed'], ]; //$usingRule = input("using_rule/a"); @@ -743,10 +753,10 @@ class Coupon extends Base $couponMain['deduction_money'] = floor($couponMain['deduction_money'] * 100) / 100; $totalMoney = $couponMain['deduction_money'] * $couponMain['count']; - //检测消费者部分是否最少1元 + //检测消费者部分是否最少0.3元 $consumerMoney = ($couponMain['commission_consumer']/100) * $couponMain['deduction_money']; - if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_consumer_money) { - return $this->json(4002, "消费者红包最低" . CouponMain::min_consumer_money . "元"); + if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_redpack_money) { + return $this->json(4002, "扣除金额最低" . (CouponMain::min_redpack_money * (100 / ($data['commission_consumer']))) . "元"); } //未领取的优惠券 diff --git a/app/controller/manager/Config.php b/app/controller/manager/Config.php index cb0371d..173c00c 100644 --- a/app/controller/manager/Config.php +++ b/app/controller/manager/Config.php @@ -189,9 +189,9 @@ class Config extends Base $data = input("post."); unset($data['_token']); $validate = $this->validateByApi($data, [ - 'agency' => 'require|number', - 'admin' => 'require|number', - 'consumer' => 'require|number', + 'agency|渠道商占比' => 'require|number', + 'admin|平台占比' => 'require|number', + 'consumer|消费者占比' => 'require|number', ]); if ($validate !== true) { @@ -210,4 +210,31 @@ class Config extends Base return $this->view(); } } + /* 分配比例-分销*/ + public function distributionProportionUser(){ + if ($this->request->isPost()) { + $data = input("post."); + unset($data['_token']); + $validate = $this->validateByApi($data, [ + 'admin|平台占比' => 'require|number', + 'distribution|(领券)分销者占比' => 'require|number', + 'distributed|(核销)被分销者占比' => 'require|number', + ]); + + if ($validate !== true) { + return $validate; + } + $total = $data['admin'] + $data['distribution'] + $data['distributed']; + if ($total != 100) { + return $this->json(5002,"分配比例总和不等于100"); + } + $php = var_export($data, true); + file_put_contents($this->extraPath . 'distribution_proportion_user.php', 'json(); + } else { + CConfig::load('extra/distribution_proportion_user', 'distributionProportionUser'); + $this->data['item'] = config('distributionProportionUser'); + return $this->view(); + } + } } \ No newline at end of file diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 1487aa5..e75c563 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -35,7 +35,9 @@ class Coupon extends Base { parent::initialize(); // TODO: Change the autogenerated stub CConfig::load('extra/distribution_proportion', 'distributionProportion'); + CConfig::load('extra/distribution_proportion_user', 'distributionProportionUser'); $this->data['distributionProportion'] = config('distributionProportion'); + $this->data['distributionProportionUser'] = config('distributionProportionUser'); } /** @@ -222,22 +224,61 @@ class Coupon extends Base - $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"); + $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"); + $data['commission_dis_admin'] = input("item.commission_dis_admin/d", 0,"abs"); + $data['commission_dis_distribution'] = input("item.commission_dis_distribution/d", 0,"abs"); + $data['commission_dis_distributed'] = input("item.commission_dis_distributed/d", 0,"abs"); - $totalC = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; - if ($totalC != 100) { + $totalCommission = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; + if ($totalCommission != 100) { return $this->json(5002, "分配比例总和不等于100"); } + $totalCommissionDis = $data['commission_dis_admin'] + $data['commission_dis_distribution'] + $data['commission_dis_distributed']; + if ($totalCommissionDis != 100) { + return $this->json(5002, "(开启分销)分配比例总和不等于100"); + } //保留两位小数 $data['deduction_money'] = floor($data['deduction_money'] * 100) / 100; - //检测消费者部分是否最少1元 + //检测消费者部分是否最少0.3元 $consumerMoney = ($data['commission_consumer']/100) * $data['deduction_money']; - if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_consumer_money) { - return $this->json(4002, "消费者红包最低" . CouponMain::min_consumer_money . "元"); + if ($consumerMoney != 0 && $consumerMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + "【分销者】红包不足" + .CouponMain::min_redpack_money + .";当前比例扣除金额最低" + . (CouponMain::min_redpack_money * (100 / ($data['commission_consumer']))) + . "元"); + } + + //如果开启分销 添加操作 处理扣除金额 + if($data["is_distribution"] == CouponMain::COMMON_ON ){ + if($data['commission_dis_distribution']>$data['commission_dis_distributed']){ + //检测【分销者】部分是否最少0.3元 + $distributionMoney = ($data['commission_dis_distribution']/100) * $data['deduction_money']; + if ($distributionMoney != 0 && $distributionMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + "开启分销后:【分销者】红包不足" + .CouponMain::min_redpack_money + .",扣除金额最低" . + (CouponMain::min_redpack_money * (100 / ($data['commission_dis_distribution']))) + . "元"); + } + }else{ + //检测【被分销者】部分是否最少0.3元 + $distributedMoney = ($data['commission_dis_distributed']/100) * $data['deduction_money']; + if ($distributedMoney != 0 && $distributedMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + "开启分销后:【被分销者】红包不足" + .CouponMain::min_redpack_money + .",扣除金额最低" . + (CouponMain::min_redpack_money * (100 / ($data['commission_dis_distribution']))) + . "元"); + } + } } @@ -330,13 +371,50 @@ class Coupon extends Base $data['lat'] = $business['lat']; - $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); - $totalC = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; - if ($totalC != 100) { + $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"); + $data['commission_dis_admin'] = input("item.commission_dis_admin/d", 0,"abs"); + $data['commission_dis_distribution'] = input("item.commission_dis_distribution/d", 0,"abs"); + $data['commission_dis_distributed'] = input("item.commission_dis_distributed/d", 0,"abs"); + + $totalCommission = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; + if ($totalCommission != 100) { return $this->json(5002, "分配比例总和不等于100"); } + $totalCommissionDis = $data['commission_dis_admin'] + $data['commission_dis_distribution'] + $data['commission_dis_distributed']; + if ($totalCommissionDis != 100) { + return $this->json(5002, "(开启分销)分配比例总和不等于100"); + } + + //如果开启分销 添加操作 处理扣除金额 + if($data["is_distribution"] == CouponMain::COMMON_ON ){ + + //检测【分销者】部分是否最少0.3元 + $distributionMoney = ($data['commission_dis_distribution']/100) * $data['deduction_money']; + if ($distributionMoney != 0 && $distributionMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + "开启分销后:【分销者】红包不足" + .CouponMain::min_redpack_money + .",(领券)分销者占比最低" . + ( round((CouponMain::min_redpack_money / ($data['deduction_money']) )*100,2)) + . "%" + ); + } + + //检测【被分销者】部分是否最少0.3元 + $distributedMoney = ($data['commission_dis_distributed']/100) * $data['deduction_money']; + if ($distributedMoney != 0 && $distributedMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + "开启分销后:【被分销者】红包不足" + .CouponMain::min_redpack_money + .",(核销)被分销者占比最低" . + ( round((CouponMain::min_redpack_money / ($data['deduction_money']) )*100,2)) + . "%"); + } + + } + $data['update_time'] = date("Y-m-d H:i:s"); @@ -408,5 +486,58 @@ class Coupon extends Base return download(public_path() . $path,$couponMain['name']); } + /** + * 设置分销开关 + * + * */ + public function setDistribution() + { + $ids = input("ids/a", []); + $isDistribution = input("is_distribution/d"); + //如果是开启分销操作 + if ($isDistribution == CouponMain::COMMON_ON) { + $couponMains = CouponMain::findList([["id", "in", $ids]], [],1,0); + foreach ($couponMains["list"] as $key=> $item) { + //如果开启分销 添加操作 处理扣除金额 + if ($item["is_distribution"] == CouponMain::COMMON_OFF) { + + //检测【分销者】部分是否最少0.3元 + $distributionMoney = ($item['commission_dis_distribution'] / 100) * $item['deduction_money']; + if ($distributionMoney != 0 && $distributionMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + $item['name'] + ."开启分销后:【分销者】红包不足" + . CouponMain::min_redpack_money + . ",(领券)分销者占比最低" . + (round((CouponMain::min_redpack_money / ($item['deduction_money'])) * 100, 2)) + . "%" + ); + } + + //检测【被分销者】部分是否最少0.3元 + $distributedMoney = ($item['commission_dis_distributed'] / 100) * $item['deduction_money']; + if ($distributedMoney != 0 && $distributedMoney < CouponMain::min_redpack_money) { + return $this->json(4002, + $item['name'] + . "开启分销后:【被分销者】红包不足" + . CouponMain::min_redpack_money + . ",(核销)被分销者占比最低" . + (round((CouponMain::min_redpack_money / ($item['deduction_money'])) * 100, 2)) + . "%"); + } + + } + } + } + Db::startTrans(); + try { + CouponMain::whereIn("id",$ids)->update(["is_distribution"=>$isDistribution]); + Db::commit(); + return $this->json(); + } catch (Exception $e) { + Db::rollback(); + return $this->json(5001, "设置失败".$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index a9c02f0..26ba621 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -23,7 +23,7 @@ class CouponMain extends Base const on_screen_yes = 1;//展示到商圈大屏 const on_screen_no = 0;//不展示到商圈大屏 - const min_consumer_money = 0.3;// + const min_redpack_money = 0.3;// const receive_status_over = 2;//领取状态 已领完 const receive_status_received = 1;//领取状态 已领完 diff --git a/public/static/manager/js/coupon/index.js b/public/static/manager/js/coupon/index.js index 5908470..f778cc0 100644 --- a/public/static/manager/js/coupon/index.js +++ b/public/static/manager/js/coupon/index.js @@ -42,7 +42,7 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect','laydate'] }, page: true, cols: [[ - // {type: 'checkbox'}, + {type: 'checkbox'}, {field: 'id' , width: 80, title: 'ID'}, {field: 'name', title: '名称'}, @@ -109,9 +109,75 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect','laydate'] openLayer(url, title, width, height); return false; } + + if (layEvent === 'distribution') { + + let ids = [$(this).data('value')]; + setDistribution(url, ids); + return false; + } + }); + //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 + table.on('toolbar(table-container)', function (obj) { + let layEvent = obj.event; + let insTb = Tools.getInsTb(); + let url = $($(this).context).data('href') + let title = $($(this).context).data('title') + let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; + let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; + + // debugger; + switch (layEvent) { + + // toolbar 刷新 + case 'refresh': + refreshTab(insTb); + return false; + + case 'distribution': + let checkStatus = table.checkStatus('table-container'); + if (checkStatus.data.length <= 0) { + layer.msg('请先选择数据'); + return false; + } + let selected = checkStatus.data; + let ids = []; + + $.each(selected, function (index, val) { + ids.push(val.id); + }); + setDistribution(url, ids); + return false; + + // 其他 默认为打开弹出层 + default: + if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { + openLayer(url, title, width, height); + return false; + } + } + }); - + //删除 + function setDistribution(url, ids) { + let index = layer.confirm('确认操作吗?', { + btn: ['确认','取消'], //按钮 + title: '操作提示', + }, function() { + $.post(url, { + ids: ids, + }, function (res) { + layer.msg(res.msg) + if (res.code === 0) { + insTb.reload(); + } + }) + }, function(){ + layer.close(index) + return false; + }); + } } /*** index end ***/ diff --git a/view/manager/config/distribution_proportion_user.html b/view/manager/config/distribution_proportion_user.html new file mode 100644 index 0000000..c68fb05 --- /dev/null +++ b/view/manager/config/distribution_proportion_user.html @@ -0,0 +1,46 @@ +{layout name="manager/layout" /} +
+
+
+
+ 请填写完整整数 总和为100 +
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ + + +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/view/manager/coupon/add.html b/view/manager/coupon/add.html index b59f91f..7d405d3 100644 --- a/view/manager/coupon/add.html +++ b/view/manager/coupon/add.html @@ -183,6 +183,14 @@ +
+ +
+ + +
+
+
@@ -243,6 +251,40 @@
+ +
+ (开启分销状态)请填写完整整数 总和为100 +
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
diff --git a/view/manager/coupon/edit.html b/view/manager/coupon/edit.html index d95ed3d..84f750d 100644 --- a/view/manager/coupon/edit.html +++ b/view/manager/coupon/edit.html @@ -182,6 +182,15 @@
+
+ +
+ + + +
+
+
@@ -251,6 +260,41 @@
+
+ (开启分销状态)请填写完整整数 总和为100 +
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+ + +
diff --git a/view/manager/coupon/index.html b/view/manager/coupon/index.html index 3ddd0b1..3799752 100644 --- a/view/manager/coupon/index.html +++ b/view/manager/coupon/index.html @@ -93,6 +93,18 @@ {{# }else{ }} 下架 {{# } }} + + {{# if(d.is_distribution == 1){ }} + 关闭分销 + {{# }else{ }} + 开启分销 + {{# } }} 下载二维码 编辑 @@ -101,6 +113,12 @@