123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- /**
- * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
- * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
- * @author pillar<ltmn@qq.com>
- * 同城号
- */
- namespace app\citys\controller;
- use app\citys\controller\Common;
- use app\citys\model\CitysMp;
- use app\common\model\SystemUser;
- use think\facade\Validate;
- use think\facade\Request;
- use think\helper\Time;
- class Mp extends Common{
- public function initialize() {
- parent::initialize();
- $this->assign('pathMaps',[['name'=>'城市号','url'=>url("citys/mp/index")]]);
- }
- /**
- * 列表
- */
- public function index(int $types = 0,int $vip = 0){
- $condition = [];
- $time = Request::param('time/d',0);
- $starttime = Request::param('starttime/s');
- $endtime = Request::param('endtime/s');
- if($time){
- switch ($time) {
- case 2:
- list($start, $end) = Time::yesterday();
- break;
- case 30:
- list($start, $end) = Time::month();
- break;
- case 60:
- list($start, $end) = Time::lastMonth();
- break;
- default:
- list($start, $end) = Time::today();
- break;
- }
- $condition[] = ['reg_time','>=',$start];
- $condition[] = ['reg_time','<=',$end];
- }else{
- if($starttime){
- $condition[] = ['reg_time','>=',strtotime($starttime)];
- }
- if($endtime){
- $condition[] = ['reg_time','<=',strtotime($endtime)];
- }
- }
- $view['num'] = CitysMp::where($this->mini_program)->where($condition)->count();
- $view['vip_num'] = CitysMp::where($this->mini_program)->where($condition)->where(['is_vip' => 1])->count();
- $view['notvip_num'] = CitysMp::where($this->mini_program)->where($condition)->where(['is_vip' => 0])->count();
- $condition[] = ['is_lock','=',$types];
- $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]]);
- $view['types'] = $types;
- $view['lists'] = $lists;
- $view['time'] = $time;
- $view['starttime'] = $starttime;
- $view['endtime'] = $endtime;
- return view()->assign($view);
- }
- //规格编辑
- public function edit(){
- if(request()->isAjax()){
- $data = [
- 'member_miniapp_id' => $this->member_miniapp_id,
- 'id' => $this->request->param('id/d',0),
- 'uid' => $this->request->param('uid/d'),
- 'logo' => $this->request->param('logo/s'),
- 'title' => $this->request->param('title/s'),
- 'note' => $this->request->param('note/s'),
- 'is_vip' => $this->request->param('is_vip/d',0),
- 'vip_title' => $this->request->param('vip_title/s'),
- 'vip_about' => $this->request->param('vip_about/s'),
- 'vip_time' => $this->request->param('vip_time/s'),
- ];
- $validate = $this->validate($data,$data['is_vip'] ? 'Info.mpVip':'Info.mpEdit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- $result = CitysMp::edit($data);
- if(empty($result)){
- return enjson(403,'操作失败');
- }
- return enjson(200,'操作成功',['url'=>url('citys/mp/index')]);
- }else{
- $view['info'] = CitysMp::where($this->mini_program)->where(['id' => $this->request->param('id/d',0)])->find();
- return view()->assign($view);
- }
- }
-
- /**
- * 预览信息
- * @return void
- */
- public function review(){
- $view['info'] = CitysMp::where($this->mini_program)->where(['id' => $this->request->param('id/d',0)])->find();
-
- return view()->assign($view);
- }
- /**
- * 选择所属用户
- */
- public function selectUid(){
- $keyword = Request::param('keyword');
- $input = Request::param('input');
- $condition = [];
- if(!empty($keyword)){
- if(Validate::isMobile($keyword)){
- $condition[] = ['phone_uid','=',$keyword];
- }else{
- $condition[] = ['nickname','like','%'.$keyword.'%'];
- }
- }
- $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]]);
- $view['keyword'] = $keyword;
- $view['input'] = $input;
- $view['id'] = $this->member_miniapp_id;
- return view()->assign($view);
- }
- /**
- * 认证
- */
- public function vip(int $id){
- $result = CitysMp::where($this->mini_program)->where(['id' => $id])->field('is_vip')->find();
- if(!$result){
- return enjson(0);
- }else{
- $result->is_vip = $result->is_vip ? 0: 1;
- $result->save();
- return enjson(200);
- }
- }
- /**
- * 锁定
- */
- public function lock(int $id){
- $result = CitysMp::where($this->mini_program)->where(['id' => $id])->field('is_lock')->find();
- if(!$result){
- return enjson(0);
- }else{
- $result->is_lock = $result->is_lock ? 0: 1;
- $result->save();
- return enjson(200);
- }
- }
- }
|