From 3249387341e76b474215768efaf5d1bb01c3d6eb Mon Sep 17 00:00:00 2001 From: weiz Date: Mon, 6 Nov 2023 16:19:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E5=90=88=E5=90=8C=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contract/ContractController.php | 28 ++ .../contract/VehicleContractController.php | 1 - app/adminapi/lists/contract/ContractLists.php | 110 ++++++ app/api/logic/SmsLogic.php | 26 ++ app/common/controller/JunziqianController.php | 12 +- app/common/logic/company/CompanyLogic.php | 8 + app/common/logic/contract/ContractLogic.php | 371 ++++++++++++++++++ app/common/logic/user/WorkerUserLogic.php | 8 + app/common/model/WorkerAdmin/WorkerAdmin.php | 11 + app/common/model/contract/Contract.php | 36 ++ app/common/model/dict/WorkerDictData.php | 24 ++ app/common/model/user/WorkerUser.php | 11 + 12 files changed, 639 insertions(+), 7 deletions(-) create mode 100644 app/adminapi/controller/contract/ContractController.php create mode 100644 app/adminapi/lists/contract/ContractLists.php create mode 100644 app/common/logic/company/CompanyLogic.php create mode 100644 app/common/logic/contract/ContractLogic.php create mode 100644 app/common/logic/user/WorkerUserLogic.php create mode 100644 app/common/model/WorkerAdmin/WorkerAdmin.php create mode 100644 app/common/model/dict/WorkerDictData.php create mode 100644 app/common/model/user/WorkerUser.php diff --git a/app/adminapi/controller/contract/ContractController.php b/app/adminapi/controller/contract/ContractController.php new file mode 100644 index 00000000..950557aa --- /dev/null +++ b/app/adminapi/controller/contract/ContractController.php @@ -0,0 +1,28 @@ +dataLists(new ContractLists()); + } + + public function detail() + { + $params = $this->request->get(['id']); + $result = ContractLogic::detail($params); + return $this->data($result); + } + + } diff --git a/app/adminapi/controller/contract/VehicleContractController.php b/app/adminapi/controller/contract/VehicleContractController.php index d1672daa..bd284ae4 100644 --- a/app/adminapi/controller/contract/VehicleContractController.php +++ b/app/adminapi/controller/contract/VehicleContractController.php @@ -6,7 +6,6 @@ use app\common\enum\notice\NoticeEnum; use app\common\model\contract\VehicleContract; use app\common\model\vehicle\VehicleRent; - use think\facade\Log; use think\response\Json; class VehicleContractController extends BaseAdminController diff --git a/app/adminapi/lists/contract/ContractLists.php b/app/adminapi/lists/contract/ContractLists.php new file mode 100644 index 00000000..62c28425 --- /dev/null +++ b/app/adminapi/lists/contract/ContractLists.php @@ -0,0 +1,110 @@ + ['contract_type', 'contract_no', 'status'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/07/18 14:28 + */ + public function lists(): array + { + $params=$this->request->param(); + $where=[]; + if(isset($params['company_id']) && $params['company_id']!=''){ + $arr= Company::where('company_name','like','%'.$params['company_id'].'%')->column('id'); + if($arr){ + $where[]=['party_a|party_b','in',$arr]; + } + } + if(isset($params['area_manager']) && $params['area_manager']!=''){ + $arr= WorkerAdmin::where('name','like','%'.$params['area_manager'].'%')->column('id'); + if($arr){ + $where[]=['area_manager','in',$arr]; + } + } + return Contract::where($this->searchWhere)->where($where)->with(['companyName','party_a_info','contractType']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item, $key) { + if($item->type==1){ + $item->party_b_name=Db::connect('mysql2')->name('la_company')->where('id',$item->party_b)->value('company_name'); + }else{ + $item->party_b_name=Db::connect('mysql2')->name('la_user')->where('id',$item->party_b)->value('nickname'); + } + if(!empty($item->party_a_info)){ + $area_manager_name=Db::connect('mysql2')->name('la_admin')->where('id',$item->party_a_info->area_manager)->value('name'); + if($area_manager_name){ + $item->area_manager_name=$area_manager_name; + }else{ + $item->area_manager_name='暂无片区经理'; + } + }else{ + $item->area_manager_name='暂无片区经理'; + } + $item->contract_type_name=Db::connect('mysql2')->name('la_dict_data')->where('id',$item->contract_type)->value('name'); + $item->status_name=$item->status==1?'已签约':'未签约'; + }) + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/07/18 14:28 + */ + public function count(): int + { + return Contract::where($this->searchWhere)->count(); + } + + } \ No newline at end of file diff --git a/app/api/logic/SmsLogic.php b/app/api/logic/SmsLogic.php index fa6b6670..c8a580a8 100644 --- a/app/api/logic/SmsLogic.php +++ b/app/api/logic/SmsLogic.php @@ -56,5 +56,31 @@ class SmsLogic extends BaseLogic return false; } } + + public static function contractUrl($params) + { + try { + $scene = NoticeEnum::getSceneByTag($params['scene']); + if (empty($scene)) { + throw new \Exception('场景值异常'); + } + + $result = event('Notice', [ + 'scene_id' => $scene, + 'params' => [ + 'mobile' => $params['mobile'], + 'name' => $params['name'], + 'type' => $params['type'], + 'code' => $params['code'] + ] + ]); + + return $result[0]; + + } catch (\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } } \ No newline at end of file diff --git a/app/common/controller/JunziqianController.php b/app/common/controller/JunziqianController.php index f196aab3..064ce2d0 100644 --- a/app/common/controller/JunziqianController.php +++ b/app/common/controller/JunziqianController.php @@ -357,7 +357,7 @@ class JunziqianController extends BaseLikeAdminController public function download_file($applyNo) { $requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret); - $find = Db::name('contract')->where('contract_no', $applyNo)->value('contract_url'); + $find = Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->value('contract_url'); if ($find) { return $this->success('获取成功', ['url' => env('url.url_prefix') . $find]); } @@ -368,7 +368,7 @@ class JunziqianController extends BaseLikeAdminController $response = $requestUtils->doPost("/v2/sign/linkFile", $request); if ($response->success == true) { $this->getDownload($response->data, root_path() . 'public/uploads/contract/' . $applyNo . '.pdf'); - Db::name('contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']); + Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']); return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/contract/' . $applyNo . '.pdf']); } else { return $this->fail('获取失败'); @@ -377,7 +377,7 @@ class JunziqianController extends BaseLikeAdminController public function download_shop_file($applyNo) { $requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret); - $find = Db::name('contract')->where('contract_no', $applyNo)->value('contract_url'); + $find = Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->value('contract_url'); if ($find) { return $this->success('获取成功', ['url' => env('url.url_prefix') . $find]); } @@ -388,7 +388,7 @@ class JunziqianController extends BaseLikeAdminController $response = $requestUtils->doPost("/v2/sign/linkFile", $request); if ($response->success == true) { $this->getDownload($response->data, root_path() . 'public/uploads/contract/' . $applyNo . '.pdf'); - Db::name('shop_contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']); + Db::connect('mysql2')->name('la_shop_contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']); return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/contract/' . $applyNo . '.pdf']); } else { return $this->fail('获取失败'); @@ -412,7 +412,7 @@ class JunziqianController extends BaseLikeAdminController $response = $requestUtils->doPost("/v2/sign/presLinkFile", $request); if ($response->success == true) { $this->getDownload($response->data, root_path() . 'public/uploads/evidence/' . $param['applyNo'] . '.zip'); - Db::name('contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence/' . $param['applyNo'] . '.zip']); + Db::connect('mysql2')->name('la_contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence/' . $param['applyNo'] . '.zip']); return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/evidence/' . $param['applyNo'] . '.zip']); } else { return $this->fail('获取失败'); @@ -437,7 +437,7 @@ class JunziqianController extends BaseLikeAdminController $response = $requestUtils->doPost("/v2/sign/presLinkFile", $request); if ($response->success == true) { $this->getDownload($response->data, root_path() . 'public/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip'); - Db::name('shop_contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip']); + Db::connect('mysql2')->name('la_shop_contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip']); return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip']); } else { return $this->fail('获取失败'); diff --git a/app/common/logic/company/CompanyLogic.php b/app/common/logic/company/CompanyLogic.php new file mode 100644 index 00000000..5859afbd --- /dev/null +++ b/app/common/logic/company/CompanyLogic.php @@ -0,0 +1,8 @@ + $params['company_id'], + 'contract_type' => $params['contract_type'], + 'contract_no' => $params['contract_no'], + 'file' => $params['file'], + 'status' => $params['status'], + 'party_a' => $params['party_a'], + 'party_b' => $params['party_b'], + 'area_manager' => $params['area_manager'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/07/18 14:28 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Contract::where('id', $params['id'])->update([ + 'company_id' => $params['company_id'], + 'contract_type' => $params['contract_type'], + 'contract_no' => $params['contract_no'], + 'file' => $params['file'], + 'status' => $params['status'], + 'party_a' => $params['party_a'], + 'party_b' => $params['party_b'], + 'area_manager' => $params['area_manager'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/07/18 14:28 + */ + public static function delete(array $params): bool + { + return Contract::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/07/18 14:28 + */ + public static function detail($params) + { + $data = Db::connect('mysql2')->name('la_contract')->where('id', $params['id']) + ->withAttr('party_b_info', function ($value, $data) { + if ($data['type'] == 1) { + $field = ['id,company_name,company_type,company_type company_type_name,organization_code, + province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,master_phone,master_name, + qualification']; + $company = Company::where(['id' => $data['party_b']])->field($field)->find(); + if(empty($company)){ + return []; + }else{ + $company=$company->toArray(); + } + $company['qualification'] = json_decode($company['qualification'], true); + if($company['qualification'] && isset($company['qualification']['other_qualifications'])){ + $company['qualification']['other_qualifications']=json_decode($company['qualification']['other_qualifications'],true); + } + return $company; + } else { + $filed = ['id,id_card,avatar,nickname,sex,mobile, + province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,nickname master_name, + qualification']; + $user = WorkerUser::where('id', $data['party_b'])->field($filed)->find(); + if(empty($user)){ + return []; + }else{ + $user=$user->toArray(); + } + $user['qualification'] = json_decode($user['qualification'], true); + if($user['qualification'] && isset($user['qualification']['other_qualifications'])){ + $user['qualification']['other_qualifications']=json_decode($user['qualification']['other_qualifications'],true); + } + return $user; + } + }) + ->withAttr('party_a_info', function ($value, $data) { + $field = ['id,company_name,company_type,company_type company_type_name,organization_code, + province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,master_phone,master_name, + qualification']; + $company = Company::where(['id' => $data['party_a']])->field($field)->find()->toArray(); + $company['qualification'] = json_decode($company['qualification'], true); + if($company['qualification'] && isset($company['qualification']['other_qualifications'])){ + $company['qualification']['other_qualifications']=json_decode($company['qualification']['other_qualifications'],true); + } + return $company; + }) + ->withAttr('area_manager_name', function ($value, $data) { + return Db::connect('mysql2')->name('la_admin')->where('id', $data['area_manager'])->value('name'); + }) + ->withAttr('contract_type_name', function ($value, $data) { + return Db::connect('mysql2')->name('la_dict_data')->where('id', $data['contract_type'])->value('name'); + }) + ->withAttr('type_name', function ($value, $data) { + return $data['type'] == 1 ? '公司' : '个人'; + }) + ->withAttr('status_name', function ($value, $data) { + return $data['status'] == 1 ? '已签约' : '未签约'; + }) + ->find(); + $data['signed_contract_url'] = self::getSignedContract($data); + return $data; + } + + /** + * 获取已签约盖章的合同 + */ + public static function getSignedContract($contract) + { + $signedContractUrl = ''; + if($contract['status'] == 1){ + if ($contract['contract_url'] == '') { + $res = app(JunziqianController::class)->download_file($contract['contract_no'])->getData(); + if ($res['code'] == 1) { + $signedContractUrl = $res['data']['url']; + } + }else { + $signedContractUrl = env('url.url_prefix').$contract['contract_url']; + } + } + return $signedContractUrl; + } + + //生成合同 + public static function Initiate_contract($data) + { + // 平台公司可以直接签合同,其他类型的公司需要做过合同乙方才能签合同 + $partyACompamyInfo = Company::where(['id'=>$data['party_a']])->find(); + if ($partyACompamyInfo['company_type'] != 30) { + $partyAModel = Contract::where(['party_b' => $data['party_a']])->find(); + if (empty($partyAModel)) { + return self::setError('当前甲方暂无和平台或上级公司签约,请先进行签约'); + } + } + $model = Contract::where(['party_b' => $data['party_b'],'contract_type'=>$data['contract_type']])->find(); + if (empty($model)) { + $model = new Contract(); + $model->contract_no = time(); + $model->create_time = time(); + } + if($data['party_a']<=0){ + return self::setError('甲方不能为空'); + } + if($data['party_b']<=0){ + return self::setError('乙方不能为空'); + } + if($data['type']==1){ + if($data['party_a'] == $data['party_b']){ + return self::setError('甲方和乙方不能是同一个公司'); + } + } + try { + $model->check_status = 1; + $model->update_time = time(); + $model->setAttrs($data); + $res = $model->save($data); + if($res){ + return ['code'=>1,'msg'=>'发起成功,等待平台风控部上传合同','data'=>['id'=>$model->id]]; + }else{ + return ['code'=>0,'msg'=>'发起失败,请稍后重试',]; + } + }catch(\Exception $e){ + return ['code'=>0,'msg'=>$e->getMessage()]; + } + + } + + /**发送合同 + * @type 1公司 2个人 + */ + public static function Draftingcontracts($params,$type=1) + { + if($type==1){ + $result = CompanyLogic::detail($params); + }else{ + $result = WorkerUserLogic::detail($params['id']); + } + $result['contract']= Contract::where('id',$params['contract_id'])->with(['party_a_info', 'contractType'])->find(); + if ($result && isset($result['contract']) && isset($result['contract']['file']) && $result['contract']['file'] != '') { + if ($result['contract']['check_status'] == 3) { + return self::setError('你已经生成过合同,请勿重复生成'); + } + if($type==1){ + $name=$result['company_name']; + $data = [ + 'name' => $name . '的合同', + 'signatories' => [ + ['fullName' => $name, 'identityType' => 12, 'identityCard' => $result['organization_code'], 'email' => $result['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1], // 'authLevel'=>[11], 签约时验证人脸识别 + ['fullName' => $result['contract']['party_a_info']['company_name'], 'identityType' => 12, 'identityCard' => $result['contract']['party_a_info']['organization_code'], 'email' => $result['contract']['party_a_info']['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1] + ], + 'url' => $result['contract']['file'], + ]; + }else{ + $name=$result['nickname']; + $data = [ + 'name' => $name . '的合同', + 'signatories' => [ + ['fullName' => $name, 'identityType' => 1, 'identityCard' => $result['id_card'], 'mobile' => $result['mobile'], 'noNeedVerify' => 1, 'signLevel' => 1], + ['fullName' => $result['contract']['party_a_info']['company_name'], 'identityType' => 12, 'identityCard' => $result['contract']['party_a_info']['organization_code'], 'email' => $result['contract']['party_a_info']['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1] + ], + 'url' => $result['contract']['file'] + ]; + } + $res = app(JunziqianController::class)->Signing($data, $result['contract']['id']); + if ($res->success == true) { + Db::connect('mysql2')->name('la_contract')->where('id', $result['contract']['id'])->update(['contract_no' => $res->data, 'check_status' => 3]); + self::postsms(['id'=>$result['contract']['id']]); + return true; + } else { + return self::setError($res->msg); + } + } else { + return self::setError('生成合同成功失败,联系管理员'); + } + } + + //**发送短信 */ + public static function postsms($params) + { + $result = self::detail($params); + Log::info(['发送合同短信', $result]); + if ($result && $result['file'] != '') { + //发送短信 + $data = [ + [ + "applyNo" => $result['contract_no'], //TODO * + "fullName" => $result['party_a_info']['company_name'], //TODO * + "identityCard" => $result['party_a_info']['organization_code'], //TODO * + "identityType" => 12, //TODO * + "master_phone" => $result['party_a_info']['master_phone'], + "type"=>"party_a" + ], + ]; + if($result['type']==1){ + $data[]= [ + "applyNo" => $result['contract_no'], //TODO * + "fullName" => $result['party_b_info']['company_name'], //TODO * + "identityCard" => $result['party_b_info']['organization_code'], //TODO * + "identityType" => 12, //TODO * + "master_phone" => $result['party_b_info']['master_phone'], + "type"=>"party_b" + + ]; + }else{ + $data[]= [ + "applyNo" => $result['contract_no'], //TODO * + "fullName" => $result['party_b_info']['nickname'], //TODO * + "identityCard" => $result['party_b_info']['id_card'], //TODO * + "identityType" => 1, //TODO * + "master_phone" => $result['party_b_info']['mobile'], + "type"=>"party_b" + + ]; + } + $find = Db::connect('mysql2')->name('la_contract')->where('id', $params['id']) + ->withAttr('contract_type_name', function ($value, $data) { + return Db::connect('mysql2')->name('la_dict_data')->where('id', $data['contract_type'])->value('name'); + })->find(); + + $url = []; + foreach ($data as $k => $v) { + $res = app(JunziqianController::class)->SigningLink($v); + if ($res->success == true) { + if ($v['type'] == 'party_a') { + $url['party_a'] =$res->data; + } else { + $url['party_b'] =$res->data; + } + //发送短信 + $sms = [ + 'mobile' => $v['master_phone'], + 'name' => $v['fullName'], + 'type' => '《' . $find['contract_type_name'] . '》', + 'code' => 'api/Hetong/url?id=' . $find['id'].'&type='.$v['type'], + 'scene' => 'WQ' + ]; + Log::info(['发送合同短信-消息体', $sms]); + $result = SmsLogic::contractUrl($sms); + if ($result != true) { + return self::setError(SmsLogic::getError()); + } + } else { + return self::setError($res->msg); + } + } + Db::connect('mysql2')->name('la_contract')->where('id', $find['id'])->update(['url' => json_encode($url)]); + return true; + }else{ + return self::setError('没找到合同,联系管理员'); + } + } + } diff --git a/app/common/logic/user/WorkerUserLogic.php b/app/common/logic/user/WorkerUserLogic.php new file mode 100644 index 00000000..5ccfd8f8 --- /dev/null +++ b/app/common/logic/user/WorkerUserLogic.php @@ -0,0 +1,8 @@ +hasOne(Company::class, 'id', 'company_id')->bind(['company_name']); + } + public function company(): \think\model\relation\HasOne + { + return $this->hasOne(Company::class, 'id', 'company_id'); + } + public function partyAInfo(): \think\model\relation\HasOne + { + return $this->hasOne(Company::class, 'id', 'party_a')->field('id,company_name,organization_code,master_name,master_phone,master_email,area_manager'); + } + public function partyBInfo(): \think\model\relation\HasOne + { + return $this->hasOne(Company::class, 'id', 'party_b')->field('id,company_name,organization_code,master_name,master_phone,master_email,area_manager'); + } + public function partyA(): \think\model\relation\HasOne + { + return $this->hasOne(Company::class, 'id', 'party_a')->bind(['party_a_name' => 'company_name']); + } + public function partyB(): \think\model\relation\HasOne + { + return $this->hasOne(Company::class, 'id', 'party_b')->bind(['party_b_name' => 'company_name']); + } + public function contractType(): \think\model\relation\HasOne + { + return $this->hasOne(WorkerDictData::class, 'id', 'contract_type')->bind(['contract_type_name' => 'name']); + } + + public function getContractTypeNameAttr($value) + { + return WorkerDictData::where(['id' => $this->contract_type])->value('name'); + } } \ No newline at end of file diff --git a/app/common/model/dict/WorkerDictData.php b/app/common/model/dict/WorkerDictData.php new file mode 100644 index 00000000..69e03755 --- /dev/null +++ b/app/common/model/dict/WorkerDictData.php @@ -0,0 +1,24 @@ + 'town_task_type', 'status' => 1])->column('value', 'id'); + if(isset($townTaskTypeList[$typeId])) { + return $townTaskTypeList[$typeId]; + } + return ''; + } + } \ No newline at end of file diff --git a/app/common/model/user/WorkerUser.php b/app/common/model/user/WorkerUser.php new file mode 100644 index 00000000..78583611 --- /dev/null +++ b/app/common/model/user/WorkerUser.php @@ -0,0 +1,11 @@ + Date: Mon, 6 Nov 2023 16:51:31 +0800 Subject: [PATCH 2/2] update --- .../contract/ContractController.php | 76 ++++++++++++++++++- .../contract/VehicleContractController.php | 2 +- ...ongController.php => HetongController.php} | 2 +- app/api/controller/IndexController.php | 1 - 4 files changed, 76 insertions(+), 5 deletions(-) rename app/api/controller/{HeTongController.php => HetongController.php} (98%) diff --git a/app/adminapi/controller/contract/ContractController.php b/app/adminapi/controller/contract/ContractController.php index 950557aa..2d3bb766 100644 --- a/app/adminapi/controller/contract/ContractController.php +++ b/app/adminapi/controller/contract/ContractController.php @@ -3,7 +3,12 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\contract\ContractLists; + use app\api\logic\SmsLogic; use app\common\logic\contract\ContractLogic; + use app\common\model\company\Company; + use app\common\model\contract\Contract; + use app\common\model\user\WorkerUser; + use think\facade\Db; /** * 合同控制器 @@ -13,16 +18,83 @@ class ContractController extends BaseAdminController { - public function lists() + public function lists(): \think\response\Json { return $this->dataLists(new ContractLists()); } - public function detail() + public function detail(): \think\response\Json { $params = $this->request->get(['id']); $result = ContractLogic::detail($params); return $this->data($result); } + public function wind_control(): \think\response\Json + { + $params = $this->request->param(); + $file = $params['file']; + $res = Contract::where('id', $params['id'])->update(['file' => $file, 'check_status' => 2]); + if ($res) { + $find = Contract::where('id', $params['id'])->with(['party_a_info'])->field('type,party_b,party_a') + ->find()->toArray(); + if ($find['type'] == 1) { + $find['party_b_info'] = Company::where('id', $find['party_b'])->field('company_name name,master_phone phone')->find()->toArray(); + } else { + $find['party_b_info'] = WorkerUser::where('id', $find['party_b'])->field('nickname name,mobile phone')->find()->toArray(); + } + $a = [ + 'mobile' => $find['party_a_info']['master_phone'], + 'name' => $find['party_a_info']['company_name'], + 'scene' => 'WQTZ' + ]; + SmsLogic::contractUrl($a); + $b = [ + 'mobile' => $find['party_b_info']['phone'], + 'name' => $find['party_b_info']['name'], + 'scene' => 'WQTZ' + ]; + SmsLogic::contractUrl($b); + return $this->success('上传成功', [], 1, 1); + } else { + if ($res == 0) { + return $this->success('没有更新', [], 1, 1); + } + return $this->fail('上传失败'); + } + } + + public function postsms() + { + $params = $this->request->param(); + $find = Db::connect('mysql2')->name('la_contract')->where('id', $params['id']) + ->withAttr('contract_type_name', function ($value, $data) { + return Db::connect('mysql2')->name('la_dict_data')->where('id', $data['contract_type'])->value('name'); + }) + ->withAttr('user_info', function ($value, $data) { + if ($data['type'] == 1) { + return Db::connect('mysql2')->name('la_admin')->where('id', $data['party_b'])->field('name,phone')->find(); + } else { + return Db::connect('mysql2')->name('la_user')->where('id', $data['party_b'])->field('nickname name,mobile phone')->find(); + } + }) + ->find(); + if ($find && $find['url'] != '') { + //发送短信 + $sms = [ + 'mobile' => $find['user_info']['phone'], + 'name' => $find['user_info']['name'], + 'type' => '《' . $find['contract_type_name'] . '》', + 'code' => 'api/Hetong/url?id=' . $find['id'], + 'scene' => 'WQ' + ]; + $result = SmsLogic::contractUrl($sms); + if (true === $result) { + return $this->success('发送成功'); + } else { + return $this->fail(SmsLogic::getError()); + } + } + } + } diff --git a/app/adminapi/controller/contract/VehicleContractController.php b/app/adminapi/controller/contract/VehicleContractController.php index bd284ae4..b11d0a85 100644 --- a/app/adminapi/controller/contract/VehicleContractController.php +++ b/app/adminapi/controller/contract/VehicleContractController.php @@ -192,7 +192,7 @@ 'mobile' => $v['master_phone'], 'name' => $v['fullName'], 'type' => $title, - 'code' => 'api/HeTong/info?id='.$id.'&type='.$v['type'], + 'code' => 'api/Hetong/info?id='.$id.'&type='.$v['type'], 'scene' => 'WQ' ]; $scene = NoticeEnum::getSceneByTag($sms['scene']); diff --git a/app/api/controller/HeTongController.php b/app/api/controller/HetongController.php similarity index 98% rename from app/api/controller/HeTongController.php rename to app/api/controller/HetongController.php index 638bd2ee..392ad6fe 100644 --- a/app/api/controller/HeTongController.php +++ b/app/api/controller/HetongController.php @@ -8,7 +8,7 @@ use think\facade\Db; use think\facade\Log; - class HeTongController extends BaseLikeAdminController + class HetongController extends BaseLikeAdminController { public array $notNeedLogin = ['url','info', 'toFaceCreate', 'notifyOrganizationFaceCreate']; diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 7003d5ef..1fd36a8f 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -3,7 +3,6 @@ namespace app\api\controller; use app\common\enum\notice\NoticeEnum; -use app\common\model\user\User; use think\facade\Log; use think\response\Json;