AgentManage.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\agent;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\agent\AgentManageServices;
  14. use app\services\user\UserServices;
  15. use think\facade\App;
  16. /**
  17. * 分销商管理控制器
  18. * Class AgentManage
  19. * @package app\adminapi\controller\v1\agent
  20. */
  21. class AgentManage extends AuthController
  22. {
  23. /**
  24. * AgentManage constructor.
  25. * @param App $app
  26. * @param AgentManageServices $services
  27. */
  28. public function __construct(App $app, AgentManageServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 分销管理列表
  35. * @return mixed
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->getMore([
  40. ['nickname', ''],
  41. ['data', ''],
  42. ]);
  43. return app('json')->success($this->services->agentSystemPage($where));
  44. }
  45. /**
  46. * 分销头部统计
  47. * @return mixed
  48. */
  49. public function get_badge()
  50. {
  51. $where = $this->request->getMore([
  52. ['data', ''],
  53. ['nickname', ''],
  54. ]);
  55. return app('json')->success(['res' => $this->services->getSpreadBadge($where)]);
  56. }
  57. /**
  58. * 推广人列表
  59. * @return mixed
  60. */
  61. public function get_stair_list()
  62. {
  63. $where = $this->request->getMore([
  64. ['uid', 0],
  65. ['data', ''],
  66. ['nickname', ''],
  67. ['type', '']
  68. ]);
  69. return app('json')->success($this->services->getStairList($where));
  70. }
  71. /**
  72. * 推广人列表头部统计
  73. * @return mixed
  74. */
  75. public function get_stair_badge()
  76. {
  77. $where = $this->request->getMore([
  78. ['uid', ''],
  79. ['data', ''],
  80. ['nickname', ''],
  81. ['type', ''],
  82. ]);
  83. return app('json')->success(['res' => $this->services->getSairBadge($where)]);
  84. }
  85. /**
  86. * 统计推广订单列表
  87. * @return mixed
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\DbException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. */
  92. public function get_stair_order_list()
  93. {
  94. $where = $this->request->getMore([
  95. ['uid', 0],
  96. ['data', ''],
  97. ['order_id', ''],
  98. ['type', ''],
  99. ]);
  100. return app('json')->success($this->services->getStairOrderList((int)$where['uid'], $where));
  101. }
  102. /**
  103. * 统计推广订单头部统计
  104. * @return mixed
  105. */
  106. public function get_stair_order_badge()
  107. {
  108. $where = $this->request->getMore([
  109. ['uid', ''],
  110. ['data', ''],
  111. ['order_id', ''],
  112. ['type', ''],
  113. ]);
  114. return app('json')->success($this->services->getStairOrderBadge($where));
  115. }
  116. /**
  117. * 查看公众号推广二维码
  118. * @param int $uid
  119. * @return json
  120. * */
  121. public function look_code($uid = '', $action = '')
  122. {
  123. if (!$uid || !$action) return app('json')->fail('缺少参数');
  124. try {
  125. if (method_exists($this, $action)) {
  126. $res = $this->$action($uid);
  127. if ($res)
  128. return app('json')->success($res);
  129. else
  130. return app('json')->fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!');
  131. } else
  132. return app('json')->fail('暂无此方法');
  133. } catch (\Exception $e) {
  134. return app('json')->fail('获取推广二维码失败,请检查您的微信配置', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
  135. }
  136. }
  137. /**
  138. * 获取公众号二维码
  139. * */
  140. public function wechant_code($uid)
  141. {
  142. $qr_code = $this->services->wechatCode((int)$uid);
  143. if (isset($qr_code['url']))
  144. return ['code_src' => $qr_code['url']];
  145. else
  146. return app('json')->fail('获取失败,请稍后再试!');
  147. }
  148. /**
  149. * TODO 查看小程序推广二维码
  150. * @param string $uid
  151. */
  152. public function look_xcx_code($uid = '')
  153. {
  154. if (!strlen(trim($uid))) {
  155. return app('json')->fail('缺少参数');
  156. }
  157. return app('json')->success($this->services->lookXcxCode((int)$uid));
  158. }
  159. /**
  160. * 查看H5推广二维码
  161. * @param string $uid
  162. * @return mixed|string
  163. */
  164. public function look_h5_code($uid = '')
  165. {
  166. if (!strlen(trim($uid))) return app('json')->fail('缺少参数');
  167. return app('json')->success($this->services->lookH5Code((int)$uid));
  168. }
  169. /**
  170. * 解除单个用户的推广权限
  171. * @param int $uid
  172. * */
  173. public function delete_spread($uid)
  174. {
  175. if (!$uid) app('json')->fail('缺少参数');
  176. return app('json')->success($this->services->delSpread((int)$uid) ? '解除成功' : '解除失败');
  177. }
  178. /**
  179. * 修改上级推广人
  180. * @param UserServices $services
  181. * @return mixed
  182. */
  183. public function editSpread(UserServices $services)
  184. {
  185. [$uid, $spreadUid] = $this->request->postMore([
  186. [['uid', 'd'], 0],
  187. [['spread_uid', 'd'], 0],
  188. ], true);
  189. if (!$uid || !$spreadUid) {
  190. return app('json')->fail('缺少参数');
  191. }
  192. if ($uid == $spreadUid) {
  193. return app('json')->fail('上级推广人不能为自己');
  194. }
  195. $userInfo = $services->get($uid);
  196. if (!$userInfo) {
  197. return app('json')->fail('用户不存在');
  198. }
  199. if (!$services->count(['uid' => $spreadUid])) {
  200. return app('json')->fail('上级用户不存在');
  201. }
  202. if ($userInfo->spread_uid == $spreadUid) {
  203. return app('json')->fail('当前推广人已经是所选人');
  204. }
  205. $spreadInfo = $services->get($spreadUid);
  206. if($spreadInfo->spread_uid == $uid) {
  207. return app('json')->fail('上级推广人不能为自己下级');
  208. }
  209. $userInfo->spread_uid = $spreadUid;
  210. $userInfo->spread_time = time();
  211. $userInfo->save();
  212. return app('json')->success('修改成功');
  213. }
  214. }