From b9333d51ba9421c64270997b6aac61296d78a014 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Wed, 13 Sep 2023 15:54:15 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=95=86=E5=9F=8E=E5=95=86=E6=88=B7?= =?UTF-8?q?=E5=85=A5=E9=A9=BB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/controller/CompanyController.php | 54 +++++++++++++- app/api/controller/IndexController.php | 74 ++++++++++++++----- app/api/controller/JunziqianController.php | 24 ++++++ app/common/model/ShopMerchant.php | 8 ++ app/common/model/contract/ShopContract.php | 10 +++ 5 files changed, 151 insertions(+), 19 deletions(-) create mode 100644 app/common/model/ShopMerchant.php create mode 100644 app/common/model/contract/ShopContract.php diff --git a/app/adminapi/controller/CompanyController.php b/app/adminapi/controller/CompanyController.php index 05c164478..5969c5a08 100644 --- a/app/adminapi/controller/CompanyController.php +++ b/app/adminapi/controller/CompanyController.php @@ -24,7 +24,9 @@ use app\api\controller\JunziqianController; use app\common\logic\RedisLogic; use app\common\model\auth\Admin; use app\common\model\Company; +use app\common\model\ShopMerchant; use think\cache\driver\Redis; +use think\Exception; use think\facade\Db; use app\common\logic\contract\ContractLogic; use app\common\model\contract\Contract; @@ -39,8 +41,7 @@ use think\facade\Log; */ class CompanyController extends BaseAdminController { - - + public array $notNeedLogin = ['createShopMerchant']; /** * @notes 获取列表 * @return \think\response\Json @@ -357,4 +358,53 @@ class CompanyController extends BaseAdminController } return $this->success('success', array_unique($data)); } + public function createShopMerchant() + { + try { + $params = $this->request->param(); + if (empty($params['company_name'])) { + throw new Exception('商户名称不能为空'); + } + if (empty($params['organization_code'])) { + throw new Exception('社会统一信用代码不能为空'); + } + if (empty($params['master_name'])) { + throw new Exception('商户法人名称不能为空'); + } + $data = [ + 'mer_intention_id' => $params['mer_intention_id'], // 商城商户入驻申请id,签约完成后回调使用 + 'company_name' => $params['company_name'], + 'organization_code' => $params['organization_code'], + 'city' => $params['city'], + 'area' => $params['area'], + 'street' => $params['street'], + 'master_name' => $params['master_name'], + 'master_phone' => $params['master_phone'], + 'master_email' => substr(md5(uniqid()),rand(0, 22),10)."@lihai.com", + 'face_create_status' => 1 + ]; + + $shopMerchantModel = ShopMerchant::create($data); + + if (!$shopMerchantModel->isEmpty()) { + // 自动发起企业认证 + $shopMerchantCertificationData = [ + 'name' => $shopMerchantModel->company_name, + 'organization_code' => $shopMerchantModel->organization_code, + 'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png', + 'master_name' => $shopMerchantModel->master_name, + 'master_email' => $shopMerchantModel->master_email, + 'master_phone' => $shopMerchantModel->master_phone, + 'id' => $shopMerchantModel->id, + ]; + app(JunziqianController::class)->ShopMerchantCertification($shopMerchantCertificationData); + } else { + throw new Exception('商户创建失败'); + } + return $this->success('成功', [], 1, 1); + } catch (Exception $exception) { + return $this->fail($exception->getMessage()); + } + + } } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 659d174a4..99bddf445 100755 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -17,11 +17,15 @@ use app\api\logic\IndexLogic; use app\common\logic\RedisLogic; use app\common\model\Company; use app\common\model\company\CompanyProperty; +use app\common\model\contract\Contract; +use app\common\model\contract\ShopContract; use app\common\model\contract\VehicleContract; +use app\common\model\ShopMerchant; use app\common\model\vehicle\VehicleRent; use think\cache\driver\Redis; use think\facade\Db; use think\facade\Log; +use think\model\Pivot; use think\response\Json; @@ -496,24 +500,31 @@ class IndexController extends BaseApiController Log::info(['认证回调:',$parmas]); try { if ($parmas) { - $data=json_decode($parmas['data'],true); - // 成功回调标记 - $redis = RedisLogic::getInstance(); - $cache = $redis->get('authentication_company_id_'.$parmas['id']); - if (!empty($cache)) { - $cacheData = json_decode($cache, true); - $cacheData['is_callback'] = 1; - $redis->set('authentication_company_id_'.$parmas['id'], json_encode($cacheData)); + // 商城系统商户入驻 + if (isset($parmas['type']) && $parmas['type'] == 'shop_merchant') { + $this->shopMerchantCall($parmas); + return json(['success' => true, 'msg' => '成功']); + } else { + $data=json_decode($parmas['data'],true); + // 成功回调标记 + $redis = RedisLogic::getInstance(); + $cache = $redis->get('authentication_company_id_'.$parmas['id']); + if (!empty($cache)) { + $cacheData = json_decode($cache, true); + $cacheData['is_callback'] = 1; + $redis->set('authentication_company_id_'.$parmas['id'], json_encode($cacheData)); + } + if($data['status']==1){ + Company::where('id', $parmas['id'])->update(['is_authentication' => 1]); + } + if($data['status']==2){ + // 记录认证失败原因 + Db::name('company_authentication_fail_log')->insert(['company_id'=>$parmas['id'],'fail_reason'=>$data['msg'],'create_time'=>time()]); + Company::where('id', $parmas['id'])->update([ 'is_contract'=>0]); + } + return json(['success' => true, 'msg' => '成功']); } - if($data['status']==1){ - Company::where('id', $parmas['id'])->update(['is_authentication' => 1]); - } - if($data['status']==2){ - // 记录认证失败原因 - Db::name('company_authentication_fail_log')->insert(['company_id'=>$parmas['id'],'fail_reason'=>$data['msg'],'create_time'=>time()]); - Company::where('id', $parmas['id'])->update([ 'is_contract'=>0]); - } - return json(['success' => true, 'msg' => '成功']); + } } catch (\Exception $e) { Log::error('认证回调错误:'.$e->getMessage()); @@ -521,4 +532,33 @@ class IndexController extends BaseApiController return json(['success' => false, 'msg' => '失败,没有参数']); } + + private function shopMerchantCall($parmas) + { + $shopMerchant = ShopMerchant::find(['id', $parmas['id']]); + $data=json_decode($parmas['data'],true); + if($data['status']==1){ + $shopMerchant->save(['is_authentication' => 1]); + // 生成合同 + $createContractData = [ + 'id' => $parmas['id'], + 'party_a' => 1, + 'party_a_name' => '泸州市海之农科技有限公司', + 'party_b' => $parmas['id'], + 'party_b_name' => $shopMerchant->company_name, + 'contract_type' => 22, + ]; + $model = new ShopContract(); + $model->contract_no = time(); + $model->create_time = time(); + $model->check_status = 1; + $model->update_time = time(); + $model->setAttrs($createContractData); + $res = $model->save($data); + } + if($data['status']==2){ + // 记录认证失败原因 + Db::name('company_authentication_fail_log')->insert(['company_id'=>$parmas['id'], 'log_type'=>3, 'fail_reason'=>$data['msg'], 'create_time'=>time()]); + } + } } diff --git a/app/api/controller/JunziqianController.php b/app/api/controller/JunziqianController.php index b0b0830a4..4ac9b4796 100644 --- a/app/api/controller/JunziqianController.php +++ b/app/api/controller/JunziqianController.php @@ -92,6 +92,30 @@ class JunziqianController extends BaseApiController return $response; } + /** + * @param $data + * @return object + * 商城商户入驻,实名认证 + */ + public function ShopMerchantCertification($data) + { + $requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret); + $request = new OrganizationCreateReq(); + $request->name = $data['name']; + $request->identificationType = 1; //证件类型:0多证,1多证合一 + $request->organizationType = 0; //组织类型 0企业,1事业单位 + $request->organizationRegNo = $data['organization_code']; + $request->organizationRegImg = $data['business_license']; + $request->legalName = $data["master_name"]; //法人 + if (isset($data['master_email'])) { + $request->emailOrMobile = $data['master_email']; //邮箱 + } + $request->notifyUrl = env('url.url_prefix') . '/notifyAuthentication?id=' . $data['id'].'&type=shop_merchant'; // 回调增加type参数,用于回调是辨别是商户认证会带 + //发起创建企业请求 + $response = $requestUtils->doPost("/v2/user/organizationCreate", $request); + return $response; + } + //重新提交企业实名认证 public function organizationReapply($data) { diff --git a/app/common/model/ShopMerchant.php b/app/common/model/ShopMerchant.php new file mode 100644 index 000000000..c588a0cca --- /dev/null +++ b/app/common/model/ShopMerchant.php @@ -0,0 +1,8 @@ +