全部
常见问题
产品动态
精选推荐

分享一个线下优惠券发放

管理 管理 编辑 删除
场景:跟其他平台进行流量合作 生成优惠券券码给对方平台用户,对方平台用户凭券码来兑换取得抵扣的优惠券

520152025203

app\models\store 增加StoreCouponCode.php

app\admin\controller\ump 修改 StoreCoupon.php

    public function issue($id)

{

if (!CouponModel::be(['id' => $id, 'status' => 1, 'is_del' => 0]))

return $this->failed('发布的优惠劵已失效或不存在!');

$f = [];

$f[] = Form::input('id', '优惠劵ID', $id)->disabled(1);

$f[] = Form::dateTimeRange('range_date', '领取时间')->placeholder('不填为永久有效');

$f[] = Form::radio('is_permanent', '是否不限量', 0)->options([['label' => '限量', 'value' => 0], ['label' => '不限量', 'value' => 1]]);

$f[] = Form::number('count', '发布数量', 0)->min(0)->placeholder('不填或填0,为不限量');

$f[] = Form::radio('is_full_give', '消费满赠', 0)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);

$f[] = Form::number('full_reduction', '满赠金额')->min(0)->placeholder('赠送优惠券的最低消费金额');

$f[] = Form::radio('is_give_subscribe', '首次关注赠送', 0)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);

$f[] = Form::radio('send_type', '发放方式', 0)->options([['label' => '线上', 'value' => 0], ['label' => '线下', 'value' => 1]]);

$f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);

$form = Form::make_post_form('添加优惠券', $f, Url::buildUrl('update_issue', array('id' => $id)));

$this->assign(compact('form'));

return $this->fetch('public/form-builder');

}

public function update_issue($id)

{

list($_id, $rangeTime, $count, $status, $is_permanent, $full_reduction, $is_give_subscribe, $send_type,$is_full_give) = Util::postMore([

'id',

['range_date', ['', '']],

['count', 0],

['status', 0],

['is_permanent', 0],

['full_reduction', 0],

['is_give_subscribe', 0],

['send_type', 0],

['is_full_give', 0]

], null, true);

if ($_id != $id) return Json::fail('操作失败,信息不对称');

if (!$count) $count = 0;

if (!CouponModel::be(['id' => $id, 'status' => 1, 'is_del' => 0])) return Json::fail('发布的优惠劵已失效或不存在!');

if (count($rangeTime) != 2) return Json::fail('请选择正确的时间区间');

list($startTime, $endTime) = $rangeTime;

// echo $startTime;echo $endTime;var_dump($rangeTime);die;

if (!$startTime) $startTime = 0;

if (!$endTime) $endTime = 0;

if (!$startTime && $endTime) return Json::fail('请选择正确的开始时间');

if ($startTime && !$endTime) return Json::fail('请选择正确的结束时间');

if (StoreCouponIssue::setIssue($id, $count, strtotime($startTime), strtotime($endTime), $count, $status, $is_permanent,$full_reduction, $is_give_subscribe,$send_type, $is_full_give))

return Json::successful('发布优惠劵成功!');

else

return Json::fail('发布优惠劵失败!');

}

app\admin\controller\ump 修改StoreCouponIssue.php

namespace app\admin\controller\ump;

use app\admin\controller\AuthController;

use think\facade\Route as Url;

use crmeb\traits\CurdControllerTrait;

use crmeb\services\{JsonService, FormBuilder as Form, UtilService as Util};

use app\admin\model\ump\{StoreCouponIssue as CouponIssueModel, StoreCouponIssueUser};

use app\models\store\StoreCouponCode as CouponCodeModel;
新增

 public function issue_code_list($id = '') 

{

if (!$id) return JsonService::fail('参数有误!');

$this->assign(CouponCodeModel::systemCouponCodePage($id));

return $this->fetch();

}

public function export_text($id = '') //导出券码

{

if (!$id) return JsonService::fail('参数有误!');

$list = CouponCodeModel::where(['cid'=>$id,'status'=>0])->field('code')->select()->toArray();

foreach ($list as $val) {

$val = join(",",$val);

$temp_array[] = $val;

}

$list = implode("\r", $temp_array);

return JsonService::successful('导出成功!',$list);

}

public function issue_make_code($id = '') //券码生成

{

if (!$id) return JsonService::fail('参数有误!');

$issueInfo = CouponIssueModel::get($id);

if (-1 == $issueInfo['status'] || 1 == $issueInfo['is_del'] || 0 == $issueInfo['send_type']) return $this->failed('状态错误,无法操作');

$f = [];

$f[] = Form::input('cid', '优惠劵编号', $issueInfo['id'])->disabled(1);

if ( 0 == $issueInfo['is_permanent']) {

$f[] = Form::number('count', '生成数量(剩余'.$issueInfo['make_count'].')', 1)->min(1)->max($issueInfo['make_count']);

} else {

$f[] = Form::number('count', '生成数量', 1)->min(1)->max(1000);

}

$form = Form::make_post_form('生成优惠券', $f, Url::buildUrl('make_code_handle'));

$this->assign(compact('form'));

return $this->fetch('public/form-builder');

}

public function make_code_handle()

{

$data = Util::postMore([

['cid', 0],

['count', 0]

]);

if (!$data['cid']) return JsonService::fail('操作错误');

if (!$data['count']) return JsonService::fail('数量不能小于0');

$data['send_time'] = time();

$issueInfo = CouponIssueModel::get($data['cid']);

if (0 == $issueInfo['make_count']) {

return JsonService::fail('可生成数量错误!'.$issueInfo['make_count']);

}

$datas = array();

for($i = 0; $i < $data['count']; $i++){

$datas[$i]['cid'] = $data['cid'];

$datas[$i]['send_time'] = time();

do{

$code = get_rand_str(8,0,1);//获取随机8位字符串

$check_exist = CouponCodeModel::where(['code' => $code])->find();

}while($check_exist);

$datas[$i]['code'] = $code;

}

CouponCodeModel::insertAll($datas);

CouponIssueModel::where(['id' => $data['cid']])->dec('make_count',$data['count'])->update();

return JsonService::successful('生成成功!');

}
app\admin\view\ump\store_coupon_issue 修改 index.php

app\admin\view\ump\store_coupon_issue 增加 issue_code_list.php

app\ 修改common.php

小程序 h5也需要修改

详情看附件,给需要的人。lol

分享一个线下优惠券发放 分享一个线下优惠券发放 分享一个线下优惠券发放 分享一个线下优惠券发放 分享一个线下优惠券发放

CRMEB官方 最后编辑于2022-11-06 19:46:16

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
2067
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

CRMEB官方 作者
暂无简介

回答

0

发布

0

经验

0

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服