UserWish.php 6.5 KB

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