title = '会员信息管理'; $id_order = input('id_order') == 1 ? 'asc' : 'desc'; $integral_order = input('integral_order') == 1 ? 'asc' : 'desc'; $query = $this->_query($this->table)->where('is_deleted',0) ->like('name,phone') ->equal('status,vip,group,is_open_official_DDC'); $query->dateBetween('create_at')->order("id $id_order ,integral $integral_order")->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) { foreach ($data as $k=>&$v){ $v['group_name'] = Db::name('store_member_group')->where('id',$v['group'])->value('name'); $v['invite_count'] = Db::name($this->table)->where('pid',$v['id'])->count(); $v['vip_name'] = $v['vip'] > 0 ? Db::name('store_vip')->where('id',$v['vip'])->value('name') : '普通会员'; } $this->group_list = Db::name('store_member_group')->select(); $this->group_list = array_merge([['id'=>'','name'=>'全部会员']],$this->group_list); } //删除货主 public function remove() { $this->_save($this->table, ['is_deleted' => '1']); } //禁用货主 public function forbid() { $this->_save($this->table, ['status' => '0']); } //启用货主 public function resume() { $this->_save($this->table, ['status' => '1']); } /** * 编辑抢购卡 * @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 snap_card(){ $this->title = '抢购卡'; $this->_form($this->table, 'snap_card'); } /** * 编辑积分 * @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 integral(){ $this->title = '积分变更'; $this->_form($this->table, 'integral'); } /** * 编辑转赠次数 * @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 examples_number(){ $this->title = '转赠次数'; $this->_form($this->table, 'examples_number'); } /** * 编辑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 vip(){ $this->title = 'vip'; $this->_form($this->table, '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 info(){ $this->title = '详情'; $this->_form($this->table, 'info'); } /** * 编辑分组 * @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 save_group(){ $this->title = '编辑分组'; $this->group_list = Db::name('store_member_group')->select(); $this->_form($this->table, 'save_group'); } /** * 一键抢购卡 * @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 snap_cards(){ $this->title = '抢购卡'; $this->group_list = Db::name('store_member_group')->select(); $this->_form($this->table, 'snap_cards'); } /** * 一键分组 * @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 grouping(){ $this->title = '分组'; $list = Db::name('store_member') ->where('is_deleted',0) ->where('group',0) ->field('id,name,phone') ->select(); $group_list = Db::name('store_member_group')->select(); $this->assign('list',$list); $this->assign('group_list',$group_list); $this->_form($this->table, 'grouping'); } /** * 钱包管理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function wallet() { $this->title = '钱包'; $this->_form($this->table, 'wallet'); } protected function _form_filter(&$data){ if($this->request->isPost() && $this->request->action() == 'snap_card') { if($data['id']) { if($data['int_type'] == 4) { $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',1); }else{ $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',0); } if ($result){ setMembercard($data['id']); setMemberInfoHash($data['id']); $this->success('调整成功'); } } } if($this->request->isPost() && $this->request->action() == 'snap_cards') { if (!isset($data['group']) || $data['group']==''){ $this->error('请选择分组'); } $user = Db::name('store_member')->where('is_deleted',0)->where('group',$data['group'])->select(); foreach ($user as &$v){ $result = memberMoneyChange($data['snap_card'],2,$v['id'],'后台人工调整',1); if ($result){ setMembercard($v['id']); setMemberInfoHash($v['id']); } } $this->success('调整成功'); } if($this->request->isPost() && $this->request->action() == 'integral') { if($data['id']) { if($data['int_type'] == 4) { $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',1); }else{ $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',0); } if ($result){ setMemberInfoHash($data['id']); $this->success('调整成功'); } } } if($this->request->isPost() && $this->request->action() == 'examples_number') { if($data['id']) { if (Db::name('store_member')->where('id',$data['id'])->update(['examples_number'=>$data['examples_number'],'update_at'=>date('Y-m-d H:i:s')])){ setMemberInfoHash($data['id']); $this->success('调整成功'); } } } if($this->request->isPost() && $this->request->action() == 'vip') { if($data['id']) { if (Db::name('store_member')->where('id',$data['id'])->update(['vip'=>$data['vip'],'update_at'=>date('Y-m-d H:i:s')])){ setMemberInfoHash($data['id']); $this->success('调整成功'); } } } if($this->request->isPost() && $this->request->action() == 'info') { if($data['id']) { if ($data['password']!=''){ $date['password'] = md5($data['password']); } if ($data['second_password']!=''){ $date['second_password'] = md5($data['second_password']); } $date['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$data['id'])->update($date)){ setMemberInfoHash($data['id']); $this->success('编辑成功'); } $this->error('编辑失败'); } } if($this->request->isPost() && $this->request->action() == 'save_group') { if($data['id']) { if (!isset($data['group']) || $data['group']==''){ $this->error('请选择分组'); } $date['group'] = $data['group']; $date['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$data['id'])->update($date)){ setMemberInfoHash($data['id']); $this->success('编辑成功'); } $this->error('编辑失败'); } } if($this->request->isPost() && $this->request->action() == 'grouping') { if (!isset($data['group']) || $data['group']==''){ $this->error('请选择分组'); } if (!isset($data['users']) || $data['users']==''){ $this->error('请选择用户'); } if (Db::name('store_member')->whereIn('id',$data['users'])->update(['group'=>$data['group']])){ $this->success('分组成功',url('/#/user/member/index')); } $this->error('分组失败',url('/#/user/member/index')); } if($this->request->post() && $this->request->action() == 'wallet') { // 增加 if($data['int_type'] == 1){ if($data['change_money']) memberMoneyChange($data['change_money'],3,$data['id'],'后台增加',1,0); }else{ if($data['change_money']) memberMoneyChange($data['change_money'],3,$data['id'],'后台扣减',0,0); } setMemberInfoHash($data['id']); } } public function shoucang(){ $id=$this->request->get('id'); $this->title = Db::name($this->table)->where('id',$id)->value('name').'--收藏明细'; $query = $this->_query('store_order_info')->where('mid',$id)->whereIn('status','1,3'); $query->dateBetween('create_at')->order('id desc')->page(); $this->fetch(); } /** * 数据列表处理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _shoucang_page_filter(&$data) { foreach ($data as $k=>&$v){ $v['pro_info'] =json_decode($v['pro_info'],true); $info = Db::name('store_member')->where('id',$v['mid'])->field('name,phone')->find(); $v['scz'] = $info['name'].'('.$info['phone'].')'; $pro_info = Db::name('store_collection')->where('id',$v['c_id'])->field('one_given_day,other_given_day')->find(); $log = Db::name('store_collect_examples_log') ->where('order_info_id',$v['id']) ->count(); if (!$log){ if ($pro_info['one_given_day']!=0){ $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['one_given_day']*24*60*60)); }else{ $v['exam_time'] = $v['create_at']; } }else{ if ($pro_info['other_given_day']!=0){ $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['other_given_day']*24*60*60)); }else{ $v['exam_time'] = $v['create_at']; } } } } public function export(){ $get_data = $this->request->get(); $time = explode(' - ',$get_data['create_at']); $phone = $get_data['phone']; $name = $get_data['name']; $where = []; $where[] = ['status',1]; $where[] = ['is_deleted',0]; $where_str = ' status = 1 AND is_deleted = 0'; if($name) $where_str .=' AND name like '."'%".$name."%'"; if($phone) $where_str .=' AND phone like '."'%".$phone."%'"; if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'"; //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die(); $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC'); if(empty($data)) $this->error('暂无可以导出的数据'); foreach ($data as $k=>&$v) { if(!$v) $v = '--'; } $field=array( 'A' => array('name', '昵称'), 'B' => array('true_name', '真实姓名'), 'C' => array('phone', '联系电话'), 'D' => array('synopsis', '个人简介'), 'E' => array('create_at', '注册时间'), //'F' => array('headimg', '头像地址'), ); $this->phpExcelList($field,$data,'会员列表'); } public function phpExcelList($field=[],$list=[],$title='文件'){ $PHPExcel=new \PHPExcel(); $PHPSheet=$PHPExcel->getActiveSheet(); $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称 foreach($list as $key=>$value) { foreach($field as $k=>$v){ if($key == 0){ $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]); } $i=$key+2; $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]); } } $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件, header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格 header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称 header('Cache-Control: max-age=0'); //禁止缓存 $PHPWriter->save("php://output"); //输出到浏览器 } /** * 添加 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function add(){ $this->title = '添加'; if($this->request->isPost()) { list($data) = [$this->request->post()]; $check_where =[]; $check_where[] = ['phone','=',$data['phone']]; $user_info = Db::name('store_member')->where($check_where)->find(); if($user_info) $this->error('用户已存在'); if (!preg_match('/^[0-9a-z]{6,12}$/i',$data['password'])) $this->error('密码格式错误,请输入6-12位数字+字母'); if (!preg_match('/^[0-9]{6}$/i',$data['second_password'])) $this->error('二级密码格式错误,请输入6位纯数字'); $pid = 0; if($data['invite_code']){ $isset = Db::name('store_member')->where('is_deleted',0)->where('invite_code',$data['invite_code'])->value('pid'); if (!$isset) $this->error('邀请码不存在'); $pid = $isset; } $user_add = [ 'phone'=>$data['phone'], 'pid'=>$pid, 'password'=>md5($data['password']), 'second_password'=>md5($data['second_password']), 'wallet_address'=>'', 'accountName'=>$data['phone'] ]; $member_id = Db::name('store_member')->insertGetId($user_add); if ($member_id){ $code = get32Str(8); $invite_img = setintivecode($code); $invite_address = getintiveaddress($code); Db::name('store_member')->where('id',$member_id)->update(['name'=>'收藏家'.$member_id,'invite_img'=>$invite_img,'invite_address'=>$invite_address,'invite_code'=>$code]); //邀请好友送积分 if ($data['invite_code']>0){ $invite_friends_integral = getConfigValue('invite_friends_integral'); memberMoneyChange($invite_friends_integral,1,$data['invite_code'],'邀请好友',1,$member_id); } } $this->success('添加成功'); } $this->_form($this->table, 'add'); } /** * 导出EXCL * @remark 根据WHERE条件导出EXCL * @param array $post 查询条件所需值 * @return array */ public function get_excl() { set_time_limit(0); $where =[]; $where[] = ['is_deleted','=',0]; if($name = $this->request->get('name')) $where[] = ['name','like','%'.$name.'%']; if($phone = $this->request->get('phone')) $where[] = ['phone','like','%'.$phone.'%']; $id_order = input('id_order') == 1 ? 'asc' : 'desc'; $integral_order = input('integral_order') == 1 ? 'asc' : 'desc'; $sel_time = input('create_at'); if($sel_time) { $time_arr = explode(' - ',$sel_time); $where[]= ['create_at','> time',$time_arr[0]]; $where[]= ['create_at','< time',$time_arr[1]]; } $list = Db::name('store_member') ->where($where) ->order("id $id_order ,integral $integral_order") ->select(); $export = []; if (is_array($list)) { foreach ($list as $index => $item) { $item['is_auth'] = $item['is_auth'] ? '是':'否'; $export[] = [ $item['id'], $item['name'], $item['phone'], $item['wallet_address'], $item['money'], $item['create_at'], $item['is_auth'], $item['true_name'], $item['id_card'], ]; } } $title = ['用户ID','用户名','手机号','钱包地址','余额','时间','是否认证','真实姓名','身份证号']; PHPExcelService::setExcelHeader($title) ->setExcelTile('用户导出' . date('YmdHis', time()), '用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())) ->setExcelContent($export) ->ExcelSave(); } }