| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller\user;
- use app\admin\controller\AuthController;
- use service\JsonService;
- use service\QrcodeService;
- use traits\CurdControllerTrait;
- use app\admin\model\user\User;
- use app\admin\model\user\UserBill;
- use app\admin\model\wechat\WechatUser as UserModel;
- use app\admin\model\order\StoreOrder;
- /**
- * 用户推广员管理
- * Class UserSpread
- * @package app\admin\controller\user
- */
- class UserSpread extends AuthController
- {
- use CurdControllerTrait;
- public function index()
- {
- $this->assign('year', getMonth());
- return $this->fetch();
- }
- public function spread_list()
- {
- $where = parent::getMore([
- ['nickname', ''],
- ['start_time', ''],
- ['end_time', ''],
- ['sex', ''],
- ['excel', 0],
- ['data', ''],
- ['subscribe', ''],
- ['order', ''],
- ['page', 1],
- ['limit', 20],
- ['user_type', ''],
- ]);
- return JsonService::successlayui(User::agentSystemPage($where));
- }
- public function get_badge_list()
- {
- $where = parent::postMore([
- ['data', ''],
- ['nickname', ''],
- ['excel', ''],
- ]);
- return JsonService::successful(User::getSpreadBadge($where));
- }
- /**
- * 一级推荐人页面
- * @return mixed
- */
- public function stair($uid = '')
- {
- if ($uid == '') return $this->failed('参数错误');
- $this->assign('uid', $uid ?: 0);
- $this->assign('year', getMonth());
- return $this->fetch();
- }
- /**
- * 统计推广订单
- * @param int $uid
- */
- public function stair_order($uid = 0)
- {
- if ($uid == '') return $this->failed('参数错误');
- $this->assign('uid', $uid ?: 0);
- $this->assign('year', getMonth());
- return $this->fetch();
- }
- public function get_stair_order_list()
- {
- $where = parent::getMore([
- ['uid', $this->request->param('uid', 0)],
- ['data', ''],
- ['order_id', ''],
- ['type', ''],
- ['page', 1],
- ['limit', 20],
- ]);
- return JsonService::successlayui(User::getStairOrderList($where));
- }
- public function get_stair_order_badge()
- {
- $where = parent::getMore([
- ['uid', ''],
- ['data', ''],
- ['order_id', ''],
- ['type', ''],
- ]);
- return JsonService::successful(User::getStairOrderBadge($where));
- }
- public function get_stair_list()
- {
- $where = parent::getMore([
- ['uid', $this->request->param('uid', 0)],
- ['data', ''],
- ['nickname', ''],
- ['type', ''],
- ['page', 1],
- ['limit', 20],
- ]);
- return JsonService::successlayui(User::getStairList($where));
- }
- public function get_stair_badge()
- {
- $where = parent::getMore([
- ['uid', ''],
- ['data', ''],
- ['nickname', ''],
- ['type', ''],
- ]);
- return JsonService::successful(User::getSairBadge($where));
- }
- /**
- * 二级推荐人页面
- * @return mixed
- */
- public function stair_two($uid = '')
- {
- if ($uid == '') return $this->failed('参数错误');
- $spread_uid = User::where('spread_uid', $uid)->column('uid', 'uid');
- if (count($spread_uid))
- $spread_uid_two = User::where('spread_uid', 'in', $spread_uid)->column('uid', 'uid');
- else
- $spread_uid_two = [0];
- $list = User::alias('u')
- ->where('u.uid', 'in', $spread_uid_two)
- ->field('u.avatar,u.nickname,u.now_money,u.spread_time,u.uid')
- ->where('u.status', 1)
- ->order('u.add_time DESC')
- ->select()
- ->toArray();
- foreach ($list as $key => $value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid']) ?: 0;
- $this->assign('list', $list);
- return $this->fetch('stair');
- }
- /*
- * 批量清除推广权限
- * */
- public function delete_promoter()
- {
- list($uids) = parent::postMore([
- ['uids', []]
- ], $this->request, true);
- if (!count($uids)) return JsonService::fail('请选择需要解除推广权限的用户!');
- User::beginTrans();
- try {
- if (User::where('uid', 'in', $uids)->update(['is_promoter' => 0])) {
- User::commitTrans();
- return JsonService::successful('解除成功');
- } else {
- User::rollbackTrans();
- return JsonService::fail('解除失败');
- }
- } catch (\PDOException $e) {
- User::rollbackTrans();
- return JsonService::fail('数据库操作错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
- } catch (\Exception $e) {
- User::rollbackTrans();
- return JsonService::fail('系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
- }
- }
- /*
- * 查看公众号推广二维码
- * @param int $uid
- * @return json
- * */
- public function look_code($uid = '', $action = '')
- {
- if (!$uid || !$action) return JsonService::fail('缺少参数');
- try {
- if (method_exists($this, $action)) {
- $res = $this->$action($uid);
- if ($res)
- return JsonService::successful($res);
- else
- return JsonService::fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!');
- } else
- return JsonService::fail('暂无此方法');
- } catch (\Exception $e) {
- return JsonService::fail('获取推广二维码失败,请检查您的微信配置', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
- }
- }
- /*
- * 获取公众号二维码
- * */
- public function wechant_code($uid)
- {
- $qr_code = QrcodeService::getForeverQrcode('spread', $uid);
- if (isset($qr_code['url']))
- return ['code_src' => $qr_code['url']];
- else
- throw new \think\Exception('获取失败,请稍后再试!');
- }
- /*
- * 解除单个用户的推广权限
- * @param int $uid
- * */
- public function delete_spread($uid = 0)
- {
- if (!$uid) return JsonService::fail('缺少参数');
- if (User::where('uid', $uid)->update(['is_promoter' => 0]))
- return JsonService::successful('解除成功');
- else
- return JsonService::fail('解除失败');
- }
- /*
- * 清除推广人
- * */
- public function empty_spread($uid = 0)
- {
- if (!$uid) return JsonService::fail('缺少参数');
- $res = User::where('uid', $uid)->update(['spread_uid' => 0]);
- if ($res)
- return JsonService::successful('清除成功');
- else
- return JsonService::fail('清除失败');
- }
- /**
- * 个人资金详情页面
- * @return mixed
- */
- public function now_money($uid = '')
- {
- if ($uid == '') return $this->failed('参数错误');
- $list = UserBill::where('uid', $uid)->where('category', 'now_money')
- ->field('mark,pm,number,add_time')
- ->where('status', 1)->order('add_time DESC')->select()->toArray();
- foreach ($list as &$v) {
- $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
- }
- $this->assign('list', $list);
- return $this->fetch();
- }
- }
|