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(); } } }