|
@@ -12,6 +12,8 @@ use algorithm;
|
|
use brand_helper;
|
|
use brand_helper;
|
|
use category_helper;
|
|
use category_helper;
|
|
use Log;
|
|
use Log;
|
|
|
|
+use special_manager;
|
|
|
|
+use commonid_helper;
|
|
|
|
|
|
function mb_str_split( $string ) {
|
|
function mb_str_split( $string ) {
|
|
return preg_split('/(?<!^)(?!$)/u', $string );
|
|
return preg_split('/(?<!^)(?!$)/u', $string );
|
|
@@ -303,6 +305,7 @@ class searcher
|
|
|
|
|
|
private $goods_info;
|
|
private $goods_info;
|
|
private $price_cids;
|
|
private $price_cids;
|
|
|
|
+ private $promot_cids;
|
|
|
|
|
|
private static $stInstance;
|
|
private static $stInstance;
|
|
|
|
|
|
@@ -340,6 +343,7 @@ class searcher
|
|
$this->goods_dict = new goods_dict();
|
|
$this->goods_dict = new goods_dict();
|
|
$this->goods_info = new goods_info();
|
|
$this->goods_info = new goods_info();
|
|
$this->price_cids = new valtokey();
|
|
$this->price_cids = new valtokey();
|
|
|
|
+ $this->promot_cids = [];
|
|
|
|
|
|
$mod_goods = Model('goods');
|
|
$mod_goods = Model('goods');
|
|
global $config;
|
|
global $config;
|
|
@@ -377,6 +381,30 @@ class searcher
|
|
$this->price_cids->add($common_id,intval($item['goods_price'] * 100 + 0.5));
|
|
$this->price_cids->add($common_id,intval($item['goods_price'] * 100 + 0.5));
|
|
}
|
|
}
|
|
$this->price_cids->finish();
|
|
$this->price_cids->finish();
|
|
|
|
+ $this->read_promotion();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function read_promotion()
|
|
|
|
+ {
|
|
|
|
+ global $config;
|
|
|
|
+ $special = $config['bonus_match_goods'];
|
|
|
|
+ if(empty($special)) return false;
|
|
|
|
+ $special_id = intval($special['special_id']);
|
|
|
|
+ if($special_id <= 0) return false;
|
|
|
|
+
|
|
|
|
+ special_manager::instance()->special($special_id,$goods_ids);
|
|
|
|
+ if(empty($goods_ids)) return false;
|
|
|
|
+
|
|
|
|
+ $cids = [];
|
|
|
|
+ foreach ($goods_ids as $gid) {
|
|
|
|
+ $cid = commonid_helper::instance()->common_id($gid);
|
|
|
|
+ if($cid != false) {
|
|
|
|
+ $cids[] = $cid;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sort($cids);
|
|
|
|
+ $this->promot_cids = $cids;
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
private function get_name($dict, $words)
|
|
private function get_name($dict, $words)
|
|
@@ -697,6 +725,46 @@ class searcher
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function promote_goods($params)
|
|
|
|
+ {
|
|
|
|
+ $price = $params['price'];
|
|
|
|
+ $count = intval($params['count']);
|
|
|
|
+
|
|
|
|
+ $items = $this->price_cids->findall(intval($price * 100 + 0.5));
|
|
|
|
+ sort($items);
|
|
|
|
+
|
|
|
|
+ $match_cids = $items;
|
|
|
|
+ $pro_cids = algorithm::set_intersection($match_cids,$this->promot_cids);
|
|
|
|
+ if(count($pro_cids) < $count) {
|
|
|
|
+ $cids = $this->random_goods($match_cids,$count);
|
|
|
|
+ } else {
|
|
|
|
+ $cids = $this->random_goods($pro_cids,$count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ['total' => 1,'cids' => $cids,'total' => count($cids)];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function random_goods($cids,$count)
|
|
|
|
+ {
|
|
|
|
+ $length = count($cids);
|
|
|
|
+ if($length <= $count) return $cids;
|
|
|
|
+
|
|
|
|
+ $result = [];
|
|
|
|
+ for ($i = 0; $i < $count;)
|
|
|
|
+ {
|
|
|
|
+ $pos = mt_rand(0,$length - 1);
|
|
|
|
+ $val = $cids[$pos];
|
|
|
|
+
|
|
|
|
+ if(!in_array($val,$result)) {
|
|
|
|
+ $result[] = $val;
|
|
|
|
+ $i++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private function get_ids($dict, $words)
|
|
private function get_ids($dict, $words)
|
|
{
|
|
{
|
|
$i = 0;
|
|
$i = 0;
|