UserService.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\extra\service\user;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\user\UserDao;
  5. use app\extra\service\cutter\CutterOrderService;
  6. use support\exception\BusinessException;
  7. class UserService extends Service
  8. {
  9. /**
  10. * 设置模型
  11. * @return string
  12. */
  13. public function __construct()
  14. {
  15. $this->dao = new UserDao();
  16. }
  17. /**
  18. * 列表
  19. * @param array $param
  20. */
  21. public function getList(array $param = [],string $field = '*',string $order = 'id desc')
  22. {
  23. [$page,$limit] = $this->getPageValue();
  24. $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order);
  25. $count = $this->dao->count($this->searchFilter($param));
  26. return compact('list','count');
  27. }
  28. protected function searchFilter(array $param = []): array
  29. {
  30. $filter = [];
  31. !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
  32. !empty($param['is_del']) && $filter[] = ["is_del", '=', $param['is_del']];
  33. return $filter;
  34. }
  35. /**
  36. * 用户详情
  37. * @param array $data
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getUserInfo(array $data):array
  44. {
  45. $user = $this->dao->getOne(['openid'=>$data['openid'],'is_del'=>0]);
  46. if($user->isEmpty()){
  47. $user = $this->dao->save(['openid'=>$data['openid'],'nickname'=>'wx'.time().rand(1000,9999),'login_ip'=>$data['login_ip'],'login_at'=>$data['login_at']]);
  48. }else if($user['status'] == 0){
  49. throw new BusinessException('用户已被封禁');
  50. }
  51. return $user->toArray();
  52. }
  53. /**
  54. * 个人中心数据
  55. * @param array $user
  56. * @return array
  57. */
  58. public function getUserProfile(array $user)
  59. {
  60. if($user['is_del'])
  61. throw new BusinessException('用户已注销');
  62. if(!$user['status'])
  63. throw new BusinessException('用户已被封禁');
  64. $cutterOrderService = new CutterOrderService();
  65. $userBrokerageService = new UserBrokerageService();
  66. $user['order_count'] = $cutterOrderService->count(['uid'=>$user['uid']]);
  67. $user['brokerage_sum'] = $userBrokerageService->sum([['uid','=',$user['uid']],['pm','=',1],['type','not in',['extract_fail']]],'number');
  68. if($user['level']){
  69. $userLevelService = new UserLevelService();
  70. $user['vip'] = $userLevelService->getOne(['id'=>$user['level']],'name,icon');
  71. }
  72. return $user;
  73. }
  74. public function rank(int $type,array $user):array
  75. {
  76. $where = ['is_del'=>0,'status'=>1];
  77. $list = $this->dao->getRank($where,'uid,nickname,avatar',$type);
  78. $where['uid'] = $user['uid'];
  79. $self = $this->dao->getSelfRank($where,'uid,nickname,avatar',$type);
  80. $self['brokerage_sum'] = $self['brokerage_sum']?:0;
  81. $jackpot = 20000;
  82. return compact('list','self','jackpot');
  83. }
  84. }