add:商城商户入驻逻辑

This commit is contained in:
chenbo 2023-09-13 15:54:15 +08:00
parent dc532e5f29
commit b9333d51ba
5 changed files with 151 additions and 19 deletions

View File

@ -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());
}
}
}

View File

@ -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()]);
}
}
}

View File

@ -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)
{

View File

@ -0,0 +1,8 @@
<?php
namespace app\common\model;
class ShopMerchant extends BaseModel
{
protected $name = 'shop_merchant';
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\common\model\contract;
use app\common\model\BaseModel;
class ShopContract extends BaseModel
{
protected $name = 'shop_contract';
}