UserExtract.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\finance;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\user\UserExtractServices;
  14. use think\facade\App;
  15. use think\Request;
  16. /**
  17. * Class UserExtract
  18. * @package app\adminapi\controller\v1\finance
  19. */
  20. class UserExtract extends AuthController
  21. {
  22. /**
  23. * UserExtract constructor.
  24. * @param App $app
  25. * @param UserExtractServices $services
  26. */
  27. public function __construct(App $app, UserExtractServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 显示资源列表
  34. * @return mixed
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['status', ''],
  43. ['extract_type', ''],
  44. ['nireid', '', '', 'like'],
  45. ['data', '', '', 'time'],
  46. ]);
  47. if (isset($where['extract_type']) && $where['extract_type'] == 'wx') {
  48. $where['extract_type'] = 'weixin';
  49. }
  50. return app('json')->success($this->services->index($where));
  51. }
  52. /**
  53. * 显示编辑资源表单页
  54. * @param $id
  55. * @return mixed
  56. */
  57. public function edit($id)
  58. {
  59. if (!$id) return app('json')->fail(100026);
  60. return app('json')->success($this->services->edit((int)$id));
  61. }
  62. /**
  63. * 保存更新的资源
  64. * @param Request $request
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function update(Request $request, $id)
  69. {
  70. if (!$id) return app('json')->fail(100100);
  71. $id = (int)$id;
  72. $UserExtract = $this->services->getExtract($id);
  73. if (!$UserExtract) app('json')->fail(100026);
  74. if ($UserExtract['extract_type'] == 'alipay') {
  75. $data = $this->request->postMore([
  76. 'real_name',
  77. 'mark',
  78. 'extract_price',
  79. 'alipay_code',
  80. ]);
  81. if (!$data['real_name']) return app('json')->fail(400107);
  82. if ($data['extract_price'] <= -1) return app('json')->fail(400108);
  83. if (!$data['alipay_code']) return app('json')->fail(400109);
  84. } else if ($UserExtract['extract_type'] == 'weixin') {
  85. $data = $this->request->postMore([
  86. 'real_name',
  87. 'mark',
  88. 'extract_price',
  89. 'wechat',
  90. ]);
  91. if ($data['extract_price'] <= -1) return app('json')->fail(400108);
  92. if (!$data['wechat']) return app('json')->fail(400110);
  93. } else {
  94. $data = $this->request->postMore([
  95. 'real_name',
  96. 'extract_price',
  97. 'mark',
  98. 'bank_code',
  99. 'bank_address',
  100. ]);
  101. if (!$data['real_name']) return app('json')->fail(400107);
  102. if ($data['extract_price'] <= -1) return app('json')->fail(400108);
  103. if (!$data['bank_code']) return app('json')->fail(400111);
  104. if (!$data['bank_address']) return app('json')->fail(400112);
  105. }
  106. return app('json')->success($this->services->update($id, $data) ? 100001 : 100007);
  107. }
  108. /**
  109. * 拒绝
  110. * @param $id
  111. * @return mixed
  112. */
  113. public function refuse($id)
  114. {
  115. if (!$id) app('json')->fail(100100);
  116. $data = $this->request->postMore([
  117. ['message', '']
  118. ]);
  119. if ($data['message'] == '') return app('json')->fail(400113);
  120. return app('json')->success($this->services->refuse((int)$id, $data['message']) ? 100014 : 100015);
  121. }
  122. /**
  123. * 通过
  124. * @param $id
  125. * @return mixed
  126. */
  127. public function adopt($id)
  128. {
  129. if (!$id) app('json')->fail(100100);
  130. return app('json')->success($this->services->adopt((int)$id) ? 100014 : 100015);
  131. }
  132. }