new-admin-api/app/common/repositories/user/UserWithdrawalAccountReposi...

106 lines
3.8 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\common\repositories\user;
use app\common\dao\user\UserWithdrawalAccountDao;
use app\common\model\user\UserWithdrawalAccount;
use app\common\repositories\BaseRepository;
use think\exception\ValidateException;
class UserWithdrawalAccountRepository extends BaseRepository{
protected $dao;
public function __construct(UserWithdrawalAccountDao $dao){
$this->dao = $dao;
}
/**
* Common: 规格搜索模型
* Author: wu-hui
* Time: 2024/04/07 11:38
* @param $params
* @return UserWithdrawalAccount
*/
public function getSearchModel($params){
return $this->dao->searchModel($params);
}
/**
* Common: 编辑信息
* Author: wu-hui
* Time: 2024/04/07 18:29
* @param $params
* @return \app\common\dao\BaseDao|\think\Model|void
* @throws \think\db\exception\DbException
*/
public function editInfo($params){
$id = (int)($params['id'] ?? 0);
$data = array_intersect_key($params,array_flip((array)[
'uid',
'alipay_code',
'bank_address',
'bank_code',
'bank_name',
'bank_type',
'extract_pic',
'extract_type',
'real_name',
'wechat'
]));
// 判断:信息是否完善 0=银行卡,1=微信,2=支付宝,3=微信零钱
$isHasWhere = [];
switch((int)$data['extract_type']){
case 0:
// 银行卡类型0=个人账户1=企业账户
if($data['bank_type'] == 1){
if(empty($data['real_name'])) throw new ValidateException('请输入开户名称');
if(empty($data['bank_code'])) throw new ValidateException('请输入账号');
if(empty($data['bank_address'])) throw new ValidateException('请输入开户行地址');
}else{
if(empty($data['real_name'])) throw new ValidateException('请输入持卡人姓名');
if(empty($data['bank_code'])) throw new ValidateException('请输入银行账号');
if(empty($data['bank_address'])) throw new ValidateException('请输入开户行地址');
if(empty($data['bank_name'])) throw new ValidateException('请选择收款银行');
}
// 判断:卡号是否已经存在
$isHasWhere = ['bank_code'=>$params['bank_code']];
break;
case 1:
if(empty($data['wechat'])) throw new ValidateException('请填写您的微信账号');
if(empty($data['extract_pic'])) throw new ValidateException('请上传收款码');
// 判断:微信账号是否已经存在
$isHasWhere = ['wechat'=>$params['wechat']];
break;
case 2:
if(empty($data['alipay_code'])) throw new ValidateException('请填写您的支付宝账号');
if(empty($data['extract_pic'])) throw new ValidateException('请上传收款码');
// 判断:微信账号是否已经存在
$isHasWhere = ['alipay_code'=>$params['alipay_code']];
break;
}
// 判断: 是否存在
if($isHasWhere){
$isHas = (int)$this->dao->searchModel($isHasWhere)
->when($id > 0,function($query) use ($id){
$query->where('id', '<>', $id);
})->value('id');
if($isHas) throw new ValidateException('账号已存在!');
}
// 进行处理
if($id > 0){
// 编辑信息
$this->dao->update($id, $data);
}else{
// 添加信息
return $this->dao->create($data);
}
}
}