添加:分销商提现 添加账号管理

This commit is contained in:
wuhui_zzw 2024-04-07 18:45:59 +08:00
parent cedbc1986e
commit a3982cf37b
5 changed files with 279 additions and 2 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace app\common\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\UserWithdrawalAccount;
class UserWithdrawalAccountDao extends BaseDao{
protected function getModel(): string{
return UserWithdrawalAccount::class;
}
/**
* Common: 公共搜索模型
* Author: wu-hui
* Time: 2024/04/07 11:37
* @param $params
* @return UserWithdrawalAccount
*/
public function searchModel($params){
return (new UserWithdrawalAccount())
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->when(isset($params['alipay_code']) && $params['alipay_code'] !== '',function($query) use ($params){
$query->where('alipay_code', $params['alipay_code']);
})
->when(isset($params['bank_code']) && $params['bank_code'] !== '',function($query) use ($params){
$query->where('bank_code', $params['bank_code']);
})
->when(isset($params['wechat']) && $params['wechat'] !== '',function($query) use ($params){
$query->where('wechat', $params['wechat']);
})
->with([
'user' => function($query){
$query->field('uid,nickname,avatar');
}
])
->order('create_time DESC,id DESC');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\common\model\user;
use app\common\model\BaseModel;
/**
* Common: 用户提现账号
* Author: wu-hui
* Time: 2024/04/07 11:32
* Class UserWithdrawalAccount
* @package app\common\model\user
*/
class UserWithdrawalAccount extends BaseModel
{
public static function tablePk(): string{
return 'id';
}
public static function tableName(): string{
return 'user_withdrawal_account';
}
public function user(){
return $this->hasOne(User::class, 'uid', 'uid');
}
}

View File

@ -0,0 +1,105 @@
<?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);
}
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace app\controller\api\user;
use app\common\repositories\user\UserWithdrawalAccountRepository;
use crmeb\basic\BaseController;
use think\App;
class WithdrawalAccount extends BaseController{
protected $repository;
public function __construct(App $app, UserWithdrawalAccountRepository $repository){
parent::__construct($app);
$this->repository = $repository;
}
/**
* Common: 提现账号列表
* Author: wu-hui
* Time: 2024/04/07 16:15
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(){
$uid = $this->request->uid();
$list = $this->repository->getSearchModel(['uid'=>$uid])->select()->toArray();
return app('json')->success($list);
}
/**
* Common: 编辑信息提交
* Author: wu-hui
* Time: 2024/04/07 18:29
* @return mixed
* @throws \think\db\exception\DbException
*/
public function editInfo(){
// 参数
$uid = $this->request->uid();
$params = $this->request->params([
'id',
'alipay_code',
'bank_address',
'bank_code',
'bank_name',
'bank_type',
'extract_pic',
'extract_type',
'real_name',
'wechat'
]);
$params['uid'] = $uid;
// 操作
$this->repository->editInfo($params);
return app('json')->success();
}
/**
* Common: 删除
* Author: wu-hui
* Time: 2024/04/07 18:45
* @return mixed
*/
public function delInfo(){
$id = $this->request->param('id');
$this->repository->delete($id);
return app('json')->success('删除成功');
}
}

View File

@ -441,9 +441,15 @@ Route::group('api/', function () {
Route::group('activity', function () {
Route::get('detail/:id', 'detail');
Route::get('joinActivity', 'joinActivity');
})->prefix('api.Activity/');
// 用户提现账号
Route::group('withdrawalAccount', function () {
Route::get('list', 'getList');// 获取账号列表
Route::post('edit', 'editInfo');// 提交编辑
Route::post('del', 'delInfo');// 删除
})->prefix('api.user.WithdrawalAccount/');
})->middleware(UserTokenMiddleware::class, true);