AgentManage.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. namespace app\admin\controller\agent;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\order\StoreOrder;
  5. use app\admin\model\system\SystemAttachment;
  6. use app\admin\model\user\User;
  7. use app\admin\model\wechat\WechatUser as UserModel;
  8. use app\models\routine\RoutineQrcode;
  9. use app\models\user\UserBill;
  10. use crmeb\services\JsonService;
  11. use crmeb\services\UploadService;
  12. use crmeb\services\UtilService as Util;
  13. /**
  14. * 分销商管理控制器
  15. * Class AgentManage
  16. * @package app\admin\controller\agent
  17. */
  18. class AgentManage extends AuthController
  19. {
  20. /**
  21. * @return mixed
  22. */
  23. public function index()
  24. {
  25. $this->assign('year', getMonth());
  26. $this->assign('store_brokerage_statu', sysConfig('store_brokerage_statu'));
  27. return $this->fetch();
  28. }
  29. public function get_spread_list()
  30. {
  31. $where = Util::getMore([
  32. ['nickname', ''],
  33. ['start_time', ''],
  34. ['end_time', ''],
  35. ['sex', ''],
  36. ['excel', ''],
  37. ['subscribe', ''],
  38. ['order', ''],
  39. ['page', 1],
  40. ['limit', 20],
  41. ['user_type', ''],
  42. ]);
  43. return JsonService::successlayui(UserModel::agentSystemPage($where));
  44. }
  45. public function get_badge()
  46. {
  47. $where = Util::postMore([
  48. ['data', ''],
  49. ['nickname', ''],
  50. ['excel', ''],
  51. ]);
  52. return JsonService::successful(UserModel::getSpreadBadge($where));
  53. }
  54. /**
  55. * 一级推荐人页面
  56. * @return mixed
  57. */
  58. public function stair($uid = '')
  59. {
  60. if ($uid == '') return $this->failed('参数错误');
  61. $this->assign('uid', $uid ?: 0);
  62. $this->assign('year', getMonth());
  63. return $this->fetch();
  64. }
  65. /*
  66. * 统计推广订单
  67. * @param int $uid
  68. * */
  69. public function stair_order($uid = 0)
  70. {
  71. if ($uid == '') return $this->failed('参数错误');
  72. $this->assign('uid', $uid ?: 0);
  73. $this->assign('year', getMonth());
  74. return $this->fetch();
  75. }
  76. public function get_stair_order_list()
  77. {
  78. $where = Util::getMore([
  79. ['uid', $this->request->param('uid', 0)],
  80. ['data', ''],
  81. ['order_id', ''],
  82. ['type', ''],
  83. ['page', 1],
  84. ['limit', 20],
  85. ]);
  86. return JsonService::successlayui(UserModel::getStairOrderList($where));
  87. }
  88. public function get_stair_order_badge()
  89. {
  90. $where = Util::getMore([
  91. ['uid', ''],
  92. ['data', ''],
  93. ['order_id', ''],
  94. ['type', ''],
  95. ]);
  96. return JsonService::successful(UserModel::getStairOrderBadge($where));
  97. }
  98. public function get_stair_list()
  99. {
  100. $where = Util::getMore([
  101. ['uid', $this->request->param('uid', 0)],
  102. ['data', ''],
  103. ['nickname', ''],
  104. ['type', ''],
  105. ['page', 1],
  106. ['limit', 20],
  107. ]);
  108. return JsonService::successlayui(UserModel::getStairList($where));
  109. }
  110. public function get_stair_badge()
  111. {
  112. $where = Util::getMore([
  113. ['uid', ''],
  114. ['data', ''],
  115. ['nickname', ''],
  116. ['type', ''],
  117. ]);
  118. return JsonService::successful(UserModel::getSairBadge($where));
  119. }
  120. /**
  121. * 二级推荐人页面
  122. * @return mixed
  123. */
  124. public function stair_two($uid = '')
  125. {
  126. if ($uid == '') return $this->failed('参数错误');
  127. $spread_uid = User::where('spread_uid', $uid)->column('uid', 'uid');
  128. if (count($spread_uid))
  129. $spread_uid_two = User::where('spread_uid', 'in', $spread_uid)->column('uid', 'uid');
  130. else
  131. $spread_uid_two = [0];
  132. $list = User::alias('u')
  133. ->where('u.uid', 'in', $spread_uid_two)
  134. ->field('u.avatar,u.nickname,u.now_money,u.spread_time,u.uid')
  135. ->where('u.status', 1)
  136. ->order('u.add_time DESC')
  137. ->select()
  138. ->toArray();
  139. foreach ($list as $key => $value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid']) ?: 0;
  140. $this->assign('list', $list);
  141. return $this->fetch('stair');
  142. }
  143. /*
  144. * 批量清除推广权限
  145. * */
  146. public function delete_promoter()
  147. {
  148. list($uids) = Util::postMore([
  149. ['uids', []]
  150. ], $this->request, true);
  151. if (!count($uids)) return JsonService::fail('请选择需要解除推广权限的用户!');
  152. User::beginTrans();
  153. try {
  154. if (User::where('uid', 'in', $uids)->update(['is_promoter' => 0])) {
  155. User::commitTrans();
  156. return JsonService::successful('解除成功');
  157. } else {
  158. User::rollbackTrans();
  159. return JsonService::fail('解除失败');
  160. }
  161. } catch (\PDOException $e) {
  162. User::rollbackTrans();
  163. return JsonService::fail('数据库操作错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  164. } catch (\Exception $e) {
  165. User::rollbackTrans();
  166. return JsonService::fail('系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  167. }
  168. }
  169. /*
  170. * 查看公众号推广二维码
  171. * @param int $uid
  172. * @return json
  173. * */
  174. public function look_code($uid = '', $action = '')
  175. {
  176. if (!$uid || !$action) return JsonService::fail('缺少参数');
  177. try {
  178. if (method_exists($this, $action)) {
  179. $res = $this->$action($uid);
  180. if ($res)
  181. return JsonService::successful($res);
  182. else
  183. return JsonService::fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!');
  184. } else
  185. return JsonService::fail('暂无此方法');
  186. } catch (\Exception $e) {
  187. return JsonService::fail('获取推广二维码失败,请检查您的微信配置', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
  188. }
  189. }
  190. /*
  191. * 获取小程序二维码
  192. * */
  193. public function routine_code($uid)
  194. {
  195. $userInfo = User::getUserInfos($uid);
  196. $name = $userInfo['uid'] . '_' . $userInfo['is_promoter'] . '_user.jpg';
  197. $imageInfo = SystemAttachment::getInfo($name, 'name');
  198. if (!$imageInfo) {
  199. $res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
  200. if (!$res) throw new \think\Exception('二维码生成失败');
  201. $imageInfo = UploadService::instance()->setUploadPath('routine/spread/code')->imageStream($name, $res['res']);
  202. if (!is_array($imageInfo)) return $imageInfo;
  203. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time']);
  204. RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'time' => time(), 'qrcode_url' => $imageInfo['dir']]);
  205. $urlCode = $imageInfo['dir'];
  206. } else $urlCode = $imageInfo['att_dir'];
  207. return ['code_src' => $urlCode];
  208. }
  209. /*
  210. * 获取公众号二维码
  211. * */
  212. public function wechant_code($uid)
  213. {
  214. $qr_code = \crmeb\services\QrcodeService::getForeverQrcode('spread', $uid);
  215. if (isset($qr_code['url']))
  216. return ['code_src' => $qr_code['url']];
  217. else
  218. throw new \think\Exception('获取失败,请稍后再试!');
  219. }
  220. /**
  221. * TODO 查看小程序推广二维码
  222. * @param string $uid
  223. */
  224. public function look_xcx_code($uid = '')
  225. {
  226. if (!strlen(trim($uid))) return JsonService::fail('缺少参数');
  227. try {
  228. $userInfo = User::getUserInfos($uid);
  229. $name = $userInfo['uid'] . '_' . $userInfo['is_promoter'] . '_user.jpg';
  230. $imageInfo = SystemAttachment::getInfo($name, 'name');
  231. if (!$imageInfo) {
  232. $res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
  233. if (!$res) return JsonService::fail('二维码生成失败');
  234. $imageInfo = UploadService::instance()->setUploadPath('routine/spread/code')->imageStream($name, $res['res']);
  235. if (!is_array($imageInfo)) return JsonService::fail($imageInfo);
  236. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time']);
  237. RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'time' => time(), 'qrcode_url' => $imageInfo['dir']]);
  238. $urlCode = $imageInfo['dir'];
  239. } else $urlCode = $imageInfo['att_dir'];
  240. return JsonService::successful(['code_src' => $urlCode]);
  241. } catch (\Exception $e) {
  242. return JsonService::fail('查看推广二维码失败!', ['line' => $e->getLine(), 'meassge' => $e->getMessage()]);
  243. }
  244. }
  245. /**
  246. * 解除单个用户的推广权限
  247. * @param int $uid
  248. */
  249. public function delete_spread($uid = 0)
  250. {
  251. if (!$uid) return JsonService::fail('缺少参数');
  252. if (User::where('uid', $uid)->update(['is_promoter' => 0]))
  253. return JsonService::successful('解除成功');
  254. else
  255. return JsonService::fail('解除失败');
  256. }
  257. /**
  258. * 清除推广人
  259. */
  260. public function empty_spread($uid = 0)
  261. {
  262. if (!$uid) return JsonService::fail('缺少参数');
  263. $res = User::where('uid', $uid)->update(['spread_uid' => 0]);
  264. if ($res)
  265. return JsonService::successful('清除成功');
  266. else
  267. return JsonService::fail('清除失败');
  268. }
  269. /**
  270. * 个人资金详情页面
  271. * @return mixed
  272. */
  273. public function now_money($uid = '')
  274. {
  275. if ($uid == '') return $this->failed('参数错误');
  276. $list = UserBill::where('uid', $uid)->where('category', 'now_money')
  277. ->field('mark,pm,number,add_time')
  278. ->where('status', 1)->order('add_time DESC')->select()->toArray();
  279. foreach ($list as &$v) {
  280. $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
  281. }
  282. $this->assign('list', $list);
  283. return $this->fetch();
  284. }
  285. }