381 lines
14 KiB
PHP
381 lines
14 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年9月28日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\card;
|
|
|
|
use app\models\CardBank;
|
|
use app\models\CardUnion;
|
|
use app\models\common\union\CardFrom;
|
|
use app\models\District;
|
|
use app\models\Model;
|
|
use app\models\UniqueOrderNo;
|
|
use app\models\User;
|
|
use RedisCache\RedisCache;
|
|
|
|
class CardUnionEditForm extends Model
|
|
{
|
|
|
|
public $model;
|
|
|
|
public $id;
|
|
public $cx_mch_id;
|
|
public $card_number;
|
|
public $name;
|
|
public $identity_number;
|
|
public $mobile_phone;
|
|
public $province_id;
|
|
public $city_id;
|
|
public $acct_bank_id;
|
|
public $created_at;
|
|
public $is_delete;
|
|
public $deleted_at;
|
|
public $apply_no;
|
|
public $status;
|
|
public $bank_id;
|
|
public $doc_id;
|
|
public $doc_pic;
|
|
|
|
public $redis_key;
|
|
public $redis_expire = 80;
|
|
|
|
public $note; //验证码
|
|
public $ps_no;
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['cx_mch_id', 'province_id', 'city_id', 'created_at', 'is_delete', 'deleted_at','cx_mch_id','status','bank_id','redis_expire'], 'integer'],
|
|
[['card_number', 'name', 'identity_number', 'mobile_phone', 'province_id', 'city_id','bank_id','doc_pic'], 'required'],
|
|
[['card_number', 'identity_number','doc_pic'], 'string', 'max' => 255],
|
|
[['name', 'acct_bank_id','doc_id'], 'string', 'max' => 50],
|
|
[['mobile_phone'], 'string', 'max' => 128],
|
|
[['apply_no','note','redis_key'], 'string', 'max' => 64],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'ID',
|
|
'cx_mch_id' => '平台商户id',
|
|
'card_number' => '银行号号',
|
|
'name' => '姓名',
|
|
'identity_number' => '证件号',
|
|
'mobile_phone' => '手机号',
|
|
'province_id' => '省id',
|
|
'city_id' => '市id',
|
|
'acct_bank_id' => '开户行别',
|
|
'created_at' => 'Created At',
|
|
'is_delete' => 'Is Delete',
|
|
'deleted_at' => 'Deleted At',
|
|
'apply_no' => '编号',
|
|
'note' => '短信验证码',
|
|
'status' => '绑定状态',
|
|
'bank_id' => '开户网点',
|
|
'doc_id' => '分账证明材料ID',
|
|
'doc_pic' => '分账证明材料',
|
|
'redis_key' => 'key'
|
|
];
|
|
}
|
|
|
|
//设置获取验证码按钮失效时间
|
|
public function setSmsExpire()
|
|
{
|
|
$redis = new RedisCache();
|
|
$redis->set($this->redis_key,time(),$this->redis_expire);
|
|
}
|
|
|
|
//判断获取验证码按钮是否可以点击
|
|
public function checkSmsExpire()
|
|
{
|
|
$redis = new RedisCache();
|
|
$val = $redis->get($this->redis_key);
|
|
return empty($val) ? 0 : $val;
|
|
}
|
|
|
|
//获取验证码按钮
|
|
public function send_bank_union()
|
|
{
|
|
try {
|
|
$expire_val = self::checkSmsExpire();
|
|
if(!empty($expire_val)){
|
|
$expire = $this->redis_expire - (time() - $expire_val);
|
|
return Model::asReturnError("请过{$expire}秒后再次请求");
|
|
}
|
|
if(!$this->model->isNewRecord && $this->model->status == 2){
|
|
$data = ['code' => 1,'无需再次绑定'];
|
|
}elseif (!$this->model->isNewRecord && $this->model->status == 1){
|
|
//短信重发接口
|
|
$data = self::send_sms();
|
|
}elseif ($this->model->status == 0 || $this->model->isNewRecord){
|
|
//发送绑定申请
|
|
$data = self::send_put();
|
|
}
|
|
return $data;
|
|
}catch (\Exception $e){
|
|
return Model::asReturnError($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
|
|
try {
|
|
$province = District::findOne($this->province_id);
|
|
if(empty($province)){
|
|
return Model::asReturnError('所选省不存在');
|
|
}
|
|
$city = District::findOne($this->city_id);
|
|
if(empty($city)){
|
|
return Model::asReturnError('所选市不存在');
|
|
}
|
|
$bank = CardBank::findOne(['id' => $this->bank_id]);
|
|
if(empty($bank) || empty($bank->b_id)){
|
|
return Model::asReturnError('所选开户网点不存在');
|
|
}
|
|
|
|
$acct_bank_id = substr($bank->b_id,0,3);
|
|
$this->acct_bank_id = $acct_bank_id;
|
|
$card_number = CardUnion::find()->where(['card_number' => $this->card_number])->asArray()->one();
|
|
if(!empty($card_number)){
|
|
return Model::asReturnError("此银行卡已存在,请勿重复绑定");
|
|
}
|
|
if($this->model->isNewRecord){
|
|
$this->model->is_delete = 0;
|
|
$this->model->deleted_at = 0;
|
|
$this->model->created_at = time();
|
|
}
|
|
|
|
if($this->model->isNewRecord || $this->model->status == 0){
|
|
$this->model->cx_mch_id = $this->cx_mch_id;
|
|
$this->model->card_number = $this->card_number;
|
|
$this->model->name = $this->name;
|
|
$this->model->identity_number = $this->identity_number;
|
|
$this->model->mobile_phone = $this->mobile_phone;
|
|
$this->model->province_id = $this->province_id;
|
|
$this->model->city_id = $this->city_id;
|
|
$this->model->acct_bank_id = $this->acct_bank_id;
|
|
$this->model->bank_id = $this->bank_id;
|
|
$apply_no = UniqueOrderNo::generate(UniqueOrderNo::ORDER_TYPE_BINDING_CARD_ORDER, CardUnion::class, 24, 1, 3, 'apply_no');
|
|
$this->model->apply_no = $apply_no;
|
|
if(empty($this->model->doc_id) || $this->doc_pic != $this->model->doc_pic){
|
|
$form = new CardFrom();
|
|
$is_ps = $form->psUpload($this->doc_pic);
|
|
if($is_ps['code'] != 0){
|
|
return Model::asReturnError($is_ps['msg']);
|
|
}
|
|
$psFileId = $is_ps['data']['psFileId'];
|
|
$this->model->doc_id = $psFileId;
|
|
}
|
|
$this->model->doc_pic = $this->doc_pic;
|
|
if(!$this->model->save()){
|
|
return $this->getModelError($this->model);
|
|
}
|
|
}
|
|
return Model::asReturnSuccess('ok');
|
|
|
|
}catch (\Exception $e){
|
|
return Model::asReturnError($e->getMessage());
|
|
}
|
|
}
|
|
|
|
//发送申请,获取验证码
|
|
private function send_put()
|
|
{
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
$edit = self::edit();
|
|
if(!isset($edit['code']) || $edit['code'] != 0){
|
|
$t->rollBack();
|
|
return $edit;
|
|
}
|
|
|
|
// $union = CardUnion::getUnion();
|
|
// if(!isset($edit['code']) || $edit['code'] != 0){
|
|
// $t->rollBack();
|
|
// return $union;
|
|
// }
|
|
// $union = $union['data'];
|
|
// $mchId = $union['mchId'];
|
|
|
|
$plugin = new \app\models\common\PluginService();
|
|
$updcService = $plugin->getUpdcService(0);
|
|
$appId = $updcService->appId;
|
|
$mchId = $updcService->mchId;
|
|
$private_cert = $updcService->privateKey;
|
|
$public_cert = $updcService->publicKey;
|
|
$password = $updcService->privateKeyPassword;
|
|
$url = $updcService->url;
|
|
|
|
|
|
|
|
$province = District::findOne($this->model->province_id);
|
|
if(empty($province)){
|
|
$t->rollBack();
|
|
return Model::asReturnError('所选省不存在');
|
|
}
|
|
$city = District::findOne($this->model->city_id);
|
|
if(empty($city)){
|
|
$t->rollBack();
|
|
return Model::asReturnError('所选市不存在');
|
|
}
|
|
$bank = CardBank::findOne(['id' => $this->bank_id]);
|
|
if(empty($bank) || empty($bank->name)){
|
|
$t->rollBack();
|
|
return Model::asReturnError('所选开户网点不存在');
|
|
}
|
|
|
|
$data['applyNo'] = CardUnion::get_apply_no($this->model->apply_no);
|
|
$data['acsMerNo'] = $mchId;
|
|
$data['psReceiverName'] = trim($this->model->name);
|
|
$data['psNo'] = CardUnion::getPsNo($this->model->id);
|
|
$data['psDocId'] = $this->model->doc_id;
|
|
$data['receiverType'] = 2;
|
|
$data['receiverCertType'] = 31;
|
|
$data['receiverCertNo'] = trim($this->model->identity_number);
|
|
$data['certEffectDate'] = '00000000';
|
|
$data['certExpireDate'] = '99991231';
|
|
$data['bankCity'] = $city->name;
|
|
$data['bankProvince'] = $province->name;
|
|
$data['bankName'] = $bank->name;
|
|
$data['bankAccountNo'] = trim($this->model->card_number);
|
|
$data['bankAccountName'] = trim($this->model->name);
|
|
$data['bankPhone'] = trim($this->model->mobile_phone);
|
|
$data['acctBank'] = trim($this->model->acct_bank_id);
|
|
$data['psRemark'] = 2;
|
|
|
|
$form = new CardFrom();
|
|
$res = $form->send_bank_apply($data,$this->model->apply_no);
|
|
if(!isset($res['code']) || $res['code'] != 0){
|
|
$t->rollBack();
|
|
return $res;
|
|
}
|
|
$r = \Yii::$app->db->createCommand()->update(CardUnion::tableName(), ['status' => 1], ['id' => $this->model->id,'is_delete' => 0,'status' => 0])->execute();
|
|
if(!$r){
|
|
$t->rollBack();
|
|
return Model::asReturnError('更新失败');
|
|
}
|
|
self::setSmsExpire();
|
|
$t->commit();
|
|
return Model::asReturnSuccess($res['msg']);
|
|
|
|
}catch (\Exception $e){
|
|
$t->rollBack();
|
|
return Model::asReturnError($e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
//重发验证码
|
|
public function send_sms()
|
|
{
|
|
try {
|
|
// $union = CardUnion::getUnion();
|
|
// if(!isset($edit['code']) || $edit['code'] != 0){
|
|
// return $union;
|
|
// }
|
|
// $union = $union['data'];
|
|
// $mchId = $union['mchId'];
|
|
$plugin = new \app\models\common\PluginService();
|
|
$updcService = $plugin->getUpdcService(0);
|
|
$appId = $updcService->appId;
|
|
$mchId = $updcService->mchId;
|
|
$private_cert = $updcService->privateKey;
|
|
$public_cert = $updcService->publicKey;
|
|
$password = $updcService->privateKeyPassword;
|
|
$url = $updcService->url;
|
|
|
|
$data['applyNo'] = CardUnion::get_apply_no($this->model->apply_no);
|
|
$data['acsMerNo'] = $mchId;
|
|
$data['verifyCode'] = $this->note;
|
|
$data['busType'] = 0;
|
|
|
|
$form = new CardFrom();
|
|
$res = $form->send_sms_reNotify($data,$this->model->apply_no);
|
|
if(!isset($res['code']) || $res['code'] != 0){
|
|
return $res;
|
|
}
|
|
$r = \Yii::$app->db->createCommand()->update(CardUnion::tableName(), ['status' => 1], ['id' => $this->model->id,'is_delete' => 0,'status' => 0])->execute();
|
|
if(!$r){
|
|
return Model::asReturnError('更新失败');
|
|
}
|
|
self::setSmsExpire();
|
|
return Model::asReturnSuccess($res['msg']);
|
|
}catch (\Exception $e){
|
|
return Model::asReturnError($e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
//确认验证码
|
|
public function confirm_sms()
|
|
{
|
|
try {
|
|
if($this->model->isNewRecord || $this->model->status == 0){
|
|
//未请求 - 提示请发送验证码
|
|
return Model::asReturnError('请先获取短信验证码');
|
|
}
|
|
if($this->model->status == 2 && !$this->model->isNewRecord){
|
|
//已绑定
|
|
return Model::asReturnError('无需再次绑定');
|
|
}
|
|
|
|
if(empty($this->note)){
|
|
return Model::asReturnError('请输入短信验证码');
|
|
}
|
|
|
|
// $union = CardUnion::getUnion();
|
|
// if(!isset($edit['code']) || $edit['code'] != 0){
|
|
// return $union;
|
|
// }
|
|
// $union = $union['data'];
|
|
// $mchId = $union['mchId'];
|
|
|
|
$plugin = new \app\models\common\PluginService();
|
|
$updcService = $plugin->getUpdcService(0);
|
|
$appId = $updcService->appId;
|
|
$mchId = $updcService->mchId;
|
|
$private_cert = $updcService->privateKey;
|
|
$public_cert = $updcService->publicKey;
|
|
$password = $updcService->privateKeyPassword;
|
|
$url = $updcService->url;
|
|
|
|
$data['applyNo'] = CardUnion::get_apply_no($this->model->apply_no);
|
|
$data['acsMerNo'] = $mchId;
|
|
$data['verifyCode'] = $this->note;
|
|
$form = new CardFrom();
|
|
$res = $form->verify_sms($data,$this->model->apply_no);
|
|
if(!isset($res['code']) || $res['code'] != 0){
|
|
return $res;
|
|
}
|
|
$r = \Yii::$app->db->createCommand()->update(CardUnion::tableName(), ['status' => 2], ['user_id' => $this->model->user_id,'is_delete' => 0,'status' => 1])->execute();
|
|
if(!$r){
|
|
return Model::asReturnError('更新失败');
|
|
}
|
|
self::setSmsExpire();
|
|
return Model::asReturnSuccess($res['msg']);
|
|
}catch (\Exception $e){
|
|
return Model::asReturnError($e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} |