diff --git a/app/common/dao/user/UserWithdrawalAccountDao.php b/app/common/dao/user/UserWithdrawalAccountDao.php new file mode 100644 index 0000000..cf38090 --- /dev/null +++ b/app/common/dao/user/UserWithdrawalAccountDao.php @@ -0,0 +1,55 @@ +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'); + } + + + + + + + + + + + +} diff --git a/app/common/model/user/UserWithdrawalAccount.php b/app/common/model/user/UserWithdrawalAccount.php new file mode 100644 index 0000000..d4e4e02 --- /dev/null +++ b/app/common/model/user/UserWithdrawalAccount.php @@ -0,0 +1,32 @@ +hasOne(User::class, 'uid', 'uid'); + } + + +} diff --git a/app/common/repositories/user/UserWithdrawalAccountRepository.php b/app/common/repositories/user/UserWithdrawalAccountRepository.php new file mode 100644 index 0000000..2adce65 --- /dev/null +++ b/app/common/repositories/user/UserWithdrawalAccountRepository.php @@ -0,0 +1,105 @@ +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); + } + } + + + + + + + + +} diff --git a/app/controller/api/user/WithdrawalAccount.php b/app/controller/api/user/WithdrawalAccount.php new file mode 100644 index 0000000..320810d --- /dev/null +++ b/app/controller/api/user/WithdrawalAccount.php @@ -0,0 +1,79 @@ +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('删除成功'); + } + + + + + + + + +} diff --git a/route/api.php b/route/api.php index 72703b0..9ae43eb 100644 --- a/route/api.php +++ b/route/api.php @@ -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);