Member.php 21 KB

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