124 lines
5.1 KiB
PHP
Executable File
124 lines
5.1 KiB
PHP
Executable File
<?php
|
|
namespace app\api\logic;
|
|
use app\common\enum\coach\CoachEnum;
|
|
use app\common\enum\PayEnum;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\coach\Coach;
|
|
use app\common\model\coach\CoachLifePhoto;
|
|
use app\common\model\coach\Collect;
|
|
use app\common\model\goods\Goods;
|
|
use app\common\model\goods\GoodsComment;
|
|
use app\common\model\order\Order;
|
|
use app\common\model\shop\Shop;
|
|
use app\common\model\skill\Skill;
|
|
use app\common\service\FileService;
|
|
|
|
class CoachLogic extends BaseLogic
|
|
{
|
|
|
|
/**
|
|
* @notes 技能列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @author cjhao
|
|
* @date 2024/9/4 17:00
|
|
*/
|
|
public function skillLists()
|
|
{
|
|
$lists = Skill::where(['is_show'=>1])
|
|
->field('id,name')
|
|
->select()
|
|
->toArray();
|
|
array_unshift($lists,['id'=>0,'name'=>'全部']);
|
|
|
|
return $lists;
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 师傅详情
|
|
* @param $params
|
|
* @return array|void
|
|
* @author cjhao
|
|
* @date 2024/9/4 17:23
|
|
*/
|
|
public function detail($params)
|
|
{
|
|
$id = $params['id'] ?? '';
|
|
$cityId = $params['city_id'] ?? '';
|
|
$longitude = $params['longitude'] ?? '';
|
|
$latitude = $params['latitude'] ?? '';
|
|
if(empty($id) && empty($cityId)){
|
|
return [];
|
|
}
|
|
$field = 'id,skill_id,gender,age,shop_id,education,nation,work_status,work_photo,name,0 as distance,introduction,id_card,order_num,good_comment,certification,health_certificate';
|
|
if($latitude && $longitude){
|
|
$field = 'id,skill_id,gender,age,shop_id,education,nation,work_status,work_photo,name,round(st_distance_sphere(point('.$longitude.','.$latitude.'),
|
|
point(longitude,latitude))/1000,2) as distance,introduction,id_card,order_num,good_comment,certification,health_certificate';
|
|
}
|
|
|
|
$detail = Coach::where(['id'=>$id,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS])
|
|
->append(['distance_desc'])
|
|
->field($field)
|
|
->findOrEmpty()
|
|
->toArray();
|
|
$lifePhoto = CoachLifePhoto::where(['coach_id'=>$id])->field('uri')->select()->toArray();
|
|
array_unshift($lifePhoto,['uri'=>$detail['work_photo']]);
|
|
$detail['life_photo'] = array_column($lifePhoto,'uri');
|
|
$detail['shop_name'] = '';
|
|
$detail['shop'] = [];
|
|
if($detail['shop_id']){
|
|
$field = 'id,name,good_comment,logo,work_status,0 as distance';
|
|
if($latitude && $longitude){
|
|
$field = 'id,name,good_comment,logo,work_status,round(st_distance_sphere(point('.$longitude.','.$latitude.'),point(longitude, latitude))/1000,2) as distance';
|
|
}
|
|
$detail['shop'] = Shop::where(['id'=>$detail['shop_id']])
|
|
->field($field)
|
|
->findOrEmpty();
|
|
$consumption = Order::where(['pay_status'=>PayEnum::ISPAID])
|
|
->where('shop_id','=',$detail['shop_id'])
|
|
->value('round(sum(order_amount)/count(id),2) as consumption');
|
|
$detail['shop']['consumption'] = $consumption;
|
|
}
|
|
$detail['id_card'] = substr_replace($detail['id_card'], '***************', 3);
|
|
|
|
$detail['skill_name'] = Skill::where(['id'=>$detail['skill_id']])->value('name');
|
|
$detail['first_appoint'] = \app\common\logic\CoachLogic::getLatelyLeisureTime($detail['id']);
|
|
$detail['comment_num'] = GoodsComment::where(['coach_id'=>$id])->count();
|
|
$detail['good_comment'] = $detail['good_comment'].'%';
|
|
$allCityGoodsIds = Goods::alias('G')
|
|
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
|
->where(['GCI.id '=>null,'status'=>1])
|
|
->column('G.id') ?: [];
|
|
$cityGoodsIds = Goods::alias('G')
|
|
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
|
->where(['status'=>1,'city_id'=>$cityId])
|
|
->column('G.id') ?: [];
|
|
$detail['goods_lists'] = Goods::alias('G')
|
|
->join('coach_goods_index GCI','G.id = GCI.goods_id')
|
|
->where(['GCI.coach_id'=>$id])
|
|
->where(['G.id'=>array_merge($allCityGoodsIds,$cityGoodsIds)])
|
|
->field('G.id,name,image,price,scribing_price,duration,order_num')
|
|
->limit(8)
|
|
->select()->toArray();
|
|
//评论列表
|
|
$detail['comment_lists'] = GoodsComment::alias('GC')
|
|
->join('user U','GC.user_id = U.id')
|
|
->where(['coach_id'=>$params['id']])
|
|
->field('GC.id,U.nickname,U.avatar,comment,service_comment,reply,GC.create_time')
|
|
->append(['goods_comment_image'])
|
|
->limit(8)
|
|
->select()
|
|
->toArray();
|
|
foreach ($detail['comment_lists'] as $key => $commentLists){
|
|
$detail['comment_lists'][$key]['avatar'] = FileService::getFileUrl($commentLists['avatar']);
|
|
}
|
|
$detail['is_collect'] = Collect::where(['relation_id'=>$params['id'],'user_id'=>$params['user_id'],'type'=>1])->findOrEmpty()->toArray() ? 1 : 0;
|
|
return $detail;
|
|
}
|
|
|
|
|
|
|
|
} |