Member.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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\user\controller;
  15. use app\common\library\PHPExcelService;
  16. use library\Controller;
  17. use think\Db;
  18. use function GuzzleHttp\Psr7\build_query;
  19. /**
  20. * 会员信息管理
  21. * Class Member
  22. * @package app\user\controller
  23. */
  24. class Member extends Controller
  25. {
  26. /**
  27. * 绑定数据表
  28. * @var string
  29. */
  30. protected $table = 'StoreMember';
  31. /**
  32. * 会员信息管理
  33. * @auth true
  34. * @menu true
  35. * @throws \think\Exception
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. * @throws \think\exception\PDOException
  40. */
  41. public function index()
  42. {
  43. $this->title = '会员信息管理';
  44. $query = $this->_query($this->table)->where('is_deleted',0)
  45. ->like('name,phone')
  46. ->equal('status');
  47. $coll_id = $this->request->get('coll_id');
  48. $query->dateBetween('create_at')
  49. ->when($coll_id,function ($query) use ($coll_id){
  50. $mids = Db::name('store_order_info')->whereIn('c_id',$coll_id)->where('status','neq',2)->where('is_destruction',1)->column('mid');
  51. echo Db::name('store_order_info')->getLastSql();
  52. $query->whereIn('id',$mids);
  53. })
  54. ->order('id desc')->page();
  55. }
  56. /**
  57. * 数据列表处理
  58. * @auth true
  59. * @menu true
  60. * @param array $data
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @throws \think\exception\DbException
  64. */
  65. protected function _index_page_filter(&$data)
  66. {
  67. foreach ($data as $k=>&$v){
  68. $v['group_name'] = Db::name('store_member_group')->where('id',$v['group'])->value('name');
  69. $v['invite_count'] = Db::name($this->table)->where('pid',$v['id'])->count();
  70. }
  71. $this->group_list = Db::name('store_member_group')->select();
  72. $this->group_list = array_merge([['id'=>'','name'=>'全部会员']],$this->group_list);
  73. //藏品列表
  74. $this->coll_list = Db::name('store_collection')->where('is_deleted',0)->field('id,name')->select();
  75. $this->coll_list = array_merge([['id'=>'','name'=>'全部']],$this->coll_list);
  76. $goods = [];
  77. $tmpGoods = Db::table('store_collection')->where('is_deleted', 0)->field('id,name')->select();
  78. foreach($tmpGoods as $key=>$val){
  79. $goods[$key]['name'] = $val['name'];
  80. $goods[$key]['value'] = (string)$val['id'];
  81. }
  82. $this->assign('goods', $goods);
  83. }
  84. //删除货主
  85. public function remove()
  86. {
  87. $this->_save($this->table, ['is_deleted' => '1']);
  88. }
  89. //禁用货主
  90. public function forbid()
  91. {
  92. $this->_save($this->table, ['status' => '0']);
  93. }
  94. //启用货主
  95. public function resume()
  96. {
  97. $this->_save($this->table, ['status' => '1']);
  98. }
  99. /**
  100. * 编辑抢购卡
  101. * @auth true
  102. * @menu true
  103. * @throws \think\Exception
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. * @throws \think\exception\DbException
  107. * @throws \think\exception\PDOException
  108. */
  109. public function snap_card(){
  110. $this->title = '抢购卡';
  111. $this->_form($this->table, 'snap_card');
  112. }
  113. /**
  114. * 编辑积分
  115. * @auth true
  116. * @menu true
  117. * @throws \think\Exception
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. * @throws \think\exception\DbException
  121. * @throws \think\exception\PDOException
  122. */
  123. public function integral(){
  124. $this->title = '积分变更';
  125. $this->_form($this->table, 'integral');
  126. }
  127. /**
  128. * 编辑转赠次数
  129. * @auth true
  130. * @menu true
  131. * @throws \think\Exception
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\ModelNotFoundException
  134. * @throws \think\exception\DbException
  135. * @throws \think\exception\PDOException
  136. */
  137. public function examples_number(){
  138. $this->title = '转赠次数';
  139. $this->_form($this->table, 'examples_number');
  140. }
  141. /**
  142. * 编辑vip
  143. * @auth true
  144. * @menu true
  145. * @throws \think\Exception
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\ModelNotFoundException
  148. * @throws \think\exception\DbException
  149. * @throws \think\exception\PDOException
  150. */
  151. public function vip(){
  152. $this->title = 'vip';
  153. $this->_form($this->table, 'vip');
  154. }
  155. /**
  156. * 编辑详情
  157. * @auth true
  158. * @menu true
  159. * @throws \think\Exception
  160. * @throws \think\db\exception\DataNotFoundException
  161. * @throws \think\db\exception\ModelNotFoundException
  162. * @throws \think\exception\DbException
  163. * @throws \think\exception\PDOException
  164. */
  165. public function info(){
  166. $this->title = '详情';
  167. $this->_form($this->table, 'info');
  168. }
  169. /**
  170. * 编辑分组
  171. * @auth true
  172. * @menu true
  173. * @throws \think\Exception
  174. * @throws \think\db\exception\DataNotFoundException
  175. * @throws \think\db\exception\ModelNotFoundException
  176. * @throws \think\exception\DbException
  177. * @throws \think\exception\PDOException
  178. */
  179. public function save_group(){
  180. $this->title = '编辑分组';
  181. $this->group_list = Db::name('store_member_group')->select();
  182. $this->_form($this->table, 'save_group');
  183. }
  184. /**
  185. * 一键抢购卡
  186. * @auth true
  187. * @menu true
  188. * @throws \think\Exception
  189. * @throws \think\db\exception\DataNotFoundException
  190. * @throws \think\db\exception\ModelNotFoundException
  191. * @throws \think\exception\DbException
  192. * @throws \think\exception\PDOException
  193. */
  194. public function snap_cards(){
  195. $this->title = '抢购卡';
  196. $this->group_list = Db::name('store_member_group')->select();
  197. $this->_form($this->table, 'snap_cards');
  198. }
  199. /**
  200. * 一键分组
  201. * @auth true
  202. * @menu true
  203. * @throws \think\Exception
  204. * @throws \think\db\exception\DataNotFoundException
  205. * @throws \think\db\exception\ModelNotFoundException
  206. * @throws \think\exception\DbException
  207. * @throws \think\exception\PDOException
  208. */
  209. public function grouping(){
  210. $this->title = '分组';
  211. $list = Db::name('store_member')
  212. ->where('is_deleted',0)
  213. ->where('group',0)
  214. ->field('id,name,phone')
  215. ->select();
  216. $group_list = Db::name('store_member_group')->select();
  217. $this->assign('list',$list);
  218. $this->assign('group_list',$group_list);
  219. $this->_form($this->table, 'grouping');
  220. }
  221. /**
  222. * 回收藏品
  223. * @auth true
  224. * @menu true
  225. * @throws \think\Exception
  226. * @throws \think\db\exception\DataNotFoundException
  227. * @throws \think\db\exception\ModelNotFoundException
  228. * @throws \think\exception\DbException
  229. * @throws \think\exception\PDOException
  230. */
  231. public function recycling(){
  232. $this->title = '回收藏品';
  233. $this->_form($this->table, 'recycling');
  234. }
  235. protected function _form_filter(&$data){
  236. if($this->request->isPost() && $this->request->action() == 'snap_card')
  237. {
  238. if($data['id']) {
  239. if($data['int_type'] == 4) {
  240. $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',1);
  241. }else{
  242. $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',0);
  243. }
  244. if ($result){
  245. setMembercard($data['id']);
  246. setMemberInfoHash($data['id']);
  247. $this->success('调整成功');
  248. }
  249. }
  250. }
  251. if($this->request->isPost() && $this->request->action() == 'snap_cards')
  252. {
  253. if (!isset($data['group']) || $data['group']==''){
  254. $this->error('请选择分组');
  255. }
  256. $user = Db::name('store_member')->where('is_deleted',0)->where('group',$data['group'])->select();
  257. foreach ($user as &$v){
  258. $result = memberMoneyChange($data['snap_card'],2,$v['id'],'后台人工调整',1);
  259. if ($result){
  260. setMembercard($v['id']);
  261. setMemberInfoHash($v['id']);
  262. }
  263. }
  264. $this->success('调整成功');
  265. }
  266. if($this->request->isPost() && $this->request->action() == 'integral')
  267. {
  268. if($data['id']) {
  269. if($data['int_type'] == 4) {
  270. $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',1);
  271. }else{
  272. $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',0);
  273. }
  274. if ($result){
  275. setMemberInfoHash($data['id']);
  276. $this->success('调整成功');
  277. }
  278. }
  279. }
  280. if($this->request->isPost() && $this->request->action() == 'examples_number')
  281. {
  282. if($data['id']) {
  283. if (Db::name('store_member')->where('id',$data['id'])->update(['examples_number'=>$data['examples_number'],'update_at'=>date('Y-m-d H:i:s')])){
  284. setMemberInfoHash($data['id']);
  285. $this->success('调整成功');
  286. }
  287. }
  288. }
  289. if($this->request->isPost() && $this->request->action() == 'vip')
  290. {
  291. if($data['id']) {
  292. if (Db::name('store_member')->where('id',$data['id'])->update(['vip'=>$data['vip'],'update_at'=>date('Y-m-d H:i:s')])){
  293. setMemberInfoHash($data['id']);
  294. $this->success('调整成功');
  295. }
  296. }
  297. }
  298. if($this->request->isPost() && $this->request->action() == 'info')
  299. {
  300. if($data['id']) {
  301. if ($data['password']!=''){
  302. $date['password'] = md5($data['password']);
  303. }
  304. if ($data['second_password']!=''){
  305. $date['second_password'] = md5($data['second_password']);
  306. }
  307. $date['update_at'] = date('Y-m-d H:i:s');
  308. if (Db::name('store_member')->where('id',$data['id'])->update($date)){
  309. setMemberInfoHash($data['id']);
  310. $this->success('编辑成功');
  311. }
  312. $this->error('编辑失败');
  313. }
  314. }
  315. if($this->request->isPost() && $this->request->action() == 'save_group')
  316. {
  317. if($data['id']) {
  318. if (!isset($data['group']) || $data['group']==''){
  319. $this->error('请选择分组');
  320. }
  321. $date['group'] = $data['group'];
  322. $date['update_at'] = date('Y-m-d H:i:s');
  323. if (Db::name('store_member')->where('id',$data['id'])->update($date)){
  324. setMemberInfoHash($data['id']);
  325. $this->success('编辑成功');
  326. }
  327. $this->error('编辑失败');
  328. }
  329. }
  330. if($this->request->isPost() && $this->request->action() == 'grouping')
  331. {
  332. if (!isset($data['group']) || $data['group']==''){
  333. $this->error('请选择分组');
  334. }
  335. if (!isset($data['users']) || $data['users']==''){
  336. $this->error('请选择用户');
  337. }
  338. if (Db::name('store_member')->whereIn('id',$data['users'])->update(['group'=>$data['group']])){
  339. $this->success('分组成功',url('/#/user/member/index'));
  340. }
  341. $this->error('分组失败',url('/#/user/member/index'));
  342. }
  343. if($this->request->isPost() && $this->request->action() == 'recycling')
  344. {
  345. $user = Db::name('store_member')->where('phone',$data['phone'])->find();
  346. if (!$user) $this->error('手机号不存在');
  347. //获取被回收的藏品
  348. $ids = Db::name('store_order_info')
  349. ->where('mid',$data['id'])
  350. ->where('status','neq',2)
  351. ->where('is_destruction',1)
  352. ->column('id');
  353. if (!$ids) $this->error('无可回收藏品');
  354. $idss = implode(',',$ids);
  355. $ins_data = [
  356. 'mid'=>$data['id'],
  357. 'to_mid'=>$user['id'],
  358. 'order_info_ids'=>$idss
  359. ];
  360. Db::startTrans();
  361. try {
  362. Db::name('store_order_info')->whereIn('id',$ids)->update(['mid'=>$user['id']]);
  363. Db::name('store_order_info_recycling')->insert($ins_data);
  364. Db::commit();
  365. $this->success('回收成功');
  366. }catch (\Exception $e){
  367. Db::rollback();
  368. $this->error('回收失败');
  369. }
  370. }
  371. }
  372. /**
  373. * 回收记录
  374. * @auth true
  375. * @menu true
  376. * @throws \think\Exception
  377. * @throws \think\db\exception\DataNotFoundException
  378. * @throws \think\db\exception\ModelNotFoundException
  379. * @throws \think\exception\DbException
  380. * @throws \think\exception\PDOException
  381. */
  382. public function recycling_log(){
  383. $id=$this->request->get('id');
  384. $info = Db::name('store_order_info_recycling')->where('mid',$id)->find();
  385. if (isset($info) && $info['order_info_ids']){
  386. $phone = Db::name('store_member')->where('id',$info['to_mid'])->value('phone');
  387. $list = Db::name('store_order_info')->whereIn('id',$info['order_info_ids'])->field('name')->select();
  388. foreach ($list as &$v){
  389. $v['phone'] = $phone;
  390. $v['create_at'] = $info['create_at'];
  391. }
  392. }else{
  393. $list = [];
  394. }
  395. $this->assign('list',$list);
  396. $this->fetch();
  397. }
  398. public function shoucang(){
  399. $id=$this->request->get('id');
  400. $this->title = Db::name($this->table)->where('id',$id)->value('name').'--收藏明细';
  401. $query = $this->_query('store_order_info')->where('mid',$id)->where('status','neq',2);
  402. $query->dateBetween('create_at')->order('id desc')->page();
  403. $this->fetch();
  404. }
  405. /**
  406. * 数据列表处理
  407. * @auth true
  408. * @menu true
  409. * @param array $data
  410. * @throws \think\db\exception\DataNotFoundException
  411. * @throws \think\db\exception\ModelNotFoundException
  412. * @throws \think\exception\DbException
  413. */
  414. protected function _shoucang_page_filter(&$data)
  415. {
  416. foreach ($data as $k=>&$v){
  417. $v['pro_info'] =json_decode($v['pro_info'],true);
  418. $info = Db::name('store_member')->where('id',$v['mid'])->field('name,phone')->find();
  419. $v['scz'] = $info['name'].'('.$info['phone'].')';
  420. $pro_info = Db::name('store_collection')->where('id',$v['c_id'])->field('one_given_day,other_given_day')->find();
  421. $log = Db::name('store_collect_examples_log')
  422. ->where('order_info_id',$v['id'])
  423. ->count();
  424. if (!$log){
  425. if ($pro_info['one_given_day']!=0){
  426. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['one_given_day']*24*60*60));
  427. }else{
  428. $v['exam_time'] = $v['create_at'];
  429. }
  430. }else{
  431. if ($pro_info['other_given_day']!=0){
  432. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['other_given_day']*24*60*60));
  433. }else{
  434. $v['exam_time'] = $v['create_at'];
  435. }
  436. }
  437. }
  438. }
  439. public function export(){
  440. $get_data = $this->request->get();
  441. $time = explode(' - ',$get_data['create_at']);
  442. $phone = $get_data['phone'];
  443. $name = $get_data['name'];
  444. $where = [];
  445. $where[] = ['status',1];
  446. $where[] = ['is_deleted',0];
  447. $where_str = ' status = 1 AND is_deleted = 0';
  448. if($name) $where_str .=' AND name like '."'%".$name."%'";
  449. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  450. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  451. //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die();
  452. $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');
  453. if(empty($data)) $this->error('暂无可以导出的数据');
  454. foreach ($data as $k=>&$v) {
  455. if(!$v) $v = '--';
  456. }
  457. $field=array(
  458. 'A' => array('name', '昵称'),
  459. 'B' => array('true_name', '真实姓名'),
  460. 'C' => array('phone', '联系电话'),
  461. 'D' => array('synopsis', '个人简介'),
  462. 'E' => array('create_at', '注册时间'),
  463. //'F' => array('headimg', '头像地址'),
  464. );
  465. $this->phpExcelList($field,$data,'会员列表');
  466. }
  467. public function phpExcelList($field=[],$list=[],$title='文件'){
  468. $PHPExcel=new \PHPExcel();
  469. $PHPSheet=$PHPExcel->getActiveSheet();
  470. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  471. foreach($list as $key=>$value)
  472. {
  473. foreach($field as $k=>$v){
  474. if($key == 0){
  475. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  476. }
  477. $i=$key+2;
  478. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  479. }
  480. }
  481. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  482. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  483. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  484. header('Cache-Control: max-age=0'); //禁止缓存
  485. $PHPWriter->save("php://output"); //输出到浏览器
  486. }
  487. /**
  488. * 导出EXCL
  489. * @remark 根据WHERE条件导出EXCL
  490. * @param array $post 查询条件所需值
  491. * @return array
  492. */
  493. public function get_excl()
  494. {
  495. set_time_limit(0);
  496. $name = $this->request->get('name');
  497. $phone = $this->request->get('phone');
  498. $status = $this->request->get('status');
  499. $coll_id = $this->request->get('coll_id');
  500. $create_at = $this->request->get('create_at');
  501. $model = Db::name('store_member')
  502. ->where('is_deleted',0)
  503. ->when($name,function ($query) use ($name){
  504. $query->whereLike('name','%'.$name.'%');
  505. })
  506. ->when($phone,function ($query) use ($phone){
  507. $query->whereLike('phone','%'.$phone.'%');
  508. })
  509. ->when($status,function ($query) use ($status){
  510. $query->where('status',$status);
  511. })
  512. ->when($coll_id,function ($query) use ($coll_id){
  513. $mids = Db::name('store_order_info')->where('c_id',$coll_id)->where('status','neq',2)->where('is_destruction',1)->column('mid');
  514. $query->whereIn('id',$mids);
  515. });
  516. if (isset($create_at) && $create_at){
  517. $time = explode(' - ',$_GET['create_at']);
  518. $start_date_time = $time[0].' 00:00:00';
  519. $end_date_time = $time[1].' 23:59:59';
  520. $model->whereBetweenTime('a.create_at',$start_date_time,$end_date_time);
  521. }
  522. $list =$model->field('id,name,phone')
  523. ->select();
  524. $export = [];
  525. if (is_array($list)) {
  526. foreach ($list as $index => $item) {
  527. $export[] = [
  528. $item['phone']
  529. ];
  530. }
  531. }
  532. PHPExcelService::setExcelHeader(['手机号'])
  533. ->setExcelTile('手机号导出' . date('YmdHis', time()), '手机号信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  534. ->setExcelContent($export)
  535. ->ExcelSave();
  536. }
  537. }