Member.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. $query = $this->_query($this->table)->where('is_deleted',0)->like('name,phone');
  44. $query->dateBetween('create_at')->order('id desc')->page();
  45. }
  46. /**
  47. * 数据列表处理
  48. * @auth true
  49. * @menu true
  50. * @param array $data
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. protected function _index_page_filter(&$data)
  56. {
  57. foreach ($data as $k=>&$v){
  58. }
  59. }
  60. //删除货主
  61. public function remove()
  62. {
  63. $this->_save($this->table, ['is_deleted' => '1']);
  64. }
  65. //禁用货主
  66. public function forbid()
  67. {
  68. $this->_save($this->table, ['status' => '0']);
  69. }
  70. //启用货主
  71. public function resume()
  72. {
  73. $this->_save($this->table, ['status' => '1']);
  74. }
  75. public function integral(){
  76. $this->title = '积分变更';
  77. $this->_form($this->table, 'form');
  78. }
  79. protected function _form_filter(&$data){
  80. if($this->request->isPost() && $this->request->action() == 'integral')
  81. {
  82. if($data['id']) {
  83. if($data['int_type'] == 6) {
  84. update_user_integral($data['id'],$data['int_num'],$data['int_type'],'后台增加');
  85. }else{
  86. update_user_integral($data['id'],$data['int_num'] * -1,$data['int_type'],'后台扣减');
  87. }
  88. }
  89. }
  90. }
  91. public function export(){
  92. $get_data = $this->request->get();
  93. $time = explode(' - ',$get_data['create_at']);
  94. $phone = $get_data['phone'];
  95. $name = $get_data['name'];
  96. $where = [];
  97. $where[] = ['status',1];
  98. $where[] = ['is_deleted',0];
  99. $where_str = ' status = 1 AND is_deleted = 0';
  100. if($name) $where_str .=' AND name like '."'%".$name."%'";
  101. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  102. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  103. //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die();
  104. $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');
  105. if(empty($data)) $this->error('暂无可以导出的数据');
  106. foreach ($data as $k=>&$v) {
  107. if(!$v) $v = '--';
  108. }
  109. $field=array(
  110. 'A' => array('name', '昵称'),
  111. 'B' => array('true_name', '真实姓名'),
  112. 'C' => array('phone', '联系电话'),
  113. 'D' => array('synopsis', '个人简介'),
  114. 'E' => array('create_at', '注册时间'),
  115. //'F' => array('headimg', '头像地址'),
  116. );
  117. $this->phpExcelList($field,$data,'会员列表');
  118. }
  119. public function phpExcelList($field=[],$list=[],$title='文件'){
  120. $PHPExcel=new \PHPExcel();
  121. $PHPSheet=$PHPExcel->getActiveSheet();
  122. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  123. foreach($list as $key=>$value)
  124. {
  125. foreach($field as $k=>$v){
  126. if($key == 0){
  127. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  128. }
  129. $i=$key+2;
  130. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  131. }
  132. }
  133. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  134. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  135. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  136. header('Cache-Control: max-age=0'); //禁止缓存
  137. $PHPWriter->save("php://output"); //输出到浏览器
  138. }
  139. }