getPage(); if($this->userInfo['admin_id']==0){ $query = Contract::where("type",2)->where('party_b',$this->userId); } else { $query = Contract::where("type",1)->where('party_a|party_b',$this->userInfo['company_id']); } $query->where('status',1); $count = $query->count(); $contract = $query->with(['party_a_info','party_b_info','contract_type'])->page($page)->limit($limit)->select(); return $this->success('success', ['count' => $count, 'data' => $contract]); } public function view($id) { $contract = Contract::find($id); if (empty($contract)) { return $this->fail('合同不存在'); } if ($contract['type'] == 2) { $contract['party_b_name'] = User::where('id', $contract['party_b'])->value('nickname'); } else { $contract['party_b_name'] = Db::name('company')->where('id', $contract['party_b'])->value('company_name'); } $contract['party_a_name'] = Db::name('company')->where('id', $contract['party_a'])->value('company_name'); $contract['contract_type_name'] = Db::name('dict_data')->where('id', $contract['contract_type'])->value('name'); $company = Company::where('id', $contract['party_a'])->find()->toArray(); $province_name= Db::name('geo_province')->where(['province_code' => $company['province']])->value('province_name'); $city_name= Db::name('geo_city')->where(['city_code' => $company['city']])->value('city_name'); $area_name= Db::name('geo_area')->where(['area_code' => $company['area']])->value('area_name'); $street_name= Db::name('geo_street')->where(['street_code' => $company['street']])->value('street_name'); $village_name= Db::name('geo_village')->where(['village_code' => $company['village']])->value('village_name'); $brigade_name= Db::name('geo_brigade')->where(['id' => $company['brigade']])->value('brigade_name'); $company['province_name']=$province_name; $company['city_name']=$city_name; $company['area_name']=$area_name; $company['street_name']=$street_name; $company['village_name']=$village_name; $company['brigade_name']=$brigade_name; $company['address']= $province_name.$city_name.$area_name.$street_name.$village_name.$brigade_name.$company['address']; $company['company_type_name'] = Db::name('dict_data')->where('id', $company['company_type'])->value('name'); $company['other_contacts'] = json_decode($company['other_contacts'], true); $company['qualification'] = $company['qualification'] != null ? json_decode($company['qualification'], true) : ''; // $users = Admin::where('id', $company['party_a'])->field('id,name,account,phone,qualification')->select()->toArray(); // foreach ($users as &$user) { // $user['is_main'] = $user['id'] == $company['admin_id'] ? 1 : 0; // $user['qualification'] = $user['qualification'] != null ? json_decode($user['qualification'], true) : []; // unset($user['role_id'], $user['dept_id'], $user['jobs_id'], $user['id']); // } return $this->success('success', ['contract' => $contract, 'company' => $company]); } }