Commit 26f95ff0 authored by zhz's avatar zhz

goods

parent dea92011
...@@ -942,72 +942,92 @@ class GoodsCommonServiceModel extends \Business\AbstractModel ...@@ -942,72 +942,92 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
$commonIds = []; $commonIds = [];
$existIds[] = $goodsCommonId; $existIds[] = $goodsCommonId;
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance(); $goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
//周销量前3取一个
// if($goodsCommonRedis->tableSIsMember('weekSales:'.$storeId, $goodsCommonId)) { // if($goodsCommonRedis->tableSIsMember('weekSales:'.$storeId, $goodsCommonId)) {
// $tempArr[] = $goodsCommonId; // $tempArr[] = $goodsCommonId;
// } // }
$log = \Our\Log::getInstance(); //周销量前3取一个
// $log->write(print_r($data, true)); $arr = $goodsCommonRedis->tableSRandMember('weekSales:'.$storeId,2);
$weekSales = $goodsCommonRedis->tableSmembers('weekSales:'.$storeId); $arr = array_merge(array_diff($arr, $existIds));
$log->write(json_encode($weekSales)); if($arr) {
if($weekSales) { $ret = array_pop($arr);
$arr = array_merge(array_diff($weekSales, $existIds)); $commonIds[] = $ret;
if($arr) { $existIds[] = $ret;
shuffle($arr);
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}
}
} }
//本周销售过的商品取两个 //本周销售过的商品取两个
//$commonIds = array_merge($commonIds,$arr); //$commonIds = array_merge($commonIds,$arr);
//$arr = $goodsCommonRedis->tableSRandMember('weekSaleGoods:'.$storeId,2); $arr = $goodsCommonRedis->tableSRandMember('weekSaleGoods:'.$storeId,count($existIds)+2);
//推荐商品取一个 $arr = array_merge(array_diff($arr, $existIds));
//$commonIds = array_merge($arr,$commonIds); if($arr) {
//$arr = $goodsCommonRedis->tableSRandMember('recommendGoods:'.$storeId,4-count($commonIds)); $ret = array_pop($arr);
$commonIds[] = $ret;
//$commonIds = array_merge($arr,$commonIds); $existIds[] = $ret;
$weekSaleGoods = $goodsCommonRedis->tableSmembers('weekSaleGoods:'.$storeId);
$log->write(json_encode($weekSaleGoods));
if($weekSaleGoods) {
$arr = array_merge(array_diff($weekSaleGoods, $existIds));
if($arr) { if($arr) {
shuffle($arr);
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}
$ret = array_pop($arr); $ret = array_pop($arr);
if($ret) { $commonIds[] = $ret;
$commonIds[] = $ret; $existIds[] = $ret;
$existIds[] = $ret;
}
} }
} }
$recommendGoods = $goodsCommonRedis->tableSmembers('recommendGoods:'.$storeId); //推荐商品取一个
$log->write(json_encode($recommendGoods)); //$commonIds = array_merge($arr,$commonIds);
if($recommendGoods) { $arr = $goodsCommonRedis->tableSRandMember('recommendGoods:'.$storeId,(4-count($commonIds)+count($existIds)));
$arr = array_merge(array_diff($recommendGoods, $existIds)); $arr = array_merge(array_diff($arr, $existIds));
if($arr) { if($arr) {
shuffle($arr); foreach ($arr as $v) {
while(true) { $commonIds[] = $v;
$ret = array_pop($arr);
if($ret) {
$commonIds[] = $ret;
$existIds[] = $ret;
}else{
break;
}
if(count($commonIds) == 4){
break;
}
}
} }
} }
//$commonIds = array_merge($arr,$commonIds);
// $weekSales = $goodsCommonRedis->tableSmembers('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;
// }
// }
// }
//
//
// $weekSaleGoods = $goodsCommonRedis->tableSmembers('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->tableSmembers('recommendGoods:'.$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 = []; $goods = [];
if($commonIds){ if($commonIds){
//该用户是否有参加销售活动 //该用户是否有参加销售活动
......
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