Account.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $page = $this->request->get('page', 1);
  27. $page_size = $this->request->get('page_size', 10);
  28. $tab = $this->request->get('tab', 'all');
  29. $accountType = $this->request->get('accountType', '');
  30. $where = [];
  31. if ($tab != 'all') {
  32. $where['inc_or_exp'] = $tab == 'income' ? 1 : 2;
  33. }
  34. if ($accountType) {
  35. $where['account_type'] = $accountType == 'amount' ? ['in', ['amount', 'freeze']] : $accountType;
  36. }
  37. $list = AccountLogService::getList($where, $page_size, 'id desc')->toArray();
  38. $this->success('', $list);
  39. } catch (\Exception $e) {
  40. if ($e instanceof HttpResponseException) {
  41. throw $e;
  42. }
  43. $this->error($e->getMessage());
  44. }
  45. }
  46. public function info()
  47. {
  48. $user_id = $this->auth->id ?? -1;
  49. $data = AccountService::getOne(['user_id' => $user_id]);
  50. $this->success('success', $data);
  51. }
  52. public function applyWithdraw()
  53. {
  54. try {
  55. $user_id = $this->auth->id ?? -1;
  56. $amount = $this->request->post('amount', 0);
  57. $name = $this->request->post('name', '');
  58. // 验证参数
  59. $error = $this->validate($this->request->post(), [
  60. 'name' => 'require',
  61. 'amount' => 'require|number|between:1,500',
  62. ], [
  63. 'name.require' => '微信真实姓名必填',
  64. 'amount.require' => '提现金额不正确',
  65. 'amount.number' => '提现金额必须为数字',
  66. 'amount.between' => '提现金额必须在1到500之间',
  67. ]);
  68. if (true !== $error) {
  69. throw new \Exception($error);
  70. }
  71. AccountWithdrawService::applyWithdraw($user_id, $amount, $name);
  72. $this->success('提现申请成功,1-3个工作日到账');
  73. } catch (\Exception $e) {
  74. if ($e instanceof HttpResponseException) {
  75. throw $e;
  76. }
  77. $this->error($e->getMessage());
  78. }
  79. }
  80. }