erp/app/api/controller/merchant/MerchantController.php
2024-05-13 17:41:29 +08:00

84 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller\merchant;
use app\api\lists\merchant\MerchantLists;
use app\api\controller\BaseApiController;
use app\api\validate\MerchantBankValidate;
use app\common\service\ThinkApi;
use support\Cache;
use think\facade\Db;
class MerchantController extends BaseApiController
{
public function lists(){
return $this->dataLists(new MerchantLists());
}
public function add_bank()
{
$params = (new MerchantBankValidate())->post()->goCheck('add');
if($params['user_type'] == 1){
$has = Db::name('merchant_bank')->where('mer_id',$params['mer_id'])->where('is_own',$params['is_own'])->where('is_check','<>',2)->findOrEmpty();
}else{
$has = Db::name('merchant_bank')->where('supplier_id',$params['supplier_id'])->where('is_own',$params['is_own'])->where('is_check','<>',2)->findOrEmpty();
}
if(!empty($has)){
return $this->fail('已提交审核请勿重复提交');
}
$expireAt = strtotime(date('Y-m-d 23:59:59')); // 当天结束时间戳
$totalKey = $params['user_type'] == 1 ? $params['mer_id'].$params['bank_code'] : $params['supplier_id'].$params['bank_code'];
$checkKey = $params['user_type'] == 1 ? $params['mer_id'].'check' : $params['supplier_id'].'check';
$check = Cache::get($totalKey) ?? 0;
if ($check && $check > 9) {
return $this->fail('超出绑定限制请明日再绑定');
}
$wrongNum = Cache::get($checkKey) ?? 0;
if($wrongNum && $wrongNum > 2){
return $this->fail('当日认证次数已超限制,请勿重复提交,请次日后再试');
}
Cache::set($totalKey, (int)($check+1),$expireAt);
if($params['is_own'] == 0){
$info = [
'name'=>$params['name'],
'idNum'=>$params['id_card'],
'cardNo'=>$params['bank_code'],
'mobile'=>$params['phone'],
];
$thinkApi = new ThinkApi();
$result = $thinkApi->request('bankcard/auth',$info);
if($result['code'] != 0 || empty($result['data'])){
return $this->fail($result['message']);
}
//认证结果。01一致 02不一致 03认证不确定 04认证失败。01、02收费
if($result['data']['result'] == 4 || $result['data']['result'] == 2){
Cache::set($checkKey, (int)($wrongNum+1),$expireAt);
}
if($result['data']['result'] == 4 || $result['data']['result'] == 2){
$wrongNum = Cache::get($checkKey);
$numMsg = ',当日剩余认证次数'.(3-$wrongNum);
return $this->fail('认证失败,请检查姓名,身份证,银行卡,银行预留手机号码是否正确'.$numMsg);
}
}
$save_data = [
'user_type' => $params['user_type'],
'mer_id' => $params['mer_id'] ?? 0,
'supplier_id' => $params['supplier_id'] ?? 0,
'name' => $params['name'],
'bank_id' => $params['bank_id'],
'bank_code' => $params['bank_code'],
'bank_branch' => $params['bank_branch'],
'phone' => $params['phone'] ?? '',
'id_card' => $params['id_card'] ?? '',
'financial_img' => $params['financial_img'] ?? '',
'is_own' => $params['is_own'],
'is_check' => 0,
'create_time' => time()
];
//写入数据
$res = Db::name('merchant_bank')->insert($save_data);
return $res ? $this->success('添加成功') : $this->fail('添加失败');
}
}