Account.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Accounts;
  5. use app\common\service\AccountLogService;
  6. use app\common\service\AccountService;
  7. use app\common\service\AccountWithdrawService;
  8. use app\common\service\CategoryService;
  9. use app\common\service\DemandBiddingService;
  10. use app\common\service\DemandService;
  11. use app\common\service\GoodsService;
  12. use app\common\model\Category;
  13. use app\common\service\OrderService;
  14. use app\common\service\UserService;
  15. use fast\Tree;
  16. use think\Exception;
  17. use think\exception\HttpResponseException;
  18. use think\Validate;
  19. class Account extends Api
  20. {
  21. protected $noNeedLogin = [];
  22. protected $noNeedRight = ['*'];
  23. public function logs()
  24. {
  25. try {
  26. $user_id = $this->auth->id ?? -1;
  27. $page = $this->request->get('page', 1);
  28. $page_size = $this->request->get('page_size', 10);
  29. $tab = $this->request->get('tab', 'all');
  30. $accountType = $this->request->get('accountType', '');
  31. $where = [
  32. 'user_id' => $user_id,
  33. ];
  34. if ($tab != 'all') {
  35. $where['inc_or_exp'] = $tab == 'income' ? 1 : 2;
  36. }
  37. if ($accountType) {
  38. $where['account_type'] = $accountType == 'amount' ? ['in', ['amount', 'freeze']] : $accountType;
  39. }
  40. $list = AccountLogService::getList($where, $page_size, 'id desc')->toArray();
  41. $this->success('', $list);
  42. } catch (\Exception $e) {
  43. if ($e instanceof HttpResponseException) {
  44. throw $e;
  45. }
  46. $this->error($e->getMessage());
  47. }
  48. }
  49. public function info()
  50. {
  51. $user_id = $this->auth->id ?? -1;
  52. $data = AccountService::getOne(['user_id' => $user_id]);
  53. $this->success('success', $data);
  54. }
  55. public function applyWithdraw()
  56. {
  57. try {
  58. $user_id = $this->auth->id ?? -1;
  59. $amount = $this->request->post('amount', 0);
  60. $name = $this->request->post('name', '');
  61. // 验证参数
  62. $error = $this->validate($this->request->post(), [
  63. 'name' => 'require',
  64. 'amount' => 'require|number|between:1,500',
  65. ], [
  66. 'name.require' => '微信真实姓名必填',
  67. 'amount.require' => '提现金额不正确',
  68. 'amount.number' => '提现金额必须为数字',
  69. 'amount.between' => '提现金额必须在1到500之间',
  70. ]);
  71. if (true !== $error) {
  72. throw new \Exception($error);
  73. }
  74. AccountWithdrawService::applyWithdraw($user_id, $amount, $name);
  75. $this->success('提现申请成功,1-3个工作日到账');
  76. } catch (\Exception $e) {
  77. if ($e instanceof HttpResponseException) {
  78. throw $e;
  79. }
  80. $this->error($e->getMessage());
  81. }
  82. }
  83. }