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

修改项目详情

@@ -211,6 +211,62 @@ class Project extends Api @@ -211,6 +211,62 @@ class Project extends Api
211 */ 211 */
212 public function detail() 212 public function detail()
213 { 213 {
  214 + $token = $this->request->header('token');
  215 + if(empty($token)){
  216 + $id = $this->request->param('id');
  217 + if(empty($id)){
  218 + $this->error('缺少必要参数');
  219 + }
  220 + $data = Db::name('project')
  221 + ->where('id',$id)
  222 + ->find();
  223 + $look_num = $data['look_num']+1;
  224 + Db::name('project')->where('id',$id)->update(['look_num'=>$look_num]);
  225 + $data['image'] = explode(',',$data['image']);
  226 + foreach ($data['image'] as &$val){
  227 + $val = 'http://q2ugvq3qf.bkt.clouddn.com'.$val;
  228 + }
  229 + $data['images'] = explode(',',$data['images']);
  230 + foreach ($data['images'] as &$v){
  231 + $v = 'http://q2ugvq3qf.bkt.clouddn.com'.$v;
  232 + }
  233 + //查出项目对应的农场名称以及农场简介
  234 + $farm = Db::name('farm')
  235 + ->alias('a')
  236 + ->join('user b','a.user_id = b.id')
  237 + ->where('a.id',$data['farm_id'])
  238 + ->field('a.id,a.name,a.content,a.province,a.city,a.address,a.user_id,b.avatar')
  239 + ->find();
  240 + $data['farm_address'] = $farm['address'];
  241 + $data['avatar'] = $farm['avatar'];
  242 + $data['farm_id'] = $farm['id'];
  243 + $data['farm_name'] = $farm['name'];
  244 + $data['farm_content'] = $farm['content'];
  245 +
  246 + //查看用户对该项目是否点过赞 默认都为未点赞
  247 + $data['is_zan'] = 1;
  248 +
  249 + //查看用户是否关注过该农场 默认都为未关注
  250 + $data['is_guan'] = 1;
  251 +
  252 + $user = Db::name('user')->where('id',$farm['user_id'])->field('identity')->find();
  253 + if($user['identity'] == 3){
  254 + $company = Db::name('company')
  255 + ->where('user_id',$farm['user_id'])
  256 + ->field('company_name,name')
  257 + ->find();
  258 + $data['nong_name'] = $company['name'];
  259 + $data['company_name'] = $company['company_name'];
  260 + }else{
  261 + $company = Db::name('personage')
  262 + ->where('user_id',$farm['user_id'])
  263 + ->field('id,name')
  264 + ->find();
  265 + $data['nong_name'] = $company['name'];
  266 + $data['company_name'] = '';
  267 + }
  268 + $this->success('success',$data);
  269 + }
214 $user_id = $this->getUserId(); 270 $user_id = $this->getUserId();
215 $id = $this->request->param('id'); 271 $id = $this->request->param('id');
216 if(empty($id)){ 272 if(empty($id)){
@@ -736,16 +792,22 @@ class Project extends Api @@ -736,16 +792,22 @@ class Project extends Api
736 $v['user_avatar'] = $user['avatar']; 792 $v['user_avatar'] = $user['avatar'];
737 $v['nickname'] = $user['nickname']; 793 $v['nickname'] = $user['nickname'];
738 $v['is_guan'] = 1; 794 $v['is_guan'] = 1;
  795 + $v['name'] = '';
  796 + $v['project_num'] = '';
  797 + $v['fun_num'] = '';
739 }else{ 798 }else{
740 //查出关注我的用户 自己的农场信息 799 //查出关注我的用户 自己的农场信息
741 $user_farm = Db::name('farm') 800 $user_farm = Db::name('farm')
742 - ->field('id,name,project_num,fun_num')  
743 - ->where('user_id',$v['user_id']) 801 + ->alias('a')
  802 + ->join('user b','a.user_id = b.id')
  803 + ->field('a.id,a.name,a.project_num,a.fun_num,b.avatar as user_avatar,b.nickname')
  804 + ->where('a.user_id',$v['user_id'])
744 ->find(); 805 ->find();
745 $v['name'] = $user_farm['name']; 806 $v['name'] = $user_farm['name'];
746 $v['project_num'] = $user_farm['project_num']; 807 $v['project_num'] = $user_farm['project_num'];
747 $v['fun_num'] = $user_farm['fun_num']; 808 $v['fun_num'] = $user_farm['fun_num'];
748 - 809 + $v['user_avatar'] = $user_farm['user_avatar'];
  810 + $v['nickname'] = $user_farm['nickname'];
749 $guanzhu = Db::name('guanzhu') 811 $guanzhu = Db::name('guanzhu')
750 ->where('user_id',$user_id) 812 ->where('user_id',$user_id)
751 ->where('farm_id',$user_farm['id']) 813 ->where('farm_id',$user_farm['id'])