Commit 71d11674 authored by zhz's avatar zhz

goods

parent 970fe2ab
......@@ -18,7 +18,7 @@ class GoodsController extends \Our\Controller_AbstractIndex {
$goodsInfo['freeShippingPrice'] = $store['freeShippingPrice'];
$goodsInfo['isQuality'] = $store['isQuality'];
$evaluation =$this->goodsService->getEvaluation($this->req[\Our\NameConst::data]);
$recomndGoods = $this->goodsService->getRecommendGoods($goodsInfo['storeId'],$this->memberId);
$recomndGoods = $this->goodsService->getRecommendGoods($goodsInfo['storeId'],$this->req[\Our\NameConst::data]['goodsCommonId'],$this->memberId);
$groups = \Business\Goods\GroupSaleServiceModel::getInstance()->getGroupByCommonId($this->req[\Our\NameConst::data]['goodsCommonId'],$goodsInfo['storeId']);
$couponService = \Business\Coupon\CouponServiceModel::getInstance();
$coupons = $couponService->getGoodsCoupons(array('storeId'=>$goodsInfo['storeId']),$this->memberId);
......
......@@ -938,19 +938,75 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
* @param null $memberId
* @return array
*/
public function getRecommendGoods($storeId,$memberId = null){
public function getRecommendGoods($storeId,$goodsCommonId,$memberId = null){
$commonIds = [];
//周销量前3取一个
$existIds[] = $goodsCommonId;
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$arr = $goodsCommonRedis->tableSRandMember('weekSales:'.$storeId,1);
//本周销售过的商品取一个
$commonIds = array_merge($commonIds,$arr);
$arr = $goodsCommonRedis->tableSRandMember('weekSaleGoods:'.$storeId,2);
//推荐商品取一个
$commonIds = array_merge($arr,$commonIds);
$arr = $goodsCommonRedis->tableSRandMember('recommendGoods:'.$storeId,4-count($commonIds));
//周销量前3取一个
if($goodsCommonRedis->tableSIsMember('weekSales:'.$storeId, $goodsCommonId)) {
$tempArr[] = $goodsCommonId;
}
if($goodsCommonRedis->sIsMember('weekSales:'.$storeId, $goodsCommonId)) {
$weekSales = $goodsCommonRedis->smembers('weekSales:'.$storeId);
if($weekSales) {
$arr = array_merge(array_diff($weekSales, $existIds));
if($arr) {
shuffle($arr);
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}
}
}
}else{
$arr = $goodsCommonRedis->tableSRandMember('weekSales:'.$storeId,1);
}
$commonIds = array_merge($arr,$commonIds);
//本周销售过的商品取两个
//$commonIds = array_merge($commonIds,$arr);
//$arr = $goodsCommonRedis->tableSRandMember('weekSaleGoods:'.$storeId,2);
//推荐商品取一个
//$commonIds = array_merge($arr,$commonIds);
//$arr = $goodsCommonRedis->tableSRandMember('recommendGoods:'.$storeId,4-count($commonIds));
//$commonIds = array_merge($arr,$commonIds);
$weekSaleGoods = $goodsCommonRedis->smembers('weekSaleGoods:'.$storeId);
if($weekSaleGoods) {
$arr = array_merge(array_diff($weekSaleGoods, $existIds));
if($arr) {
shuffle($arr);
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}
}
}
$recommendGoods = $goodsCommonRedis->smembers('weekSaleGoods:'.$storeId);
if($recommendGoods) {
$arr = array_merge(array_diff($recommendGoods, $existIds));
if($arr) {
shuffle($arr);
while(true) {
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}else{
break;
}
if(count($commonIds) == 4){
break;
}
}
}
}
$goods = [];
if($commonIds){
//该用户是否有参加销售活动
......
......@@ -99,7 +99,6 @@ class AbstractModel extends \Redis\AbstractModel {
public function tableSRandMember($h,$count = null){
return $this->sRandMember($this->calcKey($h),$count);
}
public function tableHIncrBy($h,$key,$keysvalue){
return $this->hIncrBy($this->calcKey($h),$key,$keysvalue);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment