User.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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\outapi\controller;
  12. use think\facade\App;
  13. use app\services\user\OutUserServices;
  14. /**
  15. * 用户控制器
  16. * Class User
  17. * @package app\outapi\controller
  18. */
  19. class User extends AuthController
  20. {
  21. /**
  22. * User constructor.
  23. * @param App $app
  24. * @param OutUserServices $service
  25. * @method temp
  26. */
  27. public function __construct(App $app, OutUserServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 用户列表
  34. * @return mixed
  35. */
  36. public function lst()
  37. {
  38. $where = $this->request->getMore([
  39. ['nickname', ''],
  40. ['status', ''],
  41. ['field_key', ''],
  42. ]);
  43. return app('json')->success($this->services->getUserList($where));
  44. }
  45. /**
  46. * 保存新建的资源
  47. *
  48. * @param \think\Request $request
  49. * @return \think\Response
  50. */
  51. public function save()
  52. {
  53. $data = $this->request->postMore([
  54. ['real_name', ''],
  55. ['phone', 0],
  56. ['mark', ''],
  57. ['pwd', ''],
  58. ['level', 0],
  59. ['spread_open', 0],
  60. ['is_promoter', 0],
  61. ['status', 1]
  62. ]);
  63. $uid = $this->services->saveUser(0, $data);
  64. if (!$uid) {
  65. return app('json')->fail(100022);
  66. }
  67. return app('json')->success(100021, ['uid' => $uid]);
  68. }
  69. /**
  70. * 更新用户
  71. * @param $uid
  72. * @return mixed
  73. */
  74. public function update($uid)
  75. {
  76. $data = $this->request->postMore([
  77. ['real_name', ''],
  78. ['phone', 0],
  79. ['mark', ''],
  80. ['pwd', ''],
  81. ['level', 0],
  82. ['spread_open', 1],
  83. ['is_promoter', 0],
  84. ['status', 1]
  85. ]);
  86. if (!$uid) return app('json')->fail(100100);
  87. $this->services->saveUser((int)$uid, $data);
  88. return app('json')->success(100001);
  89. }
  90. /**
  91. * 赠送相关
  92. * @param int $uid
  93. * @return mixed
  94. * @throws \think\Exception
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\DbException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. */
  99. public function give($uid)
  100. {
  101. $data = $this->request->postMore([
  102. ['money_status', 0],
  103. ['money', 0],
  104. ['integration_status', 0],
  105. ['integration', 0],
  106. ['days', 0],
  107. ['coupon', 0]
  108. ]);
  109. if (!$uid) return app('json')->fail(100100);
  110. if (!$this->services->otherGive((int)$uid, $data)) {
  111. return app('json')->fail(100005);
  112. }
  113. return app('json')->success(100010);
  114. }
  115. /**
  116. * 获取用户详情
  117. * @param $uid
  118. * @return \think\Response
  119. * @author 吴汐
  120. * @email 442384644@qq.com
  121. * @date 2023/06/20
  122. */
  123. public function info($uid)
  124. {
  125. if (!$uid) return app('json')->fail(100100);
  126. $data = $this->services->userInfo($uid);
  127. return app('json')->success(compact('data'));
  128. }
  129. /**
  130. * 赠送余额
  131. * @param int $uid
  132. * @return mixed
  133. * @throws \think\Exception
  134. * @throws \think\db\exception\DataNotFoundException
  135. * @throws \think\db\exception\DbException
  136. * @throws \think\db\exception\ModelNotFoundException
  137. */
  138. public function giveBalance($uid)
  139. {
  140. $data = $this->request->postMore([
  141. ['money_status', 0],
  142. ['money', 0],
  143. ['integration_status', 0],
  144. ['integration', 0],
  145. ['days', 0],
  146. ['coupon', 0]
  147. ]);
  148. if (!$uid) return app('json')->fail(100100);
  149. if (!$this->services->otherGive((int)$uid, $data)) {
  150. return app('json')->fail(100005);
  151. }
  152. return app('json')->success(100010);
  153. }
  154. /**
  155. * 赠送积分
  156. * @param int $uid
  157. * @return mixed
  158. * @throws \think\Exception
  159. * @throws \think\db\exception\DataNotFoundException
  160. * @throws \think\db\exception\DbException
  161. * @throws \think\db\exception\ModelNotFoundException
  162. */
  163. public function givePoint($uid)
  164. {
  165. $data = $this->request->postMore([
  166. ['money_status', 0],
  167. ['money', 0],
  168. ['integration_status', 0],
  169. ['integration', 0],
  170. ['days', 0],
  171. ['coupon', 0]
  172. ]);
  173. if (!$uid) return app('json')->fail(100100);
  174. if (!$this->services->otherGive((int)$uid, $data)) {
  175. return app('json')->fail(100005);
  176. }
  177. return app('json')->success(100010);
  178. }
  179. }