column('title','id'); $bidingList = $this->where($where)->field('id,title,status,desc,is_urgent,tag_ids,create_time')->order('sort desc')->paginate($limit??5)->toArray(); if($bidingList['data']){ foreach ($bidingList['data'] as $key=>$value){ if (strstr($value['tag_ids'],',')){ $tagTitle = []; foreach (explode(',',$value['tag_ids']) as $v){ if(isset($tagList[$v]) && !empty($tagList[$v])){ $tagTitle[$v] = $tagList[$v]; } } $bidingList['data'][$key]['tagTitle'] = implode(',',$tagTitle); }else{ $bidingList['data'][$key]['tagTitle'] = isset($tagList[$value['tag_ids']]) ? $tagList[$value['tag_ids']] :''; } } } return $bidingList; } /** * @param $id * @param $member_id * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Deng * @date 2020-12-22 11:41 * 获取招标详情 */ public function getBindingDetails($id){ $member_id = request()->middleware('token.member_id'); $data = $this->where('id',$id)->find()->hidden(['update_time','delete_time','sort','desc'])->toArray(); //处理类型 $data['tagTitle'] = Tag::where('id',$data['tag_ids'])->value('title'); //处理投标文件 if($data['file']){ $resource = Db::name('resource')->whereIn('id',$data['file'])->find(); $data['file_download'] = [ 'title' => $resource['tag'], 'path' => $resource['path'], 'download_url' => ''.url('index/download',['path'=>$resource['path'],'tag'=>$resource['tag']]).'' ]; }else{ $data['file_download'] = []; } //处理关注 if($member_id != 0){ $collect = Collect::where(['member_id'=>$member_id,'bidding_id'=>$id,'delete_time'=>0])->find(); $data['is_collect'] = !empty($collect) ? 1 : 0 ; }else{ $data['is_collect'] = 0; } //如果已经中标 if($data['status']>0){ $tender = Tender::alias('t')->leftJoin('member m','m.id=t.member_id') ->where(['t.delete_time'=>0,'t.bidding_id'=>$data['id'],'t.status'=>1])->field('t.tender_price,m.username,m.mobile,m.company') ->findOrempty()->toArray(); $data['tender'] = !empty($tender) ? $tender : []; } unset($data['tag_ids']); return $data; } public static function get_ip(){ if ( getenv( "HTTP_CLIENT_IP" ) && strcasecmp( getenv( "HTTP_CLIENT_IP" ), "unknown" ) ){ $ip = getenv( "HTTP_CLIENT_IP" ); }else if ( getenv( "HTTP_X_FORWARDED_FOR" ) && strcasecmp( getenv( "HTTP_X_FORWARDED_FOR" ), "unknown" ) ){ $ip = getenv( "HTTP_X_FORWARDED_FOR" ); }else if (getenv( "REMOTE_ADDR" ) && strcasecmp( getenv( "REMOTE_ADDR" ), "unknown" ) ){ $ip = getenv( "REMOTE_ADDR" ); }else if ( isset( $_SERVER[ 'REMOTE_ADDR' ] ) && $_SERVER[ 'REMOTE_ADDR' ] && strcasecmp( $_SERVER[ 'REMOTE_ADDR' ], "unknown" ) ){ $ip = $_SERVER[ 'REMOTE_ADDR' ]; }else{ $ip = "unknown"; } if ( strpos( $ip, ',' ) ){ $ipArr = explode( ',', $ip ); $ip = $ipArr[ 0 ]; } $url = 'http://api.ip138.com/query/?ip='.$ip.'&datatype=json'; $header = array('token:c93c0e60cb73b931a0f0e0e2b88dd7e3'); error_reporting(E_ALL || ~E_NOTICE); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); if (1 == strpos("$" . $url, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $out_put = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); list($header, $body) = explode("\r\n\r\n", $out_put, 2); if ($httpCode == 200) { return $body; } else { if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) { print("参数错误"); } elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) { print("AppCode错误"); } elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) { print("请求的 Method、Path 或者环境错误"); } elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) { print("服务未被授权(或URL和Path不正确)"); } elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) { print("套餐包次数用完"); } elseif ($httpCode == 500) { print("API网关错误"); } elseif ($httpCode == 0) { print("URL错误"); } else { print("参数名错误 或 其他错误"); print($httpCode); $headers = explode("\r\n", $header); $headList = array(); foreach ($headers as $head) { $value = explode(':', $head); $headList[$value[0]] = $value[1]; } print($headList['x-ca-error-message']); } } } }