|
@@ -0,0 +1,228 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | ThinkAdmin
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 官方网站: http://demo.thinkadmin.top
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 开源协议 ( https://mit-license.org )
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
|
|
|
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+
|
|
|
+namespace app\store\controller;
|
|
|
+
|
|
|
+use app\store\service\ExtendService;
|
|
|
+use library\Controller;
|
|
|
+use library\tools\Data;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 优惠券列表
|
|
|
+ * Class Config
|
|
|
+ * @package app\store\controller
|
|
|
+ */
|
|
|
+class CouponList extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 绑定数据表
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $table = 'StoreCouponList';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券管理
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $this->title = '优惠券列表';
|
|
|
+ $coupon_id=$this->request->get('coupon_id');
|
|
|
+
|
|
|
+ $this->byWhere(1)
|
|
|
+ ->field('a.*,b.name,b.headimg')
|
|
|
+ ->where('a.config_id',$coupon_id)
|
|
|
+ ->order('a.id desc')
|
|
|
+ ->page();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 搜索条件
|
|
|
+ * @return \library\helper\QueryHelper
|
|
|
+ */
|
|
|
+ protected function byWhere($type)
|
|
|
+ {
|
|
|
+ if ($type == 1) {
|
|
|
+ $query = $this->_query($this->table);
|
|
|
+ } elseif ($type == 2) {
|
|
|
+ $query = Db::name($this->table);
|
|
|
+ }
|
|
|
+ $query = $query->alias('a')
|
|
|
+ ->join('store_member b', 'a.user_id=b.id');
|
|
|
+
|
|
|
+ if (isset($_GET['status']) && $_GET['status']) {
|
|
|
+ $query->where('a.status', $_GET['status']);
|
|
|
+ }
|
|
|
+ if (isset($_GET['title']) && $_GET['title']) {
|
|
|
+ $query->where('a.title', 'like','%'.$_GET['title'].'%');
|
|
|
+ }
|
|
|
+ if (isset($_GET['user_info']) && $_GET['user_info']) {
|
|
|
+ $query->where('b.name|b.phone', 'like', '%' . $_GET['user_info'] . '%');
|
|
|
+ }
|
|
|
+ return $query;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据列表处理
|
|
|
+ * @param array $data
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ protected function _index_page_filter(&$data)
|
|
|
+ {
|
|
|
+ foreach ($data as $k=>&$v) {
|
|
|
+
|
|
|
+ if($v['status'] == 0 && $v['end'] < date('Y-m-d')){
|
|
|
+ Db::name('store_coupon_list')->where('id',$v['id'])->update(array('status'=>2));
|
|
|
+ $v['status'] = 2;
|
|
|
+ }
|
|
|
+ $v['member'] = Db::table('store_member')->where('id',$v['user_id'])->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加优惠券
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ $this->title = '添加优惠券';
|
|
|
+ if($this->request->isPost()){
|
|
|
+
|
|
|
+ if($this->request->post('user')==0){
|
|
|
+ $user_ids=explode(',',$this->request->post('user_ids'));
|
|
|
+ //指定用户发放
|
|
|
+ }else{
|
|
|
+ //全部用户发方
|
|
|
+ $user_ids=Db::table('store_member')->where('status',1)->column('id');
|
|
|
+ }
|
|
|
+ if(empty($user_ids[0])){
|
|
|
+ $this->error('没有要发放的用户');
|
|
|
+ }
|
|
|
+ $coupon=Db::table('store_coupon_config')->where('id',$this->request->post('coupon_id'))->where('status',1)->where('is_deleted',0)->find();
|
|
|
+ if(empty($coupon)){
|
|
|
+ $this->error('优惠券不存在或已禁用');
|
|
|
+ }
|
|
|
+
|
|
|
+ $error=[];
|
|
|
+ foreach ($user_ids as $k=>$v){
|
|
|
+ $data=[];
|
|
|
+ $data['config_id']=$coupon['id'];
|
|
|
+ $data['user_id']=$v;
|
|
|
+ $data['title']=$coupon['title'];
|
|
|
+ $data['low_amount']=$coupon['low_amount'];
|
|
|
+ $data['amount']=$coupon['amount'];
|
|
|
+ $data['start']=date('Y-m-d');
|
|
|
+ $data['end']=date('Y-m-d', strtotime('+'.$coupon['low_day'].' days') );
|
|
|
+ $data['status']=0;
|
|
|
+ Db::table('store_coupon_list')->insert($data);
|
|
|
+ }
|
|
|
+ $msg='发放成功';
|
|
|
+ if($error){
|
|
|
+ $name=Db::table('store_member')->where('id','in',$error)->column('name');
|
|
|
+ $name=implode(',',$name);
|
|
|
+ $msg='发放成功'.$name.'等用户因规则原因,发放失败';
|
|
|
+ }
|
|
|
+ $this->success($msg);
|
|
|
+ }else{
|
|
|
+ $this->_form($this->table, 'form');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑优惠券
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ $this->title = '编辑优惠券';
|
|
|
+ $this->_form($this->table, 'form');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表单数据处理
|
|
|
+ * @param array $data
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ protected function _form_filter(&$data)
|
|
|
+ {
|
|
|
+ if($this->request->isPost()){
|
|
|
+
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $coupon_id=$this->request->get('coupon_id');
|
|
|
+ $this->coupon_id=$coupon_id;
|
|
|
+ $this->member=Db::table('store_member')->field('id,phone,name')->where('status',1)->select();
|
|
|
+ $this->member_count=count($this->member);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 禁用优惠券
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function forbid()
|
|
|
+ {
|
|
|
+ $this->_save($this->table, ['status' => '0']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用优惠券
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function resume()
|
|
|
+ {
|
|
|
+ $this->_save($this->table, ['status' => '1']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除优惠券
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function remove()
|
|
|
+ {
|
|
|
+ $this->_delete($this->table);
|
|
|
+ }
|
|
|
+}
|