作者 郭盛
1 个管道 的构建 通过 耗费 1 秒

修改认证

@@ -486,12 +486,12 @@ class Attestation extends Api @@ -486,12 +486,12 @@ class Attestation extends Api
486 ->select(); 486 ->select();
487 if(empty($data)){ 487 if(empty($data)){
488 $city = Db::name('government') 488 $city = Db::name('government')
489 - ->where($where['province'])  
490 - ->where($where['city']) 489 + ->where('province','Like',"$param[province]%")
  490 + ->where('city',$param['city'])
491 ->select(); 491 ->select();
492 if(empty($city)){ 492 if(empty($city)){
493 $province = Db::name('government') 493 $province = Db::name('government')
494 - ->where($where['province']) 494 + ->where('province','Like',"$param[province]%")
495 ->select(); 495 ->select();
496 if(empty($province)){ 496 if(empty($province)){
497 $this->success('暂无机构'); 497 $this->success('暂无机构');
@@ -516,7 +516,6 @@ class Attestation extends Api @@ -516,7 +516,6 @@ class Attestation extends Api
516 } 516 }
517 $this->success('success',$res); 517 $this->success('success',$res);
518 } 518 }
519 -  
520 } 519 }
521 520
522 /** 521 /**
@@ -10,6 +10,7 @@ namespace app\api\controller; @@ -10,6 +10,7 @@ namespace app\api\controller;
10 10
11 11
12 use app\common\controller\Api; 12 use app\common\controller\Api;
  13 +use think\Db;
13 14
14 /** 15 /**
15 * 平台消息模块 16 * 平台消息模块
@@ -21,23 +22,101 @@ class Message extends Api @@ -21,23 +22,101 @@ class Message extends Api
21 * @ApiSummary (平台消息列表) 22 * @ApiSummary (平台消息列表)
22 * @ApiMethod (POST) 23 * @ApiMethod (POST)
23 * @ApiRoute (/api/message/index) 24 * @ApiRoute (/api/message/index)
  25 + *
  26 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  27 + *
24 * @ApiReturn({ 28 * @ApiReturn({
25 "code": 1, 29 "code": 1,
26 "msg": "SUCCESS", 30 "msg": "SUCCESS",
27 "time": "1553839125", 31 "time": "1553839125",
28 "data": { 32 "data": {
29 'title'://标题, 33 'title'://标题,
30 - 'url': //跳转链接地址,  
31 - 'form'://来源,  
32 - 'look_num'://浏览量,  
33 - 'thumbnail'://图片 34 + 'user_id'://用户ID
  35 + 'is_read': //是否已读(0未读1已读),
34 'content'://内容, 36 'content'://内容,
  37 + 'type'://类型(1普通2活动3奖品)
  38 + 'num'://未读消息数量
  39 + 'total'://通知数量
35 'createtime'://创建时间 40 'createtime'://创建时间
36 } 41 }
37 }) 42 })
38 */ 43 */
39 public function index() 44 public function index()
40 { 45 {
  46 + $user_id = $this->getUserId();
  47 + $data['list'] = Db::name('message')
  48 + ->where('user_id',$user_id)
  49 + ->whereOr('user_id','null')
  50 + ->order('is_read desc,createtime desc')
  51 + ->select();
  52 + $data['num'] = Db::name('message')
  53 + ->where('is_read',0)
  54 + ->where(function ($query)use($user_id){
  55 + $query->where('user_id',$user_id)
  56 + ->whereOr('user_id','null');
  57 + })
  58 + ->order('is_read desc,createtime desc')
  59 + ->count();
  60 + $data['total'] = Db::name('message')
  61 + ->where('user_id',$user_id)
  62 + ->whereOr('user_id','null')
  63 + ->order('is_read desc,createtime desc')
  64 + ->count();
  65 + $this->success('success',$data);
  66 + }
41 67
  68 + /**
  69 + * @ApiTitle (平台消息详情)
  70 + * @ApiSummary (平台消息详情)
  71 + * @ApiMethod (POST)
  72 + * @ApiRoute (/api/message/detail)
  73 + *
  74 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  75 + * @ApiParams (name="id", type="int", required=false, description="平台消息ID")
  76 + *
  77 + * @ApiReturn({
  78 + "code": 1,
  79 + "msg": "SUCCESS",
  80 + "time": "1553839125",
  81 + "data": {
  82 + 'title'://标题,
  83 + 'user_id'://用户ID
  84 + 'is_read': //是否已读(0未读1已读),
  85 + 'content'://内容,
  86 + 'type'://类型(1普通2活动3奖品)
  87 + 'createtime'://创建时间
  88 + }
  89 + })
  90 + */
  91 + public function detail()
  92 + {
  93 + $user_id = $this->getUserId();
  94 + $id = $this->request->param('id');
  95 + if(empty($id)){
  96 + $this->error('缺少必要参数');
  97 + }
  98 +
  99 + //判断该消息是否为平台通知
  100 + $info = Db::name('message')->where('id',$id)->find();
  101 + if($info['user_id'] == ''){
  102 + //是
  103 + $read['user_id'] = $user_id;
  104 + $read['message_id'] = $id;
  105 + $read['createtime'] = time();
  106 + Db::name('read')->insertGetId($read);
  107 + $data = Db::name('message')
  108 + ->where('id',$id)
  109 + ->find();
  110 + Db::name('message')->where('id',$id)->update(['is_read'=>1]);
  111 + $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
  112 + }else{
  113 + //不是
  114 + $data = Db::name('message')
  115 + ->where('id',$id)
  116 + ->find();
  117 + Db::name('message')->where('id',$id)->update(['is_read'=>1]);
  118 + $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
  119 + }
  120 + $this->success('success',$data);
42 } 121 }
43 } 122 }