public function setNewUser($openid){ $userInfo = WechatService::getUserInfo($openid); if (!isset($userInfo['subscribe']) || !$userInfo['subscribe'] || !isset($userInfo['openid'])) throw new ValidateException('请关注公众号!'); $userInfo = $userInfo->toArray(); $userInfo['tagid_list'] = implode(',', $userInfo['tagid_list']); //判断 unionid 是否存在 $userInfo = is_object($userInfo) ? $userInfo->toArray() : $userInfo; $wechatInfo = []; $uid = 0; if (isset($userInfo['unionid'])) { $wechatInfo = $this->getWechatUserInfo(['unionid' => $userInfo['unionid']]); } if(!$wechatInfo){ /** @var UserServices $userServices */ $userServices = app()->make(UserServices::class); $userInfoData = $userServices->setUserInfo($userInfo); if (!$userInfoData) { throw new AdminException('用户信息储存失败!'); } $uid = $userInfoData->uid; }else{ $uid = $wechatInfo['uid']; } $userInfo['user_type'] = 'wechat'; $userInfo['add_time'] = time(); $userInfo['uid'] = $uid; if (!$this->dao->save($userInfo)) { throw new AdminException('用户储存失败!'); } //关注发优惠卷 /** @var StoreCouponIssueServices $storeCoupon */ $storeCoupon = app()->make(StoreCouponIssueServices::class); $storeCoupon->userFirstSubGiveCoupon((int)$uid); return $userInfoData;}