123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?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 CouponConfig extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'StoreCouponConfig';
- /**
- * 优惠券管理
- * @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 = '优惠券配置';
- $query = $this->_query($this->table)->like('title')->equal('status,type');
- $query->where(['is_deleted' => '0'])->order('id desc')->page();
- }
- /**
- * 数据列表处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- $type_arr = array('1'=>'发放券','2'=>'新人券','3'=>'推荐券');
- foreach ($data as &$value){
- $value['type_name'] = $type_arr[$value['type']];
- }
- }
- /**
- * 添加优惠券
- * @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 = '添加优惠券';
- $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()){
- if($data['low_amount']<=0){
- $this->error('使用条件需大于零');
- }
- if($data['amount']>$data['low_amount']){
- $this->error('优惠金额不能大于限制金额');
- }
- if($data['low_day'] <= 0){
- $this->error('使用期限许大于零');
- }
- if($data['type'] == 2){
- $data['is_new'] = 1;
- }
- }else{
- }
- }
- /**
- * 禁用优惠券
- * @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);
- }
- }
|