作者 潘浩文
1 个管道 的构建 失败 耗费 0 秒

测试

... ... @@ -140,4 +140,144 @@ class CoachController extends RestBaseController
$this->success("获取数据成功", ['data'=>$new_arr,'coach'=>$coach]);
}
/**
* @title 场所详情
* @description 场所详情接口
* @author Pan Haowen
* @url /home/coach/room
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @param name:room_id type:int require:1 desc:场所id
* @param name:time type:int require:0 desc:筛选课程时间戳
* @return room:场所详情
* @return class:该场所课程
*/
public function room()
{
$userId = $this->getUserId();
$param = $this->request->param();
$data['room'] = Db::name('room')->where('id', $param['room_id'])->find();
//图片处理
$data['room']['thumbnail'] = cmf_get_image_preview_url($data['room']['thumbnail']);
//距离计算
$distance=new ToolsService();
$user = Db::name('user')->where('id', $userId)->find();
$dis=$distance->distance($user['jing'],$user['wei'],$data['room']['lng'],$data['room']['lat']);
if($dis<1000){
$dis=floor($dis).'m';
}else{
$dis=round(($dis/1000),1).'km';
}
$data['room']['distance'] = $dis;
//根据时间计算课程
$where['c.delete_time'] = null;
$where['c.status']=3;
$where['p.delete_time'] = null;
$where['c.room_id'] = $param['room_id'];
if (!empty($param['time'])) {
$time1=$param['time'];
$time2=strtotime('+1 month',$param['time']);
$where['c.start_time'] = [['>= time',intval($time1) ], ['<= time',$time2]];
}
else {
$where['c.start_time'] = [['>= time', strtotime('+1 month', strtotime(date('Y-m', time())))], ['<= time', strtotime('+2 month', strtotime(date('Y-m', time())))]];
}
$data['class'] = Db::name('class')
->alias('c')
->join('product p', 'c.product_id=p.id')
->where($where)
// ->where(['c.start_time'=>[['>= time',intval($param['time'])], ['<= time',$time2]]])
->group('c.product_id')
->field('p.*,c.room_id,count(*) as count')
->select()
->each(function ($item) {
$item['thumbnail'] = cmf_get_image_preview_url($item['thumbnail']);
return $item;
});
$this->success("获取数据成功", $data);
}
/**
* @title 计划产品
* @description 计划产品
* @author Pan Haowen
* @url /home/coach/Class
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @param name:product_id type:int require:1 desc:产品id
* @param name:room_id type:int require:1 desc:场所id
* @param name:time type:int require:0 desc:筛选课程时间戳
* @return room:场所信息
* @return product:产品信息
* @return tuan:团课教程
* @return si:私课教程
*/
public function Class()
{
$userId = $this->getUserId();
$param = $this->request->param();
//场所信息
$data['room'] = Db::name('room')->where('id', $param['room_id'])->field('id,name,lat,lng,location')->find();
$distance=new ToolsService();
$user = Db::name('user')->where('id', $userId)->find();
$dis=$distance->distance($user['jing'],$user['wei'],$data['room']['lng'],$data['room']['lat']);
if($dis<1000){
$dis=floor($dis).'m';
}else{
$dis=round(($dis/1000),1).'km';
}
$data['room']['distance'] = $dis;
//产品信息
$data['product'] = Db::name('product')->where('id', $param['product_id'])->find();
$data['product']['thumbnail'] = cmf_get_image_preview_url($data['product']['thumbnail']);
//根据时间计算课程
$where['delete_time'] = null;
$where['room_id'] = $param['room_id'];
$where['product_id'] = $param['product_id'];
if (!empty($param['time'])) {
$where['start_time'] = [['>= time', intval($param['time'])], ['<= time', strtotime('+1 month', $param['time'])]];
} else {
$where['start_time'] = [['>= time', strtotime('+1 month', strtotime(date('Y-m', time())))], ['<= time', strtotime('+2 month', strtotime(date('Y-m', time())))]];
}
//团教课程
$data['tuan'] = Db::name('class')
->where($where)
->where(['type'=>1,'status'=>3])
->limit(2)
->select()
->each(function ($item) {
$item['avatar'] = Db::name('user_class_apply')->where(['class_id' => $item['id'], 'status' => 1])->limit(4)->select()->each(function ($item2) {
$user = Db::name('user')->where('id', $item2['user_id'])->find();
$item2['avatar'] = cmf_get_image_preview_url($user['avatar']);
$item2['user_name'] = $user['user_nickname'];
return $item2;
});
return $item;
});
//私教课程
$data['si'] = Db::name('class')
->where($where)
->where(['type'=>2,'status'=>3])
->limit(2)
->select()
->each(function ($item) {
$coach_id = Db::name('coach_class_apply')->where(['class_id' => $item['id'], 'status' => 1])->find()['coach_id'];
$coach = Db::name('coach')->where('id', $coach_id)->find();
$item['avatar'] = cmf_get_image_preview_url($coach['avatar']);
$item['coach_name'] = $coach['name'];
return $item;
});
$this->success("获取数据成功", $data);
}
}
... ...
... ... @@ -38,7 +38,7 @@ class CoachPlanController extends RestBaseController
->join('class c','cca.class_id=c.id')
->join('product p','c.product_id=p.id')
->join('room r','c.room_id=r.id')
->where(['c.delete_time'=>null,'c.status'=>1,'cca.coach_id'=>$coach['id']])
->where(['c.delete_time'=>null,'c.status'=>['neq',2],'cca.coach_id'=>$coach['id']])
->where($where)
->field('p.name as pname,c.*,cca.status,r.name as rname,cca.coach_id')
->select()
... ...