123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- namespace app\user\controller;
- use app\common\library\PHPExcelService;
- use library\Controller;
- use think\cache\driver\Redis;
- use think\Db;
- /**
- * 会员等级
- * Class Vip
- * @package app\user\controller
- */
- class Vip extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'store_vip';
- /**
- * 会员等级列表
- * @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 = 'Vip等级管理';
- $query = $this->_query($this->table)->where('is_del',0)->like('name');
- $query->dateBetween('create_at')->order('id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- //echo Db::getLastSql();die();
- }
- /**
- * 添加等级
- * @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 add()
- {
- $this->title = '添加等级';
- $this->_form($this->table, 'add');
- }
- /**
- * 编辑等级
- * @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
- */
- function edit()
- {
- $this->title = '编辑等级';
- $this->_form($this->table, 'add');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->post()){
- if ($data['discount'] == '') $this->error('请输入等级折扣');
- if ($data['discount'] < 1 || $data['discount'] > 10 ) $this->error('等级折扣错误');
- if(isset($data['id']) || !empty($data['id']) ){
- $data['update_at'] = date('Y-m-d H:i:s');
- }
- }
- }
- /**
- * 处理成功回调
- */
- public function _form_result($result){
- if($result){
- $this->uplog($result);
- $this->success('操作成功',url('/#/user/vip/index'));
- }
- }
- /**
- * @auth true
- * @menu true
- * 等级禁用
- */
- public function dis()
- {
- $data = $this->request->post();
- if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>0])){
- $this->uplog($data['id']);
- $this->success('恭喜您,数据更新成功');
- }else{
- $this->error('数据更新失败');
- }
- }
- /**
- * @auth true
- * @menu true
- * 等级开启
- */
- public function open()
- {
- $data = $this->request->post();
- if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>1])){
- $this->uplog($data['id']);
- $this->success('恭喜您,数据更新成功');
- }else{
- $this->error('数据更新失败');
- }
- }
- /**
- * @auth true
- * @menu true
- * 等级删除
- */
- public function del()
- {
- $data = $this->request->post();
- if (Db::name($this->table)->where('id',$data['id'])->update(['is_del'=>1])){
- $this->uplog($data['id']);
- $this->success('恭喜您,数据更新成功');
- }else{
- $this->error('数据更新失败');
- }
- }
- /**
- * @auth true
- * @menu true
- * 等级日志
- */
- public function uplog($id)
- {
- //插入修改日志 方便后期查问题
- $afterData = Db::name('store_vip')->where('id',$id)->find();
- $logdata = [
- 'uid' => $this->app->session->get('user.id'),
- 'vipid' => $id,
- 'after' => json_encode($afterData),
- ];
- Db::name('store_vip_log')->insert($logdata);
- }
- /**
- * @auth true
- * @menu true
- * 赠送会员等级
- */
- public function give()
- {
- if($this->request->post()){
- $data = $this->request->post();
- if (!isset($data['mid']) || $data['mid']==''){
- $this->error('请选择用户');
- }
- $otherData = [
- 'type' => 1,
- 'status' => 1,
- 'desc' => '后台人工赠送',
- 'order_table' => '',
- 'order_id' => '',
- ];
- $ret = memberVipChange($data['id'],$data['mid'],$otherData);
- if ($ret){
- $this->success('赠送成功');
- }else{
- $this->error('赠送失败');
- }
- }else{
- $id=$this->request->get('id');
- $this->assign('id',$id);
- $user = Db::name('store_member')
- ->field('id,name,phone,vip')
- ->where('is_deleted',0)
- ->select();
- foreach ($user as $k=>&$v){
- $v['vip_name'] = $v['vip'] > 0 ? Db::name('store_vip')->where('id',$v['vip'])->value('name') : '普通会员';
- }
- $this->assign('user',$user);
- $this->fetch();
- }
- }
- }
|