CutterLabelService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\extra\service\cutter;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\cutter\CutterLabelDao;
  5. use app\extra\service\user\UserBrokerageService;
  6. use support\exception\BusinessException;
  7. class CutterLabelService extends Service
  8. {
  9. /**
  10. * 设置模型
  11. * @return string
  12. */
  13. public function __construct()
  14. {
  15. $this->dao = new CutterLabelDao();
  16. }
  17. /**
  18. * 列表
  19. * @param array $param
  20. */
  21. public function getList(array $param = [],string $field = '*', int $page = 0,int $limit = 0,string $order = 'id desc')
  22. {
  23. $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order);
  24. $count = $this->dao->count($this->searchFilter($param));
  25. return compact('list','count');
  26. }
  27. protected function searchFilter(array $param = []): array
  28. {
  29. $filter = [];
  30. !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
  31. !empty($param['is_del']) && $filter[] = ["is_del", '=', $param['is_del']];
  32. !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
  33. return $filter;
  34. }
  35. public function getUserInfo(array $data):array
  36. {
  37. $user = $this->dao->getOne(['openid'=>$data['openid'],'is_del'=>0]);
  38. if($user->isEmpty()){
  39. $user = $this->dao->save(['openid'=>$data['openid'],'nickname'=>'wx'.time().rand(1000,9999),'login_ip'=>$data['login_ip'],'login_at'=>$data['login_at']]);
  40. }else if($user['status'] == 0){
  41. throw new BusinessException('用户已被封禁');
  42. }
  43. return $user->toArray();
  44. }
  45. public function getUserProfile(array $user)
  46. {
  47. if($user['is_del'])
  48. throw new BusinessException('用户已注销');
  49. if(!$user['status'])
  50. throw new BusinessException('用户已被封禁');
  51. $cutterOrderService = new CutterOrderService();
  52. $userBrokerageService = new UserBrokerageService();
  53. $user['order_count'] = $cutterOrderService->count(['uid'=>$user['uid']]);
  54. $user['brokerage_sum'] = $userBrokerageService->sum([['uid','=',$user['uid']],['pm','=',1],['type','not in',['extract_fail']]],'number');
  55. return $user;
  56. }
  57. }