初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\app\coupon;
|
||||
use think\Db;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\app\coupon\Coupon as CouponModel;
|
||||
use app\common\traits\app\CouponSend;
|
||||
use app\admin\model\app\coupon\CouponGoods;
|
||||
|
||||
/**
|
||||
* 优惠券
|
||||
*/
|
||||
class Coupon extends Backend
|
||||
{
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new CouponModel;
|
||||
$this->couponGoodsModel = new CouponGoods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||||
|
||||
$status = input('status');
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$extendWhere = [
|
||||
'deletetime'=>NULL
|
||||
];
|
||||
|
||||
switch ($status){
|
||||
case 2:
|
||||
case 3:
|
||||
$extendWhere['status'] = $status;
|
||||
break;
|
||||
case 1:
|
||||
$extendWhere['status'] = 1;
|
||||
$extendWhere['use_start_time'] = ['<=',time()];
|
||||
$extendWhere['use_end_time'] = ['>=',time()];
|
||||
break;
|
||||
case 4:
|
||||
$extendWhere['status'] = 1;
|
||||
$extendWhere['use_start_time'] = ['>',time()];
|
||||
break;
|
||||
case 5:
|
||||
$extendWhere['status'] = 1;
|
||||
$extendWhere['use_end_time'] = ['<',time()];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where($extendWhere)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as $row) {
|
||||
// $row->ticket_count = $this->ticketModel->getTicketCount($row->id);
|
||||
// $row->apply_total_data = $this->userTicketModel->getApplyTotalData($row->id);
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items(),'attr'=>[
|
||||
'typeList'=>$this->model->getTypeList(),
|
||||
'statusList'=>$this->model->getStatusList(),
|
||||
]);
|
||||
|
||||
return $this->success("获取成功",$result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加优惠券
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->only([
|
||||
'name','type','goods','max_amount_status','enough_status','discount','use_time','use_scope','amount','max_amount','enough','stock','limit_num','limit_status','use_time_type','use_start_time','use_end_time','start_days','days','description','recommend_goods_status','stock_status','share_status','public_status','double_discount_status'
|
||||
]);
|
||||
|
||||
$params['uniacid'] = UNIACID;
|
||||
|
||||
|
||||
$goods = $params['goods'];
|
||||
unset($params['goods']);
|
||||
|
||||
|
||||
$params['use_start_time'] = strtotime($params['use_time'][0]) ?? 0;
|
||||
$params['use_end_time'] = strtotime($params['use_time'][1]) ?? 0;
|
||||
unset($params['use_time']);
|
||||
$params['createtime'] = $params['updatetime'] = time();
|
||||
|
||||
$this->validateForm($params);
|
||||
|
||||
$couponId = $this->model->insertGetId($params);
|
||||
$this->couponGoodsModel->setGoods($couponId,$goods);
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->success("保存成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数验证
|
||||
* @param $params
|
||||
* @return void
|
||||
*/
|
||||
public function validateForm($params){
|
||||
if($params['use_time_type'] == 'range'){
|
||||
if($params['use_start_time'] == 0 || $params['use_end_time'] == 0){
|
||||
return $this->error("请完善使用时间");
|
||||
}
|
||||
}else{
|
||||
if($params['days']<=0){
|
||||
return $this->error("有效期请设置大于 0 天");
|
||||
}
|
||||
}
|
||||
|
||||
if($params['type'] == 'discount'){
|
||||
if($params['discount'] <= 0 || $params['discount'] > 9.99 ){
|
||||
return $this->error("请填写有效的消费折扣");
|
||||
}
|
||||
}
|
||||
if($params['type'] == 'reduce'){
|
||||
if($params['amount'] <= 0){
|
||||
return $this->error("请填写有效的满减金额");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 优惠券详情
|
||||
*
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$coupon = $this->model->where('id', $id)->find();
|
||||
if (!$coupon) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$coupon->use_time = [$coupon->use_start_time,$coupon->use_end_time];
|
||||
|
||||
$coupon->max_amount = floatval($coupon->max_amount);
|
||||
$coupon->discount = floatval($coupon->discount);
|
||||
$coupon->amount = floatval($coupon->amount);
|
||||
$coupon->enough = floatval($coupon->enough);
|
||||
$coupon->goods = $coupon->goods_value;
|
||||
|
||||
return $this->success("获取成功",$coupon);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改优惠券
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$params = $this->request->only(['name','goods','max_amount_status','enough_status','discount','type','use_time','use_scope','amount','max_amount','enough','stock','limit_num','limit_status','use_time_type','use_start_time','use_end_time','start_days','days','description','recommend_goods_status','stock_status','share_status','public_status','double_discount_status']);
|
||||
// $this->svalidateForm($params);
|
||||
$goods = $params['goods'];
|
||||
unset($params['goods']);
|
||||
|
||||
$params['use_start_time'] = strtotime($params['use_time'][0]) ?? 0;
|
||||
$params['use_end_time'] = strtotime($params['use_time'][1]) ?? 0;
|
||||
unset($params['use_time']);
|
||||
|
||||
$params['updatetime'] = time();
|
||||
$coupon = $this->model->where('id', $id)->find();
|
||||
if (!$coupon) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$this->validateForm($params);
|
||||
|
||||
$this->couponGoodsModel->setGoods($id,$goods);
|
||||
|
||||
$coupon->save($params);
|
||||
return $this->success("保存成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
* @param string $id 要删除的优惠券
|
||||
* @return void
|
||||
*/
|
||||
public function delete($ids)
|
||||
{
|
||||
if (empty($ids)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'id'));
|
||||
}
|
||||
if(is_string($ids)){
|
||||
$ids = explode(',', $ids);;
|
||||
}
|
||||
$list = $this->model->where('id', 'in', $ids)->select();
|
||||
$result = Db::transaction(function () use ($list) {
|
||||
$count = 0;
|
||||
foreach ($list as $item) {
|
||||
$item->deletetime = time();
|
||||
$count += $item->save();
|
||||
}
|
||||
return $count;
|
||||
});
|
||||
|
||||
if ($result) {
|
||||
$this->success('删除成功', null, $result);
|
||||
} else {
|
||||
$this->error(__('No rows were deleted'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$type = $this->request->param('type', 'page');
|
||||
|
||||
$coupons = $this->model->sheepFilter();
|
||||
|
||||
if ($type == 'select') {
|
||||
// 普通结果
|
||||
$coupons = $coupons->select();
|
||||
} elseif ($type == 'find') {
|
||||
$coupons = $coupons->find();
|
||||
} else {
|
||||
// 分页结果
|
||||
$coupons = $coupons->paginate($this->request->param('list_rows', 10));
|
||||
}
|
||||
|
||||
$this->success('获取成功', null, $coupons);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 切换状态
|
||||
* @param $ids
|
||||
* @param $status
|
||||
* @return void
|
||||
*/
|
||||
public function status($ids=null,$status=1){
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ?: $this->request->post("ids");
|
||||
if (empty($ids)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
$status = $status ?: $this->request->post("status");
|
||||
|
||||
$pk = $this->model->getPk();
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||||
}
|
||||
$list = $this->model->where($pk, 'in', $ids)->select();
|
||||
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $item) {
|
||||
$row = [
|
||||
'status'=>$status
|
||||
];
|
||||
|
||||
$this->model->where([
|
||||
'id'=>$item['id']
|
||||
])->update($row);
|
||||
$count++;
|
||||
}
|
||||
Db::commit();
|
||||
} catch (PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($count) {
|
||||
$this->success("操作成功");
|
||||
}
|
||||
$this->error(__('未操作任何数据'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\app\coupon;
|
||||
use think\Db;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\app\coupon\Coupon as CouponModel;
|
||||
use app\admin\model\app\coupon\CouponUser as CouponUserModel;
|
||||
use app\common\traits\app\CouponSend;
|
||||
use app\admin\model\app\coupon\CouponGoods;
|
||||
use PHPExcel_IOFactory;
|
||||
/**
|
||||
* 用券商品
|
||||
*/
|
||||
class Goods extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new CouponUserModel;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
// 设置不统计的订单状态
|
||||
$excluded_statuses = [\app\common\constant\order\Status::STATUS_CLOSE, \app\common\constant\order\Status::STATUS_UNPAID, \app\common\constant\order\Status::STATUS_CANCEL, \app\common\constant\order\Status::STATUS_REFUND];
|
||||
|
||||
$list = \app\admin\model\order\Item::alias('item')
|
||||
->join("order","item.order_no = order.order_no","left")
|
||||
->field('item.goods_type,item.item_id,count(item.id) AS total_item, COUNT(DISTINCT item.user_id) AS total_people')
|
||||
->group("CONCAT_WS('_', item.item_id,item.goods_type)")
|
||||
->where($where)
|
||||
->where('status', 'not in', $excluded_statuses)
|
||||
->order($sort, $order)->paginate($limit);
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$row){
|
||||
if($row->goods_type == 'course'){
|
||||
$type = ['article','column','video','audio','live'];
|
||||
}else{
|
||||
$type = [$row->goods_type];
|
||||
}
|
||||
|
||||
$row->goods = \app\common\model\goods\Handle::getGoodsQuery()->where([
|
||||
'id'=>$row->item_id,
|
||||
'type'=>['in',$type]
|
||||
])->find();
|
||||
}
|
||||
}
|
||||
|
||||
$goodsTotal = \app\admin\model\order\Item::alias('item')
|
||||
->join("order","item.order_no = order.order_no","left")
|
||||
->field('COUNT(item.id) AS goods_total')
|
||||
->where('status', 'not in', $excluded_statuses)
|
||||
->where($where)->find();
|
||||
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items(),'attr'=>[
|
||||
'goods_type'=>(new \app\admin\model\order\Item())->getGoodsTypeList(),
|
||||
'goods_total'=>$goodsTotal['goods_total']
|
||||
]);
|
||||
|
||||
return $this->success("获取成功",$result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据统计
|
||||
* @return mixed
|
||||
*/
|
||||
public function statistical(){
|
||||
|
||||
$coupon_id = input('coupon_id','');
|
||||
|
||||
$orderModel = new \app\admin\model\order\Order;
|
||||
|
||||
// 设置不统计的订单状态
|
||||
$excluded_statuses = [\app\common\constant\order\Status::STATUS_CLOSE, \app\common\constant\order\Status::STATUS_UNPAID, \app\common\constant\order\Status::STATUS_CANCEL, \app\common\constant\order\Status::STATUS_REFUND];
|
||||
|
||||
$result = $orderModel
|
||||
->where('status', 'not in', $excluded_statuses)
|
||||
->where('coupon_id', $coupon_id)
|
||||
->field([
|
||||
'SUM(real_price) AS total_order_amount',
|
||||
'SUM(coupon_discount_fee) AS total_discount_amount',
|
||||
'COUNT(DISTINCT user_id) AS total_users_used_coupon',
|
||||
'COUNT(*) AS order_count_with_coupon',
|
||||
'(SUM(real_price) / COUNT(*)) AS average_order_value',
|
||||
'(SUM(coupon_discount_fee) / SUM(real_price)) AS fee_effect_ratio',
|
||||
])
|
||||
->find();
|
||||
|
||||
// 领券总用户数
|
||||
$totalUsersWithCoupon = \app\admin\model\app\coupon\CouponUser::where('coupon_id', $coupon_id)
|
||||
->group('user_id')
|
||||
->count();
|
||||
// 添加领券总用户数到结果数组中
|
||||
$result['total_users_with_coupon'] = $totalUsersWithCoupon;
|
||||
|
||||
return $this->success("获取成功",$result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\app\coupon;
|
||||
use think\Db;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\app\coupon\Coupon as CouponModel;
|
||||
use app\admin\model\app\coupon\CouponUser as CouponUserModel;
|
||||
use app\common\traits\app\CouponSend;
|
||||
use app\admin\model\app\coupon\CouponGoods;
|
||||
use PHPExcel_IOFactory;
|
||||
/**
|
||||
* 领券用户
|
||||
*/
|
||||
class User extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
use CouponSend;
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new CouponUserModel;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = true;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->with(['user', 'order'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as $row) {
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items(),'attr'=>[
|
||||
'statusList'=>$this->model->statusList(),
|
||||
'getTypeList'=>$this->model->getTypeList(),
|
||||
]);
|
||||
|
||||
return $this->success("获取成功",$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换状态
|
||||
* @param $ids
|
||||
* @param $status
|
||||
* @return void
|
||||
*/
|
||||
public function ban($ids=null){
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ?: $this->request->post("ids");
|
||||
if (empty($ids)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
$pk = $this->model->getPk();
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||||
}
|
||||
$list = $this->model->where($pk, 'in', $ids)->select();
|
||||
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $item) {
|
||||
$row = [
|
||||
'status'=>2
|
||||
];
|
||||
$this->model->where([
|
||||
'id'=>$item['id']
|
||||
])->update($row);
|
||||
$count++;
|
||||
}
|
||||
Db::commit();
|
||||
} catch (PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($count) {
|
||||
$this->success("操作成功");
|
||||
}
|
||||
$this->error(__('未操作任何数据'));
|
||||
}
|
||||
|
||||
protected $exportIndex = 0;
|
||||
/**
|
||||
* 导出领取用户
|
||||
* @return void
|
||||
*/
|
||||
public function export(){
|
||||
|
||||
//当前是否为关联查询
|
||||
// $this->relationSearch = true;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
|
||||
$excelTitle = '领/用券用户【'.date('Y-m-d h:i',time()).'】';
|
||||
|
||||
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
//设置Excel属性
|
||||
$objPHPExcel->getProperties()->setTitle($excelTitle); //设置标题
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', '用户名');//可以指定位置
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('B1', '昵称');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('D1', '领券方式');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('E1', '领券时间');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('F1', '状态');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('G1', '关联订单号');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('H1', '用券时间');
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
// 给表格添加数据
|
||||
$this->model
|
||||
->with(['user', 'order'])
|
||||
->where($where)
|
||||
->chunk(10,function($list) use ($objPHPExcel) {
|
||||
if($list){
|
||||
foreach ($list as $key => $item){
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A'.(2 + $this->exportIndex), $item['user']['username']);
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('B'.(2 + $this->exportIndex), $item['user']['nickname']);
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('C'.(2 + $this->exportIndex), $item['user']['mobile']);
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('D'.(2 + $this->exportIndex), $item['get_type_text']);
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('E'.(2 + $this->exportIndex), $item['createtime'] ? date('Y-m-d H:i:s',$item['createtime']) : '-');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('F'.(2 + $this->exportIndex), $item['status_text']);
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('G'.(2 + $this->exportIndex), $item['use_order_id'] ? $item['use_order_id'] : '-');
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('H'.(2 + $this->exportIndex), $item['use_time'] ? date('Y-m-d H:i:s',$item['use_time']) : '-');
|
||||
$this->exportIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
},$this->model->getTable().'.id','desc');
|
||||
|
||||
|
||||
//设置字体
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFont()->setBold(true)->getColor()->setARGB(\PHPExcel_Style_Color::COLOR_BLACK);
|
||||
//设置水平居中
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
//设置背景颜色
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('D9FFC125');
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
||||
//激活当前表
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
ob_end_clean();//清除缓冲区,避免乱码
|
||||
//弹出提示下载文件
|
||||
header('pragma:public');
|
||||
header("Content-Disposition:attachment;filename={$excelTitle}.xlsx");
|
||||
header('Cache-Control: max-age=0');
|
||||
$objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');
|
||||
$objWriter->save( 'php://output');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发放优惠券
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$user_ids = $this->request->post('user_ids/a');
|
||||
$coupon_id = $this->request->post('coupon_id');
|
||||
$num = $this->request->post('num',1);
|
||||
|
||||
if(!$num){
|
||||
$this->error("请输入正确的发放数量");
|
||||
}
|
||||
|
||||
$users = \app\admin\model\User::whereIn('id', $user_ids)->select();
|
||||
|
||||
Db::transaction(function () use ($users, $coupon_id,$num) {
|
||||
$this->manualSend($users, $coupon_id,$num);
|
||||
});
|
||||
|
||||
$this->success('发放成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user