作者 开飞机的舒克

项目详情优化

... ... @@ -3,6 +3,7 @@
namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\Item;
use app\common\model\ItemDetails;
/**
... ... @@ -199,17 +200,12 @@ class Activity extends Api
{
$rid = $this->request->param('rid');
$id = $this->request->param('id');
$data = db('item i')
->join('ronda r','i.ronda_id = r.id')
->join('campus c','c.id = r.campus_id')
->field('c.title as campus_title,r.title as ronda_title,r.holdtime,i.details,i.images')
->where([
'i.ronda_id'=>$rid,
'i.id'=> $id,
])
->find();
$where['ronda_ids'] = ['in',$rid];
$where['id'] = $id;
$model = new Item();
$data = $model->where($where)->find();
$data['holdtime'] = date('Y-m-d',$data['holdtime']);
//$data['holdtime'] = date('Y-m-d',$data['holdtime']);
$data['details'] = strip_tags($data['details']);
$this->success('获取项目详情成功', $data);
}
... ...
<?php
namespace app\common\model;
use think\Model;
class Item extends Model
{
// 表名
protected $name = 'item';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'campus_text',
'ronda_text',
'radar_text',
];
public function getImagesAttr($value,$data){
$images = explode(',',$data['images']);
foreach ($images as $k){
$list[] = cdnurl($k,true);
}
return $list;
}
public function getCampusTextAttr($value,$data){
$campus = explode(',',$data['campus_ids']);
$title = [];
foreach ($campus as $k){
$title[] = db('campus')->where('id',$k)->value('title');
}
//$value = implode(',',$title);
return $title;
}
public function getRondaTextAttr($value,$data){
$ronda = explode(',',$data['ronda_ids']);
$title = [];
foreach ($ronda as $k){
$title[] = db('ronda')->where('id',$k)->value('title');
}
//$value = implode(',',$title);
return $title;
}
public function getRadarTextAttr($value,$data){
$radar = explode(',',$data['radar_ids']);
$title = [];
foreach ($radar as $k){
$title[] = db('radar')->where('id',$k)->value('title');
}
//$value = implode(',',$title);
return $title;
}
}
\ No newline at end of file
... ...
... ... @@ -6197,7 +6197,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2023-04-12 14:01:08 <a href="./" target="_blank">校园活动</a>
Generated on 2023-04-12 15:32:47 <a href="./" target="_blank">校园活动</a>
</div>
</div>
... ...