Member.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use library\Controller;
  16. use think\Db;
  17. use function GuzzleHttp\Psr7\build_query;
  18. /**
  19. * 会员信息管理
  20. * Class Member
  21. * @package app\store\controller
  22. */
  23. class Member extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'StoreMember';
  30. /**
  31. * 会员信息管理
  32. * @auth true
  33. * @menu true
  34. * @throws \think\Exception
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. * @throws \think\exception\PDOException
  39. */
  40. public function index()
  41. {
  42. $this->title = '会员信息管理';
  43. $lev_set = Db::table('member_level')->field('id,name')->select();
  44. $lev_set = array_column($lev_set,null,'id');
  45. $lev_data = ['-1'=>'全部','0'=>'普通会员'];
  46. array_map(function ($v)use (&$lev_data){
  47. $lev_data[$v['id']] = $v['name'];
  48. },$lev_set);
  49. $this->lev_set =$lev_data;
  50. $this->level_id =input('level_id',-1);
  51. $query = $this->_query($this->table)->where('is_deleted',0)->like('name,phone');
  52. if($this->level_id > -1) $query->where('level_id',$this->level_id);
  53. $query->dateBetween('create_at')->order('id desc')->page();
  54. }
  55. /**
  56. * 数据列表处理
  57. * @auth true
  58. * @menu true
  59. * @param array $data
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. */
  64. protected function _index_page_filter(&$data)
  65. {
  66. foreach ($data as $k=>&$v){
  67. }
  68. }
  69. //删除货主
  70. public function remove()
  71. {
  72. $this->_save($this->table, ['is_deleted' => '1']);
  73. }
  74. //禁用货主
  75. public function forbid()
  76. {
  77. $this->_save($this->table, ['status' => '0']);
  78. }
  79. //启用货主
  80. public function resume()
  81. {
  82. $this->_save($this->table, ['status' => '1']);
  83. }
  84. public function integral(){
  85. $this->title = '积分变更';
  86. $this->_form($this->table, 'form');
  87. }
  88. protected function _form_filter(&$data){
  89. if($this->request->isPost() && $this->request->action() == 'integral')
  90. {
  91. if($data['id']) {
  92. if($data['int_type'] == 6) {
  93. update_user_integral($data['id'],$data['int_num'],$data['int_type'],'后台增加');
  94. }else{
  95. update_user_integral($data['id'],$data['int_num'] * -1,$data['int_type'],'后台扣减');
  96. }
  97. }
  98. }
  99. }
  100. public function export(){
  101. $get_data = $this->request->get();
  102. $time = explode(' - ',$get_data['create_at']);
  103. $phone = $get_data['phone'];
  104. $name = $get_data['name'];
  105. $where = [];
  106. $where[] = ['status',1];
  107. $where[] = ['is_deleted',0];
  108. $where_str = ' status = 1 AND is_deleted = 0';
  109. if($name) $where_str .=' AND name like '."'%".$name."%'";
  110. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  111. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  112. //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die();
  113. $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');
  114. if(empty($data)) $this->error('暂无可以导出的数据');
  115. foreach ($data as $k=>&$v) {
  116. if(!$v) $v = '--';
  117. }
  118. $field=array(
  119. 'A' => array('name', '昵称'),
  120. 'B' => array('true_name', '真实姓名'),
  121. 'C' => array('phone', '联系电话'),
  122. 'D' => array('synopsis', '个人简介'),
  123. 'E' => array('create_at', '注册时间'),
  124. //'F' => array('headimg', '头像地址'),
  125. );
  126. $this->phpExcelList($field,$data,'会员列表');
  127. }
  128. public function phpExcelList($field=[],$list=[],$title='文件'){
  129. $PHPExcel=new \PHPExcel();
  130. $PHPSheet=$PHPExcel->getActiveSheet();
  131. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  132. foreach($list as $key=>$value)
  133. {
  134. foreach($field as $k=>$v){
  135. if($key == 0){
  136. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  137. }
  138. $i=$key+2;
  139. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  140. }
  141. }
  142. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  143. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  144. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  145. header('Cache-Control: max-age=0'); //禁止缓存
  146. $PHPWriter->save("php://output"); //输出到浏览器
  147. }
  148. }