Member.php 21 KB

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