Member.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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 library\Controller;
  16. use think\Db;
  17. use function GuzzleHttp\Psr7\build_query;
  18. /**
  19. * 会员信息管理
  20. * Class Member
  21. * @package app\user\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')->equal('vip,group,is_open_official_DDC');
  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. $v['group_name'] = Db::name('store_member_group')->where('id',$v['group'])->value('name');
  59. $v['invite_count'] = Db::name($this->table)->where('pid',$v['id'])->count();
  60. }
  61. $this->group_list = Db::name('store_member_group')->select();
  62. $this->group_list = array_merge([['id'=>'','name'=>'全部会员']],$this->group_list);
  63. }
  64. //删除货主
  65. public function remove()
  66. {
  67. $this->_save($this->table, ['is_deleted' => '1']);
  68. }
  69. //禁用货主
  70. public function forbid()
  71. {
  72. $this->_save($this->table, ['status' => '0']);
  73. }
  74. //启用货主
  75. public function resume()
  76. {
  77. $this->_save($this->table, ['status' => '1']);
  78. }
  79. /**
  80. * 编辑抢购卡
  81. * @auth true
  82. * @menu true
  83. * @throws \think\Exception
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @throws \think\exception\DbException
  87. * @throws \think\exception\PDOException
  88. */
  89. public function snap_card(){
  90. $this->title = '抢购卡';
  91. $this->_form($this->table, 'snap_card');
  92. }
  93. /**
  94. * 编辑积分
  95. * @auth true
  96. * @menu true
  97. * @throws \think\Exception
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @throws \think\exception\DbException
  101. * @throws \think\exception\PDOException
  102. */
  103. public function integral(){
  104. $this->title = '积分变更';
  105. $this->_form($this->table, 'integral');
  106. }
  107. /**
  108. * 编辑转赠次数
  109. * @auth true
  110. * @menu true
  111. * @throws \think\Exception
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. * @throws \think\exception\DbException
  115. * @throws \think\exception\PDOException
  116. */
  117. public function examples_number(){
  118. $this->title = '转赠次数';
  119. $this->_form($this->table, 'examples_number');
  120. }
  121. /**
  122. * 编辑vip
  123. * @auth true
  124. * @menu true
  125. * @throws \think\Exception
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. * @throws \think\exception\PDOException
  130. */
  131. public function vip(){
  132. $this->title = 'vip';
  133. $this->_form($this->table, 'vip');
  134. }
  135. /**
  136. * 编辑详情
  137. * @auth true
  138. * @menu true
  139. * @throws \think\Exception
  140. * @throws \think\db\exception\DataNotFoundException
  141. * @throws \think\db\exception\ModelNotFoundException
  142. * @throws \think\exception\DbException
  143. * @throws \think\exception\PDOException
  144. */
  145. public function info(){
  146. $this->title = '详情';
  147. $this->_form($this->table, 'info');
  148. }
  149. /**
  150. * 编辑分组
  151. * @auth true
  152. * @menu true
  153. * @throws \think\Exception
  154. * @throws \think\db\exception\DataNotFoundException
  155. * @throws \think\db\exception\ModelNotFoundException
  156. * @throws \think\exception\DbException
  157. * @throws \think\exception\PDOException
  158. */
  159. public function save_group(){
  160. $this->title = '编辑分组';
  161. $this->group_list = Db::name('store_member_group')->select();
  162. $this->_form($this->table, 'save_group');
  163. }
  164. /**
  165. * 一键抢购卡
  166. * @auth true
  167. * @menu true
  168. * @throws \think\Exception
  169. * @throws \think\db\exception\DataNotFoundException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. * @throws \think\exception\DbException
  172. * @throws \think\exception\PDOException
  173. */
  174. public function snap_cards(){
  175. $this->title = '抢购卡';
  176. $this->group_list = Db::name('store_member_group')->select();
  177. $this->_form($this->table, 'snap_cards');
  178. }
  179. /**
  180. * 一键分组
  181. * @auth true
  182. * @menu true
  183. * @throws \think\Exception
  184. * @throws \think\db\exception\DataNotFoundException
  185. * @throws \think\db\exception\ModelNotFoundException
  186. * @throws \think\exception\DbException
  187. * @throws \think\exception\PDOException
  188. */
  189. public function grouping(){
  190. $this->title = '分组';
  191. $list = Db::name('store_member')
  192. ->where('is_deleted',0)
  193. ->where('group',0)
  194. ->field('id,name,phone')
  195. ->select();
  196. $group_list = Db::name('store_member_group')->select();
  197. $this->assign('list',$list);
  198. $this->assign('group_list',$group_list);
  199. $this->_form($this->table, 'grouping');
  200. }
  201. protected function _form_filter(&$data){
  202. if($this->request->isPost() && $this->request->action() == 'snap_card')
  203. {
  204. if($data['id']) {
  205. if($data['int_type'] == 4) {
  206. $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',1);
  207. }else{
  208. $result = memberMoneyChange($data['snap_card'],2,$data['id'],'后台人工调整',0);
  209. }
  210. if ($result){
  211. setMembercard($data['id']);
  212. setMemberInfoHash($data['id']);
  213. $this->success('调整成功');
  214. }
  215. }
  216. }
  217. if($this->request->isPost() && $this->request->action() == 'snap_cards')
  218. {
  219. if (!isset($data['group']) || $data['group']==''){
  220. $this->error('请选择分组');
  221. }
  222. $user = Db::name('store_member')->where('is_deleted',0)->where('group',$data['group'])->select();
  223. foreach ($user as &$v){
  224. $result = memberMoneyChange($data['snap_card'],2,$v['id'],'后台人工调整',1);
  225. if ($result){
  226. setMembercard($v['id']);
  227. setMemberInfoHash($v['id']);
  228. }
  229. }
  230. $this->success('调整成功');
  231. }
  232. if($this->request->isPost() && $this->request->action() == 'integral')
  233. {
  234. if($data['id']) {
  235. if($data['int_type'] == 4) {
  236. $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',1);
  237. }else{
  238. $result = memberMoneyChange($data['integral'],1,$data['id'],'后台人工调整',0);
  239. }
  240. if ($result){
  241. setMemberInfoHash($data['id']);
  242. $this->success('调整成功');
  243. }
  244. }
  245. }
  246. if($this->request->isPost() && $this->request->action() == 'examples_number')
  247. {
  248. if($data['id']) {
  249. if (Db::name('store_member')->where('id',$data['id'])->update(['examples_number'=>$data['examples_number'],'update_at'=>date('Y-m-d H:i:s')])){
  250. setMemberInfoHash($data['id']);
  251. $this->success('调整成功');
  252. }
  253. }
  254. }
  255. if($this->request->isPost() && $this->request->action() == 'vip')
  256. {
  257. if($data['id']) {
  258. if (Db::name('store_member')->where('id',$data['id'])->update(['vip'=>$data['vip'],'update_at'=>date('Y-m-d H:i:s')])){
  259. setMemberInfoHash($data['id']);
  260. $this->success('调整成功');
  261. }
  262. }
  263. }
  264. if($this->request->isPost() && $this->request->action() == 'info')
  265. {
  266. if($data['id']) {
  267. if ($data['password']!=''){
  268. $date['password'] = md5($data['password']);
  269. }
  270. if ($data['second_password']!=''){
  271. $date['second_password'] = md5($data['second_password']);
  272. }
  273. $date['update_at'] = date('Y-m-d H:i:s');
  274. if (Db::name('store_member')->where('id',$data['id'])->update($date)){
  275. setMemberInfoHash($data['id']);
  276. $this->success('编辑成功');
  277. }
  278. $this->error('编辑失败');
  279. }
  280. }
  281. if($this->request->isPost() && $this->request->action() == 'save_group')
  282. {
  283. if($data['id']) {
  284. if (!isset($data['group']) || $data['group']==''){
  285. $this->error('请选择分组');
  286. }
  287. $date['group'] = $data['group'];
  288. $date['update_at'] = date('Y-m-d H:i:s');
  289. if (Db::name('store_member')->where('id',$data['id'])->update($date)){
  290. setMemberInfoHash($data['id']);
  291. $this->success('编辑成功');
  292. }
  293. $this->error('编辑失败');
  294. }
  295. }
  296. if($this->request->isPost() && $this->request->action() == 'grouping')
  297. {
  298. if (!isset($data['group']) || $data['group']==''){
  299. $this->error('请选择分组');
  300. }
  301. if (!isset($data['users']) || $data['users']==''){
  302. $this->error('请选择用户');
  303. }
  304. if (Db::name('store_member')->whereIn('id',$data['users'])->update(['group'=>$data['group']])){
  305. $this->success('分组成功',url('/#/user/member/index'));
  306. }
  307. $this->error('分组失败',url('/#/user/member/index'));
  308. }
  309. }
  310. public function shoucang(){
  311. $id=$this->request->get('id');
  312. $hash_send=$this->request->get('hash_send');
  313. $this->title = Db::name($this->table)->where('id',$id)->value('name').'--收藏明细';
  314. $query = $this->_query('store_order_info')
  315. ->where('mid',$id)->whereIn('status','1,3');
  316. if ($hash_send){
  317. if ($hash_send==1){
  318. $query->where('collectors_hash','neq','');
  319. }else if ($hash_send==2){
  320. $query->where('collectors_hash','eq','');
  321. }
  322. }
  323. $query->dateBetween('create_at')->order('id desc')->page();
  324. $this->fetch();
  325. }
  326. /**
  327. * 数据列表处理
  328. * @auth true
  329. * @menu true
  330. * @param array $data
  331. * @throws \think\db\exception\DataNotFoundException
  332. * @throws \think\db\exception\ModelNotFoundException
  333. * @throws \think\exception\DbException
  334. */
  335. protected function _shoucang_page_filter(&$data)
  336. {
  337. foreach ($data as $k=>&$v){
  338. $v['pro_info'] =json_decode($v['pro_info'],true);
  339. $info = Db::name('store_member')->where('id',$v['mid'])->field('name,phone')->find();
  340. $v['scz'] = $info['name'].'('.$info['phone'].')';
  341. $pro_info = Db::name('store_collection')->where('id',$v['c_id'])->field('one_given_day,other_given_day')->find();
  342. $log = Db::name('store_collect_examples_log')
  343. ->where('order_info_id',$v['id'])
  344. ->count();
  345. if (!$log){
  346. if ($pro_info['one_given_day']!=0){
  347. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['one_given_day']*24*60*60));
  348. }else{
  349. $v['exam_time'] = $v['create_at'];
  350. }
  351. }else{
  352. if ($pro_info['other_given_day']!=0){
  353. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['other_given_day']*24*60*60));
  354. }else{
  355. $v['exam_time'] = $v['create_at'];
  356. }
  357. }
  358. }
  359. }
  360. public function export(){
  361. $get_data = $this->request->get();
  362. $time = explode(' - ',$get_data['create_at']);
  363. $phone = $get_data['phone'];
  364. $name = $get_data['name'];
  365. $where = [];
  366. $where[] = ['status',1];
  367. $where[] = ['is_deleted',0];
  368. $where_str = ' status = 1 AND is_deleted = 0';
  369. if($name) $where_str .=' AND name like '."'%".$name."%'";
  370. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  371. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  372. //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die();
  373. $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');
  374. if(empty($data)) $this->error('暂无可以导出的数据');
  375. foreach ($data as $k=>&$v) {
  376. if(!$v) $v = '--';
  377. }
  378. $field=array(
  379. 'A' => array('name', '昵称'),
  380. 'B' => array('true_name', '真实姓名'),
  381. 'C' => array('phone', '联系电话'),
  382. 'D' => array('synopsis', '个人简介'),
  383. 'E' => array('create_at', '注册时间'),
  384. //'F' => array('headimg', '头像地址'),
  385. );
  386. $this->phpExcelList($field,$data,'会员列表');
  387. }
  388. public function phpExcelList($field=[],$list=[],$title='文件'){
  389. $PHPExcel=new \PHPExcel();
  390. $PHPSheet=$PHPExcel->getActiveSheet();
  391. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  392. foreach($list as $key=>$value)
  393. {
  394. foreach($field as $k=>$v){
  395. if($key == 0){
  396. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  397. }
  398. $i=$key+2;
  399. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  400. }
  401. }
  402. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  403. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  404. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  405. header('Cache-Control: max-age=0'); //禁止缓存
  406. $PHPWriter->save("php://output"); //输出到浏览器
  407. }
  408. public function crystal(){
  409. $this->title = '元石充值';
  410. $this->_form($this->table, 'crystal');
  411. }
  412. }