| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\controller\v1;
- use app\api\services\AliPayServices;
- use app\api\services\UserServices;
- use app\common\model\UserModel;
- use app\common\service\SystemConfigService;
- use app\common\service\WithdrawAccountService;
- use app\Request;
- use think\Exception;
- use think\facade\Db;
- use utils\RedisCache;
- //提现
- class Withdraw
- {
- /**
- * 提现提交
- * @param Request $request
- * @param UserServices $service
- * @return \think\Response
- */
- public function withDrawSubmit(Request $request, UserServices $service){
- Db::startTrans();
- try {
- $withdrawOpen = SystemConfigService::make()->getConfigByName('withdraw_is_open',1,'withdraw');
- $withdrawOpen = $withdrawOpen? $withdrawOpen : 0;
- if(!$withdrawOpen){
- return api_error_return('余额提现功能暂未开放');
- }
- $cacheKey = "caches:withdraw:locks:{$request->uid}";
- if(RedisCache::get($cacheKey)){
- return api_error_return('请不要频繁提交');
- }
- // 正常开放时间段
- getActionBefore(2);
- RedisCache::setnx($cacheKey, 1, rand(2,3));
- $service->withdraw($request->uid,$request->post('money'), $request->post('type'), $request->post());
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- return api_error_return($e->getMessage());
- }
- return api_succ_return('提交成功');
- }
- /**
- * 提现账号列表
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function withdrawAccountList(Request $request){
- $params = $request->post();
- if (empty($params['type'])){
- return api_error_return('参数错误');
- }
- $list = WithdrawAccountService::make()->getListByUser($request->uid, $params['type']);
- return api_succ_return(['msg'=>'成功', 'data'=>$list]);
- }
- }
|