master
wangxinglong 2022-03-30 15:52:49 +08:00
parent e16cbe2f6a
commit 52c7b2e2b5
6 changed files with 192 additions and 20 deletions

View File

@ -493,10 +493,29 @@ class Coupon extends Base
return $this->json(4001, "商家已禁用");
}
if($business->balance < $coupon->couponMain->deduction_money){
return $this->json(4001, "商家余额不足");
// 指定时间段内发布的优惠券个数
$TimeListModeReleaseCount = BusinessRepository::getInstance()
->getTimeListModeReleaseCount($business["code"],$business["time_limit_start"],$business["time_limit_end"]);
if (
$business["model"] == BusinessModel::model_ordinary
||
(
$business["model"] == BusinessModel::model_time_limit
&&
(
strtotime($business["time_limit_end"]) < $time
||
$TimeListModeReleaseCount >= $business["time_limit_release_count"]
)
)
) {
if ($business['balance'] < $coupon->couponMain->deduction_money) {
return $this->json(4001, "商家余额不足");
}
}
$deductionMoney = $coupon->couponMain->deduction_money;
$returnConsumerMoney = 0;//需要返回提示的金额
@ -629,8 +648,24 @@ class Coupon extends Base
//4. 商家扣钱 普通商家才扣钱 否则不扣钱
if($business->model == BusinessModel::model_ordinary){
$business->save(["balance"=>Db::raw("balance - " . $deductionMoney)]);
if(
$business["model"] == BusinessModel::model_ordinary
||
(
$business["model"] == BusinessModel::model_time_limit
&&
(
strtotime($business["time_limit_end"]) < $time
||
$TimeListModeReleaseCount >= $business["time_limit_release_count"]
)
)
){
$business->save([
"balance" => Db::raw("balance - " . $deductionMoney,),
"model" => BusinessModel::model_ordinary
]);
}
$payment = WechatPay::getInstance();
@ -845,6 +880,7 @@ class Coupon extends Base
return $this->json(4001, "商家已禁用");
}
$data = input();
$time = time();
Config::load("extra/distribution_proportion","distribution_proportion");
Config::load("extra/distribution_proportion_user","distribution_proportion_user");
@ -866,8 +902,6 @@ class Coupon extends Base
}
}
//验证通过 不管是商家还是工作人员 都可以发布优惠券
$couponMain = [
"name" => $data['name'] ?? '',
@ -984,7 +1018,23 @@ class Coupon extends Base
//未领取的优惠券
$NotClaimedMoney = CouponRepository::getInstance()->getBusinessNotClaimedCoupon($account->business["code"]);
if($account->business["model"] == BusinessModel::model_ordinary) {
// 指定时间段内发布的优惠券个数
$TimeListModeReleaseCount = BusinessRepository::getInstance()
->getTimeListModeReleaseCount($account->business["code"],$account->business["time_limit_start"],$account->business["time_limit_end"]);
if(
$account->business["model"] == BusinessModel::model_ordinary
||
(
$account->business["model"] == BusinessModel::model_time_limit
&&
(
(strtotime($account->business["time_limit_end"]) < $time)
||
($TimeListModeReleaseCount >= $account->business["time_limit_release_count"])
)
)
) {
if ($account->business["balance"] < ($totalMoney + $NotClaimedMoney)) {
return $this->json(4001, '商家余额不足');
}
@ -994,6 +1044,18 @@ class Coupon extends Base
try {
//CouponRepository::getInstance()->releaseCouponMain($couponMain, $totalMoney, $usingRule);
CouponRepository::getInstance()->releaseCouponMain($couponMain);
if($account->business["model"] == BusinessModel::model_time_limit){
//如果到了时间 或者发布数量到达规定 更改商家模式
if( strtotime($account->business["time_limit_end"] ) < $time
||
(($TimeListModeReleaseCount + 1) >= $account->business["time_limit_release_count"])
){
$account->business->save(["model"=>BusinessModel::model_ordinary]);
}
}
Db::commit();
return $this->json();
} catch (RepositoryException $e) {

View File

@ -230,8 +230,13 @@ class Business extends Base
// 'intro|介绍' => 'require',
// 'business_circle_id|商圈' => 'require',
'background|背景图' => 'require',
'model|商家模式' => 'require',
//'score|评分' => 'require|in:1,2,3,4,5',
'reason|驳回原因' => 'max:100',
'time_limit_start|时限商家模式【开始时间】' => 'requireIf:model,'.BusinessModel::model_time_limit.'|date',
'time_limit_end|时限商家模式【结束时间】' => 'requireIf:model,'.BusinessModel::model_time_limit.'|date|after:'.date("Y-m-d",strtotime("+1 day")),
'time_limit_release_count|时限商家模式可发布优惠券个数' => 'requireIf:model,'.BusinessModel::model_time_limit.'|>:0',
]);
if ($validate !== true) {
@ -253,10 +258,12 @@ class Business extends Base
if (empty($business)) {
return $this->error("商家不存在");
}
$this->data["item"] = $business;
$this->data["type"] = CategoryModel::getByGroup();
$this->data["businessCircle"] = BusinessCircleModel::getList();
$this->data["model"] = BusinessModel::allModel();
$this->data["item"] = $business;
$this->data["type"] = CategoryModel::getByGroup();
$this->data["businessCircle"] = BusinessCircleModel::getList();
$this->data["model"] = BusinessModel::allModel();
$this->data["model_ordinary"] = BusinessModel::model_ordinary;
$this->data["model_time_limit"] = BusinessModel::model_time_limit;
return $this->view();
}

View File

@ -178,8 +178,8 @@ class Coupon extends Base
//$usingRule = input("using_rule/a", []);
$business = BusinessRepository::getInstance()->getBusinessAccount($data["business_code"], true);
$business = BusinessRepository::getInstance()->getBusinessAccount($data["business_code"], true);
$time = time();
if (empty($business)) {
return $this->json(4001, '商家不存在');
}
@ -311,8 +311,23 @@ class Coupon extends Base
//未领取的优惠券
$NotClaimedMoney = CouponRepository::getInstance()->getBusinessNotClaimedCoupon($business["code"]);
// 指定时间段内发布的优惠券个数
$TimeListModeReleaseCount = BusinessRepository::getInstance()
->getTimeListModeReleaseCount($business["code"],$business["time_limit_start"],$business["time_limit_end"]);
if($business["model"] == BusinessModel::model_ordinary){
if(
$business["model"] == BusinessModel::model_ordinary
||
(
$business["model"] == BusinessModel::model_time_limit
&&
(
strtotime($business["time_limit_end"]) < $time
||
$TimeListModeReleaseCount >= $business["time_limit_release_count"]
)
)
){
if ($business["balance"] < ($totalMoney + $NotClaimedMoney)) {
return $this->json(4001, '商家余额不足');
}
@ -328,6 +343,17 @@ class Coupon extends Base
try {
//CouponRepository::getInstance()->releaseCouponMain($data, $totalMoney, $usingRule);
CouponRepository::getInstance()->releaseCouponMain($data);
if($business["model"] == BusinessModel::model_time_limit){
//如果到了时间 或者发布数量到达规定 更改商家模式
if( strtotime($business["time_limit_end"] ) < $time
||
(($TimeListModeReleaseCount+1) >= $business["time_limit_release_count"])
){
$business->save(["model"=>BusinessModel::model_ordinary]);
}
}
Db::commit();
return $this->json();
} catch (RepositoryException $e) {

View File

@ -13,8 +13,7 @@ class Business extends Base
const state_consumer = 4;//未认证
const model_ordinary = 0;//普通商家
const model_annual_fee = 1;//年费商家
const model_zero = 2;//0元商家
const model_time_limit = 1;//时限商家
/**
* @remarks 代理商、平台商、平台代理商、渠道商等词组均描述的是代理商,因此文案统一为【代理商】
*/
@ -23,8 +22,7 @@ class Business extends Base
{
return [
self::model_ordinary=>"普通商家",
self::model_annual_fee=>"年费商家",
self::model_zero=>"0元商家",
self::model_time_limit=>"时限商家",
];
}
public function category()

View File

@ -228,4 +228,18 @@ class BusinessRepository extends Repository
->where("a.agency_code", $agencyCode)
->sum("b.count");
}
/**
* 统计某个时间段内 商家发布的优惠券个数
* @param $businessId
* @param $startTime
* @param $endTime
*/
public function getTimeListModeReleaseCount($businessCode,$startTime,$endTime)
{
return CouponMain::where("business_code",$businessCode)
->whereBetweenTime("create_time",$startTime,$endTime)
->order("id")
->count();
}
}

View File

@ -219,10 +219,14 @@
<!-- </div>-->
<!-- </div>-->
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="compatibility">时限商家 当商家在有效期内发布优惠券次数达到设置次数,或者超出有效期,商家类型自动变成普通商家</a></legend>
</fieldset>
<div class="layui-form-item">
<label class="layui-form-label required">商家模式</label>
<div class="layui-input-block">
<select name="model">
<select name="model" lay-filter="model">
{foreach $model as $key=> $value}
<option value="{$key}" {if $item['model'] == $key } selected {/if}>{$value}</option>
{/foreach}
@ -230,6 +234,38 @@
</div>
</div>
<div class="layui-form-item time_limit_model {if $item['model'] == $model_ordinary } layui-hide {/if}">
<label class="layui-form-label required">时限-开始时间</label>
<div class="layui-input-block">
<input type="text" name="time_limit_start" id="time_limit_start"
{if strtotime($item.time_limit_start)>0}
value="{$item.time_limit_end??''}"
{/if}
class="layui-input">
</div>
</div>
<div class="layui-form-item time_limit_model {if $item['model'] == $model_ordinary } layui-hide {/if}">
<label class="layui-form-label required">时限-结束时间</label>
<div class="layui-input-block">
<input type="text" name="time_limit_end" id="time_limit_end"
{if strtotime($item.time_limit_end)>0}
value="{$item.time_limit_end??''}"
{/if}
class="layui-input">
</div>
</div>
<div class="layui-form-item time_limit_model {if $item['model'] == $model_ordinary } layui-hide {/if}">
<label class="layui-form-label required">时限-发布个数</label>
<div class="layui-input-block">
<input type="number" name="time_limit_release_count"
value="{$item.time_limit_release_count??0}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/business/business-detail?business_code={$item.code}" lay-submit lay-filter="saveBtn">确认保存</button>
@ -303,10 +339,38 @@
</script>
<script>
layui.use(['layer','form','jquery','location'],function(){
layui.use(['layer','form','jquery','location',"laydate"],function(){
let $ = layui.jquery;
let form = layui.form;
let location = layui.location;
let laydate = layui.laydate;
//日期时间选择器
laydate.render({
elem: '#time_limit_start'
,type: 'datetime'
});
//日期时间选择器
laydate.render({
elem: '#time_limit_end'
,type: 'datetime'
});
form.on('select(model)', function(data){
//console.log(data.elem); //得到select原始DOM对象
//console.log(data.value); //得到被选中的值
//console.log(data.othis); //得到美化后的DOM对象
if(data.value == {$model_time_limit}){
$(".time_limit_model").removeClass("layui-hide").show()
}else{
$(".time_limit_model").addClass("layui-hide").hide()
}
});
let lng = $('#longitude').val();
let lat = $('#latitude').val();
@ -341,5 +405,6 @@
}
});
});
</script>