Member.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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('status,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. $this->title = Db::name($this->table)->where('id',$id)->value('name').'--收藏明细';
  313. $query = $this->_query('store_order_info')->where('mid',$id)->whereIn('status','1,3');
  314. $query->dateBetween('create_at')->order('id desc')->page();
  315. $this->fetch();
  316. }
  317. /**
  318. * 数据列表处理
  319. * @auth true
  320. * @menu true
  321. * @param array $data
  322. * @throws \think\db\exception\DataNotFoundException
  323. * @throws \think\db\exception\ModelNotFoundException
  324. * @throws \think\exception\DbException
  325. */
  326. protected function _shoucang_page_filter(&$data)
  327. {
  328. foreach ($data as $k=>&$v){
  329. $v['pro_info'] =json_decode($v['pro_info'],true);
  330. $info = Db::name('store_member')->where('id',$v['mid'])->field('name,phone')->find();
  331. $v['scz'] = $info['name'].'('.$info['phone'].')';
  332. $pro_info = Db::name('store_collection')->where('id',$v['c_id'])->field('one_given_day,other_given_day')->find();
  333. $log = Db::name('store_collect_examples_log')
  334. ->where('order_info_id',$v['id'])
  335. ->count();
  336. if (!$log){
  337. if ($pro_info['one_given_day']!=0){
  338. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['one_given_day']*24*60*60));
  339. }else{
  340. $v['exam_time'] = $v['create_at'];
  341. }
  342. }else{
  343. if ($pro_info['other_given_day']!=0){
  344. $v['exam_time'] = date('Y-m-d H:i:s',strtotime($v['create_at'])+($pro_info['other_given_day']*24*60*60));
  345. }else{
  346. $v['exam_time'] = $v['create_at'];
  347. }
  348. }
  349. }
  350. }
  351. public function export(){
  352. $get_data = $this->request->get();
  353. $time = explode(' - ',$get_data['create_at']);
  354. $phone = $get_data['phone'];
  355. $name = $get_data['name'];
  356. $where = [];
  357. $where[] = ['status',1];
  358. $where[] = ['is_deleted',0];
  359. $where_str = ' status = 1 AND is_deleted = 0';
  360. if($name) $where_str .=' AND name like '."'%".$name."%'";
  361. if($phone) $where_str .=' AND phone like '."'%".$phone."%'";
  362. if($get_data['create_at']) $where_str.=" AND create_at > '".$time[0]."'AND create_at <'".$time[1]."'";
  363. //var_dump("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');die();
  364. $data = Db::query("SELECT name,headimg,true_name,phone,create_at,synopsis FROM store_member WHERE".$where_str.' ORDER BY id DESC');
  365. if(empty($data)) $this->error('暂无可以导出的数据');
  366. foreach ($data as $k=>&$v) {
  367. if(!$v) $v = '--';
  368. }
  369. $field=array(
  370. 'A' => array('name', '昵称'),
  371. 'B' => array('true_name', '真实姓名'),
  372. 'C' => array('phone', '联系电话'),
  373. 'D' => array('synopsis', '个人简介'),
  374. 'E' => array('create_at', '注册时间'),
  375. //'F' => array('headimg', '头像地址'),
  376. );
  377. $this->phpExcelList($field,$data,'会员列表');
  378. }
  379. public function phpExcelList($field=[],$list=[],$title='文件'){
  380. $PHPExcel=new \PHPExcel();
  381. $PHPSheet=$PHPExcel->getActiveSheet();
  382. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  383. foreach($list as $key=>$value)
  384. {
  385. foreach($field as $k=>$v){
  386. if($key == 0){
  387. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  388. }
  389. $i=$key+2;
  390. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  391. }
  392. }
  393. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  394. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  395. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  396. header('Cache-Control: max-age=0'); //禁止缓存
  397. $PHPWriter->save("php://output"); //输出到浏览器
  398. }
  399. public function crystal(){
  400. $this->title = '元石充值';
  401. $this->_form($this->table, 'crystal');
  402. }
  403. }