You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. <?php
  2. namespace App\Service;
  3. use App\Model\OrderMain;
  4. use App\Model\Users;
  5. class UserService implements UserServiceInterface
  6. {
  7. /**
  8. * 是否平台新用户
  9. * 在很多奖励的地方会需要用到这个查询
  10. * 判定条件:
  11. * 没有在平台下过单(包括线上和线下)
  12. * @param $user_id
  13. * @return mixed|void
  14. */
  15. public function isStageNewUser($user_id): bool
  16. {
  17. $exist = OrderMain::query()
  18. ->where(['user_id' => $user_id])
  19. ->where(function ($query){
  20. $query->where('state', 'in', [4,5,10])
  21. ->orWhere('dm_state', 'in', [2,3]);
  22. })
  23. ->exists();
  24. return !$exist;
  25. }
  26. /**
  27. * 根据用户的openid更新unionid信息
  28. * 如果没有找到用户,则不做任何处理
  29. * @param $openid
  30. * @param $unionid
  31. * @return array
  32. */
  33. public function saveUserUnionid($openid,$unionid)
  34. {
  35. $result = [
  36. 'status' => false,
  37. 'msg' => '用户不存在或者已存在相同unionid'
  38. ];
  39. // 查询用户是否存在
  40. $userinfo = Users::select('id','unionid')->where('openid',$openid)->first();
  41. if($userinfo && $userinfo->unionid != $unionid){
  42. $userinfo->unionid = $unionid;
  43. if($res = $userinfo->save()){
  44. $result['status'] = true;
  45. $result['msg'] = '更改用户unionid信息成功';
  46. $result['res'] = $res;
  47. }else{
  48. $result['msg'] = '更改用户unionid信息失败';
  49. }
  50. }
  51. return $result;
  52. }
  53. }