Member.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace app\user\controller;
  3. use app\common\model\User;
  4. use library\Controller;
  5. use think\Db;
  6. /**
  7. * 会员信息管理
  8. * Class Member
  9. * @package app\Member\controller
  10. */
  11. class Member extends Controller
  12. {
  13. /**
  14. * 绑定数据表
  15. * @var string
  16. */
  17. protected $table = 'StoreMember';
  18. /**
  19. * 会员信息管理
  20. * @auth true
  21. * @menu true
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @throws \think\exception\PDOException
  27. */
  28. public function index()
  29. {
  30. $this->search_url = strtolower($this->request->controller()).'/index_search';
  31. $this->title = '会员信息管理';
  32. $where = [];
  33. $where[] = ['m.is_deleted','=',0];
  34. if($name = input('get.name')) $where[] = ['m.name','like','%'.$name.'%'];
  35. if($phone = input('get.phone')) $where[] = ['m.phone','like','%'.$phone.'%'];
  36. if($level_id = input('get.level_id')) $where[] = ['m.level_id','=',$level_id];
  37. $field="m.id,m.openid,m.name,m.headimg,m.level_exp,m.phone,m.status,m.create_at,w.growth,w.integral,w.money";
  38. $query = $this->_query($this->table)
  39. ->field($field)
  40. ->alias('m')
  41. ->leftJoin('UserWallet w','m.id =w.user_id')
  42. ->where($where)
  43. ->dateBetween('create_at')->order('id desc')->page();
  44. }
  45. /**
  46. * 数据列表处理
  47. * @auth true
  48. * @menu true
  49. * @param array $data
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. protected function _index_page_filter(&$data)
  55. {
  56. foreach ($data as $k=>&$v){
  57. }
  58. }
  59. /**
  60. * 删除
  61. * @auth true
  62. * @menu true
  63. * @param array $data
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. */
  68. public function remove()
  69. {
  70. $this->_save($this->table, ['is_deleted' => '1','phone'=>'','email'=>'']);
  71. }
  72. /**
  73. * 禁用
  74. * @auth true
  75. * @menu true
  76. * @param array $data
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. * @throws \think\exception\DbException
  80. */
  81. public function forbid()
  82. {
  83. $this->_save($this->table, ['status' => '0']);
  84. }
  85. /**
  86. * 启用
  87. * @auth true
  88. * @menu true
  89. * @param array $data
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. */
  94. public function resume()
  95. {
  96. $this->_save($this->table, ['status' => '1']);
  97. }
  98. /**
  99. * 添加
  100. * @auth true
  101. * @menu true
  102. * @param array $data
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @throws \think\exception\DbException
  106. */
  107. public function add(){
  108. $this->title = '添加';
  109. $this->_form($this->table, 'add');
  110. }
  111. /**
  112. *
  113. * 编辑
  114. * @auth true
  115. * @menu true
  116. * @param array $data
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. */
  121. public function edit()
  122. {
  123. $this->title = '编辑';
  124. $this->_form($this->table, 'form');
  125. }
  126. /**
  127. * 钱包管理
  128. * @auth true
  129. * @menu true
  130. * @param array $data
  131. * @throws \think\db\exception\DataNotFoundException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. * @throws \think\exception\DbException
  134. */
  135. public function wallet()
  136. {
  137. $this->title = '钱包';
  138. $this->_form($this->table, 'wallet');
  139. }
  140. protected function _form_filter(&$data){
  141. if($this->request->isGet() && $this->request->action() =='edit') {
  142. }
  143. }
  144. public function export(){
  145. $get_data = $this->request->get();
  146. $time = explode(' - ',$get_data['create_at']);
  147. $phone = $get_data['phone'];
  148. $name = $get_data['name'];
  149. $where = [];
  150. $where[] = ['status',1];
  151. $where[] = ['is_deleted',0];
  152. $where_str = ' status = 1 AND is_deleted = 0';
  153. if($name) $where_str .=' AND name like '."'%".$name."%'";
  154. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  155. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  156. $data = Db::query("SELECT name,headimg,email,phone,create_at,account_type FROM dd_store_member WHERE".$where_str.' ORDER BY id DESC');
  157. if(empty($data)) $this->error('暂无可以导出的数据');
  158. foreach ($data as $k=>&$v) {
  159. if(!$v) $v = '--';
  160. }
  161. $field=array(
  162. 'A' => array('name', '昵称'),
  163. 'B' => array('email', '邮箱'),
  164. 'C' => array('phone', '电话'),
  165. 'E' => array('create_at', '注册时间'),
  166. );
  167. $this->phpExcelList($field,$data,'会员列表');
  168. }
  169. public function phpExcelList($field=[],$list=[],$title='文件'){
  170. $PHPExcel=new \PHPExcel();
  171. $PHPSheet=$PHPExcel->getActiveSheet();
  172. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  173. foreach($list as $key=>$value)
  174. {
  175. foreach($field as $k=>$v){
  176. if($key == 0){
  177. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  178. }
  179. $i=$key+2;
  180. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  181. }
  182. }
  183. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  184. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  185. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  186. header('Cache-Control: max-age=0'); //禁止缓存
  187. $PHPWriter->save("php://output"); //输出到浏览器
  188. }
  189. }