作者 开飞机的舒克

修改逻辑

@@ -5,6 +5,7 @@ namespace app\api\controller; @@ -5,6 +5,7 @@ namespace app\api\controller;
5 use app\common\controller\Api; 5 use app\common\controller\Api;
6 use app\common\model\Active; 6 use app\common\model\Active;
7 use app\common\model\Item; 7 use app\common\model\Item;
  8 +use app\common\model\Ronda;
8 9
9 /** 10 /**
10 * 活动接口 11 * 活动接口
@@ -121,15 +122,14 @@ class Activity extends Api @@ -121,15 +122,14 @@ class Activity extends Api
121 if (empty($cid)) { 122 if (empty($cid)) {
122 $this->error('参数错误', ['status' => 2]); 123 $this->error('参数错误', ['status' => 2]);
123 } 124 }
124 - $data = db('ronda r')  
125 - ->join('campus c','c.id = r.campus_id')  
126 - ->field('r.id as rid,c.title as campus_title,r.title as ronda_title,r.holdtime as ronda_holdtime')  
127 - ->where('r.campus_id',$cid)  
128 - ->paginate(10,false)  
129 - ->each(function ($item,$key){  
130 - $item['holdtime'] = date('Y-m-d',$item['ronda_holdtime']);  
131 - return $item;  
132 - }); 125 + $data = db('ronda')
  126 + ->where('campus_id',$cid)
  127 + ->select();
  128 + foreach ($data as $k => $v){
  129 + $data[$k]['holdtime'] = date('Y-m-d',$v['holdtime']);
  130 + $data[$k]['images'] = cdnurl($v['images'],true);
  131 + $data[$k]['details'] = strip_tags($v['details']);
  132 + }
133 $this->success('获取场次列表成功', $data); 133 $this->success('获取场次列表成功', $data);
134 } 134 }
135 135
@@ -156,8 +156,12 @@ class Activity extends Api @@ -156,8 +156,12 @@ class Activity extends Api
156 if (empty($rid)) { 156 if (empty($rid)) {
157 $this->error('参数错误', ['status' => 2]); 157 $this->error('参数错误', ['status' => 2]);
158 } 158 }
159 - $model = new Item();  
160 - $data = collection($model->whereIn('ronda_ids',$rid)->select())->toArray(); 159 + $model = new Ronda();
  160 + $list = $model->where('id',$rid)->value('item_ids');
  161 + $item = explode(',',$list);
  162 + foreach ($item as $k){
  163 + $data[] = db('item')->where('id',$k)->find();
  164 + }
161 $this->success('获取项目列表成功', $data); 165 $this->success('获取项目列表成功', $data);
162 } 166 }
163 167
@@ -216,8 +220,6 @@ class Activity extends Api @@ -216,8 +220,6 @@ class Activity extends Api
216 $where['id'] = $id; 220 $where['id'] = $id;
217 $model = new Item(); 221 $model = new Item();
218 $data = $model->where($where)->find(); 222 $data = $model->where($where)->find();
219 -  
220 - //$data['holdtime'] = date('Y-m-d',$data['holdtime']);  
221 $data['details'] = strip_tags($data['details']); 223 $data['details'] = strip_tags($data['details']);
222 $this->success('获取项目详情成功', $data); 224 $this->success('获取项目详情成功', $data);
223 } 225 }
@@ -20,6 +20,8 @@ class Item extends Model @@ -20,6 +20,8 @@ class Item extends Model
20 'radar_text', 20 'radar_text',
21 ]; 21 ];
22 22
  23 +
  24 +
23 public function getImagesAttr($value,$data){ 25 public function getImagesAttr($value,$data){
24 $images = explode(',',$data['images']); 26 $images = explode(',',$data['images']);
25 foreach ($images as $k){ 27 foreach ($images as $k){
  1 +<?php
  2 +
  3 +namespace app\common\model;
  4 +
  5 +use think\Model;
  6 +
  7 +class Ronda extends Model
  8 +{
  9 + // 表名
  10 + protected $name = 'ronda';
  11 + // 自动写入时间戳字段
  12 + protected $autoWriteTimestamp = 'int';
  13 + // 定义时间戳字段名
  14 + protected $createTime = 'createtime';
  15 + protected $updateTime = 'updatetime';
  16 + // 追加属性
  17 + protected $append = [
  18 + ];
  19 +
  20 +}