Mp.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 同城号
  7. */
  8. namespace app\citys\controller;
  9. use app\citys\controller\Common;
  10. use app\citys\model\CitysMp;
  11. use app\common\model\SystemUser;
  12. use think\facade\Validate;
  13. use think\facade\Request;
  14. use think\helper\Time;
  15. class Mp extends Common{
  16. public function initialize() {
  17. parent::initialize();
  18. $this->assign('pathMaps',[['name'=>'城市号','url'=>url("citys/mp/index")]]);
  19. }
  20. /**
  21. * 列表
  22. */
  23. public function index(int $types = 0,int $vip = 0){
  24. $condition = [];
  25. $time = Request::param('time/d',0);
  26. $starttime = Request::param('starttime/s');
  27. $endtime = Request::param('endtime/s');
  28. if($time){
  29. switch ($time) {
  30. case 2:
  31. list($start, $end) = Time::yesterday();
  32. break;
  33. case 30:
  34. list($start, $end) = Time::month();
  35. break;
  36. case 60:
  37. list($start, $end) = Time::lastMonth();
  38. break;
  39. default:
  40. list($start, $end) = Time::today();
  41. break;
  42. }
  43. $condition[] = ['reg_time','>=',$start];
  44. $condition[] = ['reg_time','<=',$end];
  45. }else{
  46. if($starttime){
  47. $condition[] = ['reg_time','>=',strtotime($starttime)];
  48. }
  49. if($endtime){
  50. $condition[] = ['reg_time','<=',strtotime($endtime)];
  51. }
  52. }
  53. $view['num'] = CitysMp::where($this->mini_program)->where($condition)->count();
  54. $view['vip_num'] = CitysMp::where($this->mini_program)->where($condition)->where(['is_vip' => 1])->count();
  55. $view['notvip_num'] = CitysMp::where($this->mini_program)->where($condition)->where(['is_vip' => 0])->count();
  56. $condition[] = ['is_lock','=',$types];
  57. $lists = CitysMp::where($this->mini_program)->where($condition)->where(['is_vip' => $vip])->order('id desc')->paginate(20,false,['query' => ['vip'=>$vip,'types' => $types,'starttime' => $starttime,'endtime' => $endtime,'time'=>$time]]);
  58. $view['types'] = $types;
  59. $view['lists'] = $lists;
  60. $view['time'] = $time;
  61. $view['starttime'] = $starttime;
  62. $view['endtime'] = $endtime;
  63. return view()->assign($view);
  64. }
  65. //规格编辑
  66. public function edit(){
  67. if(request()->isAjax()){
  68. $data = [
  69. 'member_miniapp_id' => $this->member_miniapp_id,
  70. 'id' => $this->request->param('id/d',0),
  71. 'uid' => $this->request->param('uid/d'),
  72. 'logo' => $this->request->param('logo/s'),
  73. 'title' => $this->request->param('title/s'),
  74. 'note' => $this->request->param('note/s'),
  75. 'is_vip' => $this->request->param('is_vip/d',0),
  76. 'vip_title' => $this->request->param('vip_title/s'),
  77. 'vip_about' => $this->request->param('vip_about/s'),
  78. 'vip_time' => $this->request->param('vip_time/s'),
  79. ];
  80. $validate = $this->validate($data,$data['is_vip'] ? 'Info.mpVip':'Info.mpEdit');
  81. if(true !== $validate){
  82. return json(['code'=>0,'msg'=>$validate]);
  83. }
  84. $result = CitysMp::edit($data);
  85. if(empty($result)){
  86. return enjson(403,'操作失败');
  87. }
  88. return enjson(200,'操作成功',['url'=>url('citys/mp/index')]);
  89. }else{
  90. $view['info'] = CitysMp::where($this->mini_program)->where(['id' => $this->request->param('id/d',0)])->find();
  91. return view()->assign($view);
  92. }
  93. }
  94. /**
  95. * 预览信息
  96. * @return void
  97. */
  98. public function review(){
  99. $view['info'] = CitysMp::where($this->mini_program)->where(['id' => $this->request->param('id/d',0)])->find();
  100. return view()->assign($view);
  101. }
  102. /**
  103. * 选择所属用户
  104. */
  105. public function selectUid(){
  106. $keyword = Request::param('keyword');
  107. $input = Request::param('input');
  108. $condition = [];
  109. if(!empty($keyword)){
  110. if(Validate::isMobile($keyword)){
  111. $condition[] = ['phone_uid','=',$keyword];
  112. }else{
  113. $condition[] = ['nickname','like','%'.$keyword.'%'];
  114. }
  115. }
  116. $view['list'] = SystemUser::where($this->mini_program)->where($condition)->whereNotIn('id',CitysMp::where($this->mini_program)->column('uid'))->order('id desc')->paginate(10,false,['query' => ['input' => $input,'keyword' => $keyword]]);
  117. $view['keyword'] = $keyword;
  118. $view['input'] = $input;
  119. $view['id'] = $this->member_miniapp_id;
  120. return view()->assign($view);
  121. }
  122. /**
  123. * 认证
  124. */
  125. public function vip(int $id){
  126. $result = CitysMp::where($this->mini_program)->where(['id' => $id])->field('is_vip')->find();
  127. if(!$result){
  128. return enjson(0);
  129. }else{
  130. $result->is_vip = $result->is_vip ? 0: 1;
  131. $result->save();
  132. return enjson(200);
  133. }
  134. }
  135. /**
  136. * 锁定
  137. */
  138. public function lock(int $id){
  139. $result = CitysMp::where($this->mini_program)->where(['id' => $id])->field('is_lock')->find();
  140. if(!$result){
  141. return enjson(0);
  142. }else{
  143. $result->is_lock = $result->is_lock ? 0: 1;
  144. $result->save();
  145. return enjson(200);
  146. }
  147. }
  148. }