UserSpread.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\user;
  12. use app\admin\controller\AuthController;
  13. use service\JsonService;
  14. use service\QrcodeService;
  15. use traits\CurdControllerTrait;
  16. use app\admin\model\user\User;
  17. use app\admin\model\user\UserBill;
  18. use app\admin\model\wechat\WechatUser as UserModel;
  19. use app\admin\model\order\StoreOrder;
  20. /**
  21. * 用户推广员管理
  22. * Class UserSpread
  23. * @package app\admin\controller\user
  24. */
  25. class UserSpread extends AuthController
  26. {
  27. use CurdControllerTrait;
  28. public function index()
  29. {
  30. $this->assign('year', getMonth());
  31. return $this->fetch();
  32. }
  33. public function spread_list()
  34. {
  35. $where = parent::getMore([
  36. ['nickname', ''],
  37. ['start_time', ''],
  38. ['end_time', ''],
  39. ['sex', ''],
  40. ['excel', 0],
  41. ['data', ''],
  42. ['subscribe', ''],
  43. ['order', ''],
  44. ['page', 1],
  45. ['limit', 20],
  46. ['user_type', ''],
  47. ]);
  48. return JsonService::successlayui(User::agentSystemPage($where));
  49. }
  50. public function get_badge_list()
  51. {
  52. $where = parent::postMore([
  53. ['data', ''],
  54. ['nickname', ''],
  55. ['excel', ''],
  56. ]);
  57. return JsonService::successful(User::getSpreadBadge($where));
  58. }
  59. /**
  60. * 一级推荐人页面
  61. * @return mixed
  62. */
  63. public function stair($uid = '')
  64. {
  65. if ($uid == '') return $this->failed('参数错误');
  66. $this->assign('uid', $uid ?: 0);
  67. $this->assign('year', getMonth());
  68. return $this->fetch();
  69. }
  70. /**
  71. * 统计推广订单
  72. * @param int $uid
  73. */
  74. public function stair_order($uid = 0)
  75. {
  76. if ($uid == '') return $this->failed('参数错误');
  77. $this->assign('uid', $uid ?: 0);
  78. $this->assign('year', getMonth());
  79. return $this->fetch();
  80. }
  81. public function get_stair_order_list()
  82. {
  83. $where = parent::getMore([
  84. ['uid', $this->request->param('uid', 0)],
  85. ['data', ''],
  86. ['order_id', ''],
  87. ['type', ''],
  88. ['page', 1],
  89. ['limit', 20],
  90. ]);
  91. return JsonService::successlayui(User::getStairOrderList($where));
  92. }
  93. public function get_stair_order_badge()
  94. {
  95. $where = parent::getMore([
  96. ['uid', ''],
  97. ['data', ''],
  98. ['order_id', ''],
  99. ['type', ''],
  100. ]);
  101. return JsonService::successful(User::getStairOrderBadge($where));
  102. }
  103. public function get_stair_list()
  104. {
  105. $where = parent::getMore([
  106. ['uid', $this->request->param('uid', 0)],
  107. ['data', ''],
  108. ['nickname', ''],
  109. ['type', ''],
  110. ['page', 1],
  111. ['limit', 20],
  112. ]);
  113. return JsonService::successlayui(User::getStairList($where));
  114. }
  115. public function get_stair_badge()
  116. {
  117. $where = parent::getMore([
  118. ['uid', ''],
  119. ['data', ''],
  120. ['nickname', ''],
  121. ['type', ''],
  122. ]);
  123. return JsonService::successful(User::getSairBadge($where));
  124. }
  125. /**
  126. * 二级推荐人页面
  127. * @return mixed
  128. */
  129. public function stair_two($uid = '')
  130. {
  131. if ($uid == '') return $this->failed('参数错误');
  132. $spread_uid = User::where('spread_uid', $uid)->column('uid', 'uid');
  133. if (count($spread_uid))
  134. $spread_uid_two = User::where('spread_uid', 'in', $spread_uid)->column('uid', 'uid');
  135. else
  136. $spread_uid_two = [0];
  137. $list = User::alias('u')
  138. ->where('u.uid', 'in', $spread_uid_two)
  139. ->field('u.avatar,u.nickname,u.now_money,u.spread_time,u.uid')
  140. ->where('u.status', 1)
  141. ->order('u.add_time DESC')
  142. ->select()
  143. ->toArray();
  144. foreach ($list as $key => $value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid']) ?: 0;
  145. $this->assign('list', $list);
  146. return $this->fetch('stair');
  147. }
  148. /*
  149. * 批量清除推广权限
  150. * */
  151. public function delete_promoter()
  152. {
  153. list($uids) = parent::postMore([
  154. ['uids', []]
  155. ], $this->request, true);
  156. if (!count($uids)) return JsonService::fail('请选择需要解除推广权限的用户!');
  157. User::beginTrans();
  158. try {
  159. if (User::where('uid', 'in', $uids)->update(['is_promoter' => 0])) {
  160. User::commitTrans();
  161. return JsonService::successful('解除成功');
  162. } else {
  163. User::rollbackTrans();
  164. return JsonService::fail('解除失败');
  165. }
  166. } catch (\PDOException $e) {
  167. User::rollbackTrans();
  168. return JsonService::fail('数据库操作错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  169. } catch (\Exception $e) {
  170. User::rollbackTrans();
  171. return JsonService::fail('系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  172. }
  173. }
  174. /*
  175. * 查看公众号推广二维码
  176. * @param int $uid
  177. * @return json
  178. * */
  179. public function look_code($uid = '', $action = '')
  180. {
  181. if (!$uid || !$action) return JsonService::fail('缺少参数');
  182. try {
  183. if (method_exists($this, $action)) {
  184. $res = $this->$action($uid);
  185. if ($res)
  186. return JsonService::successful($res);
  187. else
  188. return JsonService::fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!');
  189. } else
  190. return JsonService::fail('暂无此方法');
  191. } catch (\Exception $e) {
  192. return JsonService::fail('获取推广二维码失败,请检查您的微信配置', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
  193. }
  194. }
  195. /*
  196. * 获取公众号二维码
  197. * */
  198. public function wechant_code($uid)
  199. {
  200. $qr_code = QrcodeService::getForeverQrcode('spread', $uid);
  201. if (isset($qr_code['url']))
  202. return ['code_src' => $qr_code['url']];
  203. else
  204. throw new \think\Exception('获取失败,请稍后再试!');
  205. }
  206. /*
  207. * 解除单个用户的推广权限
  208. * @param int $uid
  209. * */
  210. public function delete_spread($uid = 0)
  211. {
  212. if (!$uid) return JsonService::fail('缺少参数');
  213. if (User::where('uid', $uid)->update(['is_promoter' => 0]))
  214. return JsonService::successful('解除成功');
  215. else
  216. return JsonService::fail('解除失败');
  217. }
  218. /*
  219. * 清除推广人
  220. * */
  221. public function empty_spread($uid = 0)
  222. {
  223. if (!$uid) return JsonService::fail('缺少参数');
  224. $res = User::where('uid', $uid)->update(['spread_uid' => 0]);
  225. if ($res)
  226. return JsonService::successful('清除成功');
  227. else
  228. return JsonService::fail('清除失败');
  229. }
  230. /**
  231. * 个人资金详情页面
  232. * @return mixed
  233. */
  234. public function now_money($uid = '')
  235. {
  236. if ($uid == '') return $this->failed('参数错误');
  237. $list = UserBill::where('uid', $uid)->where('category', 'now_money')
  238. ->field('mark,pm,number,add_time')
  239. ->where('status', 1)->order('add_time DESC')->select()->toArray();
  240. foreach ($list as &$v) {
  241. $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
  242. }
  243. $this->assign('list', $list);
  244. return $this->fetch();
  245. }
  246. }