Withdraw.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\services\AliPayServices;
  4. use app\api\services\UserServices;
  5. use app\common\model\UserModel;
  6. use app\common\service\SystemConfigService;
  7. use app\common\service\WithdrawAccountService;
  8. use app\Request;
  9. use think\Exception;
  10. use think\facade\Db;
  11. use utils\RedisCache;
  12. //提现
  13. class Withdraw
  14. {
  15. /**
  16. * 提现提交
  17. * @param Request $request
  18. * @param UserServices $service
  19. * @return \think\Response
  20. */
  21. public function withDrawSubmit(Request $request, UserServices $service){
  22. Db::startTrans();
  23. try {
  24. $withdrawOpen = SystemConfigService::make()->getConfigByName('withdraw_is_open',1,'withdraw');
  25. $withdrawOpen = $withdrawOpen? $withdrawOpen : 0;
  26. if(!$withdrawOpen){
  27. return api_error_return('余额提现功能暂未开放');
  28. }
  29. $cacheKey = "caches:withdraw:locks:{$request->uid}";
  30. if(RedisCache::get($cacheKey)){
  31. return api_error_return('请不要频繁提交');
  32. }
  33. // 正常开放时间段
  34. getActionBefore(2);
  35. RedisCache::setnx($cacheKey, 1, rand(2,3));
  36. $service->withdraw($request->uid,$request->post('money'), $request->post('type'), $request->post());
  37. Db::commit();
  38. }catch (Exception $e){
  39. Db::rollback();
  40. return api_error_return($e->getMessage());
  41. }
  42. return api_succ_return('提交成功');
  43. }
  44. /**
  45. * 提现账号列表
  46. * @param Request $request
  47. * @return \think\Response
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function withdrawAccountList(Request $request){
  53. $params = $request->post();
  54. if (empty($params['type'])){
  55. return api_error_return('参数错误');
  56. }
  57. $list = WithdrawAccountService::make()->getListByUser($request->uid, $params['type']);
  58. return api_succ_return(['msg'=>'成功', 'data'=>$list]);
  59. }
  60. }