AgentManage.php 9.0 KB

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