$userId, 'item_id' => $itemId, 'type' => $type ], $params); return $result ? 0 : 1004; } /** * 商品收藏/浏览历史列表 * */ public static function getUserInterestList($userId, $type, $page, $pageSize) { # 获取商品收藏/浏览历史列表 list($list, $count) = UserInterestGoods::interestListOfUser($userId, $type, $page, $pageSize); if(!$count) return [[], 0]; foreach ($list as $item) { # 在售价、券后价和优惠券金额单位换算 $item->item_price = $item->item_price / 100; $item->item_end_price = $item->item_end_price / 100; $item->coupon_money = $item->coupon_money / 100; # 更新日期 $item->date = date('Y-m-d', strtotime($item->updated_at)); } if($type == 2) { // 浏览历史按日期分组 $data = $midData = []; foreach ($list as $datum) { $midData[$datum->date][] = $datum; } foreach ($midData as $key=>$val) { $data[] = [ 'date' => $key, 'list' => $val ]; } return [$data, $count]; } return [$list, $count]; } /** * 收藏/浏览商品批量移除 * */ public static function removeInterest($userId, $ids, $type) { $ids = explode(',', $ids); return UserInterestGoods::removeInterest($userId, $ids, $type); } /** * 记录用户搜索历史 * */ public static function userSearch($keyword, $userId) { # 获取已存储的用户搜索历史信息 $list = RedisModel::getAfterDecode(UserService::USER_SEARCH_HISTORY . $userId); if(empty($list)) $list = []; array_unshift($list, $keyword); $list = array_unique($list); if(count($list) > 50) $list = array_slice($list, 0, 50); # 存储用户搜索历史 return RedisModel::setAfterEncode(UserService::USER_SEARCH_HISTORY . $userId, array_values($list)); } /** * 获取用户搜索历史 * */ public static function getSearchHistory($userId) { $list = RedisModel::getAfterDecode(UserService::USER_SEARCH_HISTORY . $userId); return $list ? : []; } /** * 删除用户搜索历史 * */ public static function delSearchHistory($userId) { $result = RedisModel::del(UserService::USER_SEARCH_HISTORY . $userId); return $result ? 0 : 1008; } /** * 保存用户意见反馈 * */ public static function saveFeedback($userId, $desc) { return SysFeedback::saveFeedback($userId, $desc); } /** * 保存用户分享记录 * */ public static function saveShareRecord($userId, $ids, $type, &$errno) { $shareId = UserShareRecord::saveInfo($userId, $ids, $type); if(!$shareId) $errno = 1006; return $shareId; } /** * 获取用户分享记录 * */ public static function getShareInfo($userId, $shareId, &$errno) { # 查询分享基本信息 $shareInfo = UserShareRecord::getShareInfo($userId, $shareId); # 获取分享商品信息 $interestGoodsIdsStr = $shareInfo->interest_ids ?? ''; if(empty($interestGoodsIdsStr)) { $errno = 1007; return []; } $interestGoodsIds = explode(',', $interestGoodsIdsStr); list($list, $count) = UserInterestGoods::interestListOfUser($userId, $shareInfo->type, 1, 100, $interestGoodsIds); if(!$count) { $shareInfo->goods_list = []; return $shareInfo; } foreach ($list as $item) { # 在售价、券后价和优惠券金额单位换算 $item->item_price = $item->item_price / 10; $item->item_end_price = $item->item_end_price / 10; $item->coupon_money = $item->coupon_money / 10; } $shareInfo->goods_list = $list; return $shareInfo; } /** * 设置用户头像、昵称 * */ public static function setUserInfo($userId, $type, $avatarUrl, $nickname, &$errno) { if($type == 2) { # 上传用户头像 $fileUrl = FileUploadService::uploadFile($avatarUrl); if(is_numeric($fileUrl)) { $errno = $fileUrl; return []; } } elseif($type == 1) { $fileUrl = $avatarUrl; } # 存储用户信息 $result = WxUser::where('id', $userId)->where('enable', 1)->update([ 'nickname' => $nickname, 'avatar_url' => $fileUrl ]); $errno = $result ? 0 : 1013; return ['nickname' => $nickname, 'avatar_url' => $fileUrl]; } }