1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582 |
- <?php
- /**
- * 商品管理
- *
- *好商城V3 BY 33ha o.c om
- */
- defined('InShopNC') or exit('Access Invalid!');
- class goodsModel extends Model
- {
- public function __construct()
- {
- parent::__construct('goods');
- }
- const STATE1 = 1; // 出售中
- const STATE0 = 0; // 下架
- const STATE10 = 10; // 违规
- const VERIFY1 = 1; // 审核通过
- const VERIFY0 = 0; // 审核失败
- const VERIFY10 = 10; // 等待审核
- /**
- * 新增商品数据
- *
- * @param array $insert 数据
- * @param string $table 表名
- */
- public function addGoods($insert)
- {
- $result = $this->table('goods')->insert($insert);
- if ($result) {
- $this->_dGoodsCache($result);
- $this->_dGoodsCommonCache($insert['goods_commonid']);
- $this->_dGoodsSpecCache($insert['goods_commonid']);
- }
- return $result;
- }
- /**
- * 新增商品公共数据
- *
- * @param array $insert 数据
- * @param string $table 表名
- */
- public function addGoodsCommon($insert)
- {
- return $this->table('goods_common')->insert($insert);
- }
- /**
- * 新增多条商品数据
- *
- * @param unknown $insert
- */
- public function addGoodsImagesAll($insert)
- {
- $result = $this->table('goods_images')->insertAll($insert);
- if ($result) {
- foreach ($insert as $val) {
- $this->_dGoodsImageCache($val['goods_commonid'] . '|' . $val['color_id']);
- }
- }
- return $result;
- }
- /**
- * 商品SKU列表
- *
- * @param array $condition 条件
- * @param string $field 字段
- * @param string $group 分组
- * @param string $order 排序
- * @param int $limit 限制
- * @param int $page 分页
- * @param boolean $lock 是否锁定
- * @return array 二维数组
- */
- public function getGoodsList($condition, $field = '*', $group = '', $order = '', $limit = 0, $page = 0, $lock = false, $count = 0)
- {
- $start = microtime(true);
- $condition = $this->_getRecursiveClass($condition);
- perfor_period("goods.model",$start,"getGoodsList");
- return $this->table('goods')->field($field)->where($condition)->group($group)->page($page, $count)->order($order)->limit($limit)->lock($lock)->select();
- }
- /**
- * 出售中的商品SKU列表(只显示不同颜色的商品,前台商品索引,店铺也商品列表等使用)
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param number $page
- * @return array
- */
- public function getGoodsListByColorDistinct($condition, $field = '*', $order = 'goods_id asc', $page = 0)
- {
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- $condition = $this->_getRecursiveClass($condition);
- //去掉多规格颜色显示 好商城V3-B11
- // $field = "CONCAT(goods_commonid,',',color_id) as nc_distinct ," . $field;
- // $count = $this->getGoodsOnlineCount($condition, "distinct CONCAT(goods_commonid,',',color_id)");
- $fieldex = "CONCAT(goods_commonid) as nc_distinct, max(goods_storage) as max_goods_storage, " . $field;
- $count = $this->getGoodsOnlineCount($condition, "distinct CONCAT(goods_commonid)");
- $goods_list = array();
- if ($count != 0) {
- $goods_list = $this->getGoodsOnlineList($condition, $fieldex, $page, $order, 0, 'nc_distinct', false, $count);
- }
- $goods_ret = array();
- $goods_cids = array();
- foreach($goods_list as $goods)
- {
- $g_storage = intval($goods['goods_storage']);
- if($g_storage > 0 || $g_storage == intval($goods['max_goods_storage'])) {
- array_push($goods_ret,$goods);
- } else {
- array_push($goods_cids,intval($goods['goods_commonid']));
- }
- }
- if(!empty($goods_cids))
- {
- arsort($goods_cids);
- $condition['goods_commonid'] = array('in', $goods_cids);
- $items = $this->cls()->table('goods')->field($field)->where($condition)->order('goods_commonid desc,goods_storage desc')->limit(false)->select();
- foreach($goods_cids as $commonid)
- {
- $fAdd = true;
- foreach($items as $key => $goods)
- {
- if($commonid == intval($goods['goods_commonid'])) {
- if($fAdd) {
- array_push($goods_ret,$goods);
- $fAdd = false;
- }
- unset($items[$key]);
- }
- else {
- break;
- }
- }
- }
- }
- return $goods_ret;
- }
- /**
- * 在售商品SKU列表
- *
- * @param array $condition 条件
- * @param string $field 字段
- * @param string $group 分组
- * @param string $order 排序
- * @param int $limit 限制
- * @param int $page 分页
- * @param boolean $lock 是否锁定
- * @return array
- */
- public function getGeneralGoodsList($condition, $field = '*', $page = 0, $order = 'goods_id desc')
- {
- $condition['is_virtual'] = 0;
- $condition['is_fcode'] = 0;
- $condition['is_presell'] = 0;
- return $this->getGoodsList($condition, $field, '', $order, 0, $page, false, 0);
- }
- /**
- * 在售商品SKU列表
- *
- * @param array $condition 条件
- * @param string $field 字段
- * @param string $group 分组
- * @param string $order 排序
- * @param int $limit 限制
- * @param int $page 分页
- * @param boolean $lock 是否锁定
- * @return array
- */
- public function getGoodsOnlineList($condition, $field = '*', $page = 0, $order = 'goods_id desc', $limit = 0, $group = '', $lock = false, $count = 0)
- {
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsList($condition, $field, $group, $order, $limit, $page, $lock, $count);
- }
- /**
- * 出售中的普通商品列表,即不包括虚拟商品、F码商品、预售商品
- */
- public function getGoodsListForPromotion($condition, $field = '*', $page = 0, $type = '')
- {
- switch ($type) {
- case 'xianshi':
- case 'bundling':
- case 'combo':
- $condition['is_virtual'] = 0;
- $condition['is_fcode'] = 0;
- $condition['is_presell'] = 0;
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- break;
- case 'gift':
- $condition['is_virtual'] = 0;
- break;
- default:
- break;
- }
- return $this->getGoodsList($condition, $field, '', '', 0, $page);
- }
- /**
- * 商品列表 卖家中心使用
- *
- * @param array $condition 条件
- * @param array $field 字段
- * @param string $page 分页
- * @param string $order 排序
- * @return array
- */
- public function getGoodsCommonList($condition, $field = '*', $page = 10, $order = 'goods_commonid desc')
- {
- $condition = $this->_getRecursiveClass($condition);
- return $this->table('goods_common')->field($field)->where($condition)->order($order)->page($page)->select();
- }
- /**
- * 出售中的商品列表 卖家中心使用
- *
- * @param array $condition 条件
- * @param array $field 字段
- * @param string $page 分页
- * @param string $order 排序
- * @return array
- */
- public function getGoodsCommonOnlineList($condition, $field = '*', $page = 10, $order = "goods_commonid desc")
- {
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonList($condition, $field, $page, $order);
- }
- /**
- * 出售中的普通商品列表,即不包括虚拟商品、F码商品、预售商品
- */
- public function getGoodsCommonListForPromotion($condition, $field = '*', $page = 10, $type)
- {
- if ($type == 'groupbuy') {
- $condition['is_virtual'] = 0;
- $condition['is_fcode'] = 0;
- $condition['is_presell'] = 0;
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- }
- return $this->getGoodsCommonList($condition, $field, $page);
- }
- /**
- * 出售中的未参加促销的虚拟商品列表
- */
- public function getGoodsCommonListForVrPromotion($condition, $field = '*', $page = 10)
- {
- $condition['is_virtual'] = 1;
- $condition['is_fcode'] = 0;
- $condition['is_presell'] = 0;
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonList($condition, $field, $page);
- }
- /**
- * 仓库中的商品列表 卖家中心使用
- *
- * @param array $condition 条件
- * @param array $field 字段
- * @param string $page 分页
- * @param string $order 排序
- * @return array
- */
- public function getGoodsCommonOfflineList($condition, $field = '*', $page = 10, $order = "goods_commonid desc")
- {
- $condition['goods_state'] = self::STATE0;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonList($condition, $field, $page, $order);
- }
- /**
- * 违规的商品列表 卖家中心使用
- *
- * @param array $condition 条件
- * @param array $field 字段
- * @param string $page 分页
- * @param string $order 排序
- * @return array
- */
- public function getGoodsCommonLockUpList($condition, $field = '*', $page = 10, $order = "goods_commonid desc")
- {
- $condition['goods_state'] = self::STATE10;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonList($condition, $field, $page, $order);
- }
- /**
- * 等待审核或审核失败的商品列表 卖家中心使用
- *
- * @param array $condition 条件
- * @param array $field 字段
- * @param string $page 分页
- * @param string $order 排序
- * @return array
- */
- public function getGoodsCommonWaitVerifyList($condition, $field = '*', $page = 10, $order = "goods_commonid desc")
- {
- if (!isset($condition['goods_verify'])) {
- $condition['goods_verify'] = array('neq', self::VERIFY1);
- }
- return $this->getGoodsCommonList($condition, $field, $page, $order);
- }
- /**
- * 查询商品SUK及其店铺信息
- *
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getGoodsStoreList($condition, $field = '*')
- {
- $condition = $this->_getRecursiveClass($condition);
- return $this->table('goods,store')->field($field)->join('inner')->on('goods.store_id = store.store_id')->where($condition)->select();
- }
- /**
- * 计算商品库存
- *
- * @param array $goods_list
- * @return array|boolean
- */
- public function calculateStorage($goods_list)
- {
- // 计算库存
- if (!empty($goods_list)) {
- $goodsid_array = array();
- foreach ($goods_list as $value) {
- $goodscommonid_array[] = $value['goods_commonid'];
- }
- $goods_storage = $this->getGoodsList(array('goods_commonid' => array('in', $goodscommonid_array)), 'goods_storage,goods_commonid,goods_id,goods_storage_alarm');
- $storage_array = array();
- foreach ($goods_storage as $val) {
- if ($val['goods_storage_alarm'] != 0 && $val['goods_storage'] <= $val['goods_storage_alarm']) {
- $storage_array[$val['goods_commonid']]['alarm'] = true;
- }
- $storage_array[$val['goods_commonid']]['sum'] += $val['goods_storage'];
- $storage_array[$val['goods_commonid']]['goods_id'] = $val['goods_id'];
- }
- return $storage_array;
- } else {
- return false;
- }
- }
- /**
- * 更新商品SUK数据
- *
- * @param array $update 更新数据
- * @param array $condition 条件
- * @return boolean
- */
- public function editGoods($update, $condition)
- {
- $goods_list = $this->getGoodsList($condition, 'goods_id');
- if (empty($goods_list)) {
- return true;
- }
- $goodsid_array = array();
- foreach ($goods_list as $value) {
- $goodsid_array[] = $value['goods_id'];
- }
- return $this->editGoodsById($update, $goodsid_array);
- }
- /**
- * 更新商品SUK数据
- * @param array $update
- * @param int|array $goodsid_array
- * @return boolean|unknown
- */
- public function editGoodsById($update, $goodsid_array)
- {
- if (empty($goodsid_array)) {
- return true;
- }
- $condition['goods_id'] = array('in', $goodsid_array);
- $update['goods_edittime'] = time();
- $result = $this->table('goods')->where($condition)->update($update);
- if ($result)
- {
- foreach ((array)$goodsid_array as $value) {
- $this->_dGoodsCache($value);
- }
- $items = $this->table('goods')->field('goods_commonid')->where($condition)->limit(false)->select();
- $commonids = array();
- foreach($items as $key => $commid) {
- array_push($commonids,intval($commid['goods_commonid']));
- }
- $commonids = array_unique($commonids);
- foreach($commonids as $commid) {
- $this->_dGoodsCommonCache($commid);
- $this->_dGoodsSpecCache($commid);
- }
- }
- return $result;
- }
- /**
- * 更新商品促销价 (需要验证抢购和限时折扣是否进行)
- *
- * @param array $update 更新数据
- * @param array $condition 条件
- * @return boolean
- */
- public function editGoodsPromotionPrice($condition)
- {
- $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid');
- $goods_array = array();
- foreach ($goods_list as $val) {
- $goods_array[$val['goods_commonid']][$val['goods_id']] = $val;
- }
- $model_groupbuy = Model('groupbuy');
- $model_xianshigoods = Model('p_xianshi_goods');
- foreach ($goods_array as $key => $val) {
- // 查询抢购时候进行
- $groupbuy = $model_groupbuy->getGroupbuyOnlineInfo(array('goods_commonid' => $key));
- if (!empty($groupbuy)) {
- // 更新价格
- $this->editGoods(array('goods_promotion_price' => $groupbuy['groupbuy_price'], 'goods_promotion_type' => 1), array('goods_commonid' => $key));
- continue;
- }
- foreach ($val as $k => $v) {
- // 查询限时折扣时候进行
- $xianshigoods = $model_xianshigoods->getXianshiGoodsInfo(array('goods_id' => $k, 'start_time' => array('lt', time()), 'end_time' => array('gt', time())));
- if (!empty($xianshigoods)) {
- // 更新价格
- $this->editGoodsById(array('goods_promotion_price' => $xianshigoods['xianshi_price'], 'goods_promotion_type' => 2), $k);
- continue;
- }
- // 没有促销使用原价
- $this->editGoodsById(array('goods_promotion_price' => array('exp', 'goods_price'), 'goods_promotion_type' => 0), $k);
- }
- }
- return true;
- }
- /**
- * 更新商品数据
- * @param array $update 更新数据
- * @param array $condition 条件
- * @return boolean
- */
- public function editGoodsCommon($update, $condition)
- {
- $common_list = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
- if (empty($common_list)) {
- return false;
- }
- $commonid_array = array();
- foreach ($common_list as $val) {
- $commonid_array[] = $val['goods_commonid'];
- }
- return $this->editGoodsCommonById($update, $commonid_array);
- }
- /**
- * 更新商品数据
- * @param array $update
- * @param int|array $commonid_array
- * @return boolean|unknown
- */
- public function editGoodsCommonById($update, $commonid_array)
- {
- if (empty($commonid_array)) {
- return true;
- }
- $condition['goods_commonid'] = array('in', $commonid_array);
- $result = $this->table('goods_common')->where($condition)->update($update);
- if ($result) {
- foreach ((array)$commonid_array as $val) {
- $this->_dGoodsCommonCache($val);
- }
- }
- return $result;
- }
- /**
- * 锁定商品
- * @param unknown $condition
- * @return boolean
- */
- public function editGoodsCommonLock($condition)
- {
- $update = array('goods_lock' => 1);
- return $this->editGoodsCommon($update, $condition);
- }
- /**
- * 解锁商品
- * @param unknown $condition
- * @return boolean
- */
- public function editGoodsCommonUnlock($condition)
- {
- $update = array('goods_lock' => 0);
- return $this->editGoodsCommon($update, $condition);
- }
- /**
- * 更新商品信息
- *
- * @param array $condition
- * @param array $update1
- * @param array $update2
- * @return boolean
- */
- public function editProduces($condition, $update1, $update2 = array())
- {
- $update2 = empty($update2) ? $update1 : $update2;
- $goods_array = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
- if (empty($goods_array)) {
- return true;
- }
- $commonid_array = array();
- foreach ($goods_array as $val) {
- $commonid_array[] = $val['goods_commonid'];
- }
- $return1 = $this->editGoodsCommonById($update1, $commonid_array);
- $return2 = $this->editGoods($update2, array('goods_commonid' => array('in', $commonid_array)));
- if ($return1 && $return2) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 更新商品信息(审核失败)
- *
- * @param array $condition
- * @param array $update1
- * @param array $update2
- * @return boolean
- */
- public function editProducesVerifyFail($condition, $update1, $update2 = array())
- {
- $result = $this->editProduces($condition, $update1, $update2);
- if ($result) {
- $commonlist = $this->getGoodsCommonList($condition, 'goods_commonid,store_id,goods_verifyremark', 0);
- foreach ($commonlist as $val) {
- $param = array();
- $param['common_id'] = $val['goods_commonid'];
- $param['remark'] = $val['goods_verifyremark'];
- $this->_sendStoreMsg('goods_verify', $val['store_id'], $param);
- }
- }
- }
- /**
- * 更新未锁定商品信息
- *
- * @param array $condition
- * @param array $update1
- * @param array $update2
- * @return boolean
- */
- public function editProducesNoLock($condition, $update1, $update2 = array())
- {
- $condition['goods_lock'] = 0;
- return $this->editProduces($condition, $update1, $update2);
- }
- /**
- * 商品下架
- * @param array $condition 条件
- * @return boolean
- */
- public function editProducesOffline($condition)
- {
- $update = array('goods_state' => self::STATE0);
- return $this->editProducesNoLock($condition, $update);
- }
- /**
- * 商品上架
- * @param array $condition 条件
- * @return boolean
- */
- public function editProducesOnline($condition)
- {
- $update = array('goods_state' => self::STATE1);
- // 禁售商品、审核失败商品不能上架。
- $condition['goods_state'] = self::STATE0;
- $condition['goods_verify'] = array('neq', self::VERIFY0);
- // 修改预约商品状态
- $update['is_appoint'] = 0;
- return $this->editProduces($condition, $update);
- }
- /**
- * 违规下架
- *
- * @param array $update
- * @param array $condition
- * @return boolean
- */
- public function editProducesLockUp($update, $condition)
- {
- $update_param['goods_state'] = self::STATE10;
- $update = array_merge($update, $update_param);
- $return = $this->editProduces($condition, $update, $update_param);
- if ($return) {
- // 商品违规下架发送店铺消息
- $common_list = $this->getGoodsCommonList($condition, 'goods_commonid,store_id,goods_stateremark', 0);
- foreach ($common_list as $val) {
- $param = array();
- $param['remark'] = $val['goods_stateremark'];
- $param['common_id'] = $val['goods_commonid'];
- $this->_sendStoreMsg('goods_violation', $val['store_id'], $param);
- }
- return true;
- } else {
- return false;
- }
- }
- /**
- * 获取单条商品SKU信息
- *
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getGoodsInfo($condition, $field = '*')
- {
- return $this->table('goods')->field($field)->where($condition)->find();
- }
- /**
- * 获取单条商品SKU信息及其促销信息
- *
- * @param int $goods_id
- * @param string $field
- * @return array
- */
- public function getGoodsOnlineInfoForShare($goods_id)
- {
- $goods_info = $this->getGoodsOnlineInfoAndPromotionById($goods_id);
- if (empty($goods_info)) {
- return array();
- }
- //抢购
- if (isset($goods_info['groupbuy_info'])) {
- $goods_info['promotion_type'] = '抢购';
- $goods_info['promotion_price'] = $goods_info['groupbuy_info']['groupbuy_price'];
- }
- if (isset($goods_info['xianshi_info'])) {
- $goods_info['promotion_type'] = '限时折扣';
- $goods_info['promotion_price'] = $goods_info['xianshi_info']['xianshi_price'];
- }
- return $goods_info;
- }
- /**
- * 查询出售中的商品详细信息及其促销信息
- * @param int $goods_id
- * @return array
- */
- public function getGoodsOnlineInfoAndPromotionById($goods_id)
- {
- $goods_info = $this->getGoodsInfoAndPromotionById($goods_id);
- if (empty($goods_info) || $goods_info['goods_state'] != self::STATE1 || $goods_info['goods_verify'] != self::VERIFY1) {
- return array();
- }
- return $goods_info;
- }
- /**
- * 查询商品详细信息及其促销信息
- * @param int $goods_id
- * @return array
- */
- public function getGoodsInfoAndPromotionById($goods_id)
- {
- $goods_info = $this->getGoodsInfoByID($goods_id);
- if (empty($goods_info)) {
- return array();
- }
- //抢购
- if (C('groupbuy_allow'))
- {
- $goods_info['groupbuy_info'] = Model('groupbuy')->getGroupbuyInfoByGoodsCommonID($goods_info['goods_commonid']);
- }
- //限时折扣
- if (C('promotion_allow') && empty($goods_info['groupbuy_info']))
- {
- $goods_info['xianshi_info'] = Model('p_xianshi_goods')->getXianshiGoodsInfoByGoodsID($goods_info['goods_id']);
- }
- return $goods_info;
- }
- public function getGoodsStorageById($goods_id)
- {
- $goods_info = $this->getGoodsInfoByID($goods_id);
- if (empty($goods_info)) {
- return "0";
- }
- return $goods_info['goods_storage'];
- }
- /**
- * 查询出售中的商品列表及其促销信息
- * @param array $goodsid_array
- * @return array
- */
- public function getGoodsOnlineListAndPromotionByIdArray($goodsid_array)
- {
- if (empty($goodsid_array) || !is_array($goodsid_array)) return array();
- $goods_list = array();
- foreach ($goodsid_array as $goods_id) {
- $goods_info = $this->getGoodsOnlineInfoAndPromotionById($goods_id);
- if (!empty($goods_info)) $goods_list[] = $goods_info;
- }
- return $goods_list;
- }
- /**
- * 获取单条商品信息
- *
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getGoodeCommonInfo($condition, $field = '*')
- {
- return $this->table('goods_common')->field($field)->where($condition)->find();
- }
- /**
- * 取得商品详细信息(优先查询缓存)
- * 如果未找到,则缓存所有字段
- * @param int $goods_commonid
- * @param string $fields 需要取得的缓存键值, 例如:'*','goods_name,store_name'
- * @return array
- */
- public function getGoodeCommonInfoByID($goods_commonid, $fields = '*')
- {
- $common_info = $this->_rGoodsCommonCache($goods_commonid, $fields);
- if (empty($common_info)) {
- $common_info = $this->getGoodeCommonInfo(array('goods_commonid' => $goods_commonid));
- $this->_wGoodsCommonCache($goods_commonid, $common_info);
- }
- return $common_info;
- }
- /**
- * 获得商品SKU某字段的和
- *
- * @param array $condition
- * @param string $field
- * @return boolean
- */
- public function getGoodsSum($condition, $field)
- {
- return $this->table('goods')->where($condition)->sum($field);
- }
- /**
- * 获得商品SKU数量
- *
- * @param array $condition
- * @param string $field
- * @return int
- */
- public function getGoodsCount($condition)
- {
- return $this->table('goods')->where($condition)->count();
- }
- /**
- * 获得出售中商品SKU数量
- *
- * @param array $condition
- * @param string $field
- * @return int
- */
- public function getGoodsOnlineCount($condition, $field = '*')
- {
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->table('goods')->where($condition)->group('')->count1($field);
- }
- /**
- * 获得商品数量
- *
- * @param array $condition
- * @param string $field
- * @return int
- */
- public function getGoodsCommonCount($condition)
- {
- return $this->table('goods_common')->where($condition)->count();
- }
- /**
- * 出售中的商品数量
- *
- * @param array $condition
- * @return int
- */
- public function getGoodsCommonOnlineCount($condition)
- {
- $condition['goods_state'] = self::STATE1;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonCount($condition);
- }
- /**
- * 仓库中的商品数量
- *
- * @param array $condition
- * @return int
- */
- public function getGoodsCommonOfflineCount($condition)
- {
- $condition['goods_state'] = self::STATE0;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonCount($condition);
- }
- /**
- * 等待审核的商品数量
- *
- * @param array $condition
- * @return int
- */
- public function getGoodsCommonWaitVerifyCount($condition)
- {
- $condition['goods_verify'] = self::VERIFY10;
- return $this->getGoodsCommonCount($condition);
- }
- /**
- * 审核失败的商品数量
- *
- * @param array $condition
- * @return int
- */
- public function getGoodsCommonVerifyFailCount($condition)
- {
- $condition['goods_verify'] = self::VERIFY0;
- return $this->getGoodsCommonCount($condition);
- }
- /**
- * 违规下架的商品数量
- *
- * @param array $condition
- * @return int
- */
- public function getGoodsCommonLockUpCount($condition)
- {
- $condition['goods_state'] = self::STATE10;
- $condition['goods_verify'] = self::VERIFY1;
- return $this->getGoodsCommonCount($condition);
- }
- /**
- * 商品图片列表
- *
- * @param array $condition
- * @param array $order
- * @param string $field
- * @return array
- */
- public function getGoodsImageList($condition, $field = '*', $order = 'is_default desc,goods_image_sort asc')
- {
- return $this->table('goods_images')->field($field)->where($condition)->order($order)->select();
- }
- public function getGoodsImageListEx($condition, $field = '*', $order = 'is_default desc,goods_image_sort asc')
- {
- return $this->table('goods_images')->field($field)->where($condition)->group('filesig')->order($order)->select();
- }
- /**
- * 删除商品SKU信息
- *
- * @param array $condition
- * @return boolean
- */
- public function delGoods($condition)
- {
- $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid,store_id');
- if (!empty($goods_list)) {
- $goodsid_array = array();
- // 删除商品二维码
- foreach ($goods_list as $val) {
- $goodsid_array[] = $val['goods_id'];
- @unlink(BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $val['store_id'] . DS . $val['goods_id'] . '.png');
- // 删除商品缓存
- $this->_dGoodsCache($val['goods_id']);
- // 删除商品规格缓存
- $this->_dGoodsSpecCache($val['goods_commonid']);
- }
- // 删除属性关联表数据
- $this->table('goods_attr_index')->where(array('goods_id' => array('in', $goodsid_array)))->delete();
- // 删除优惠套装商品
- Model('p_bundling')->delBundlingGoods(array('goods_id' => array('in', $goodsid_array)));
- // 优惠套餐活动下架
- Model('p_bundling')->editBundlingCloseByGoodsIds(array('goods_id' => array('in', $goodsid_array)));
- // 推荐展位商品
- Model('p_booth')->delBoothGoods(array('goods_id' => array('in', $goodsid_array)));
- // 限时折扣
- Model('p_xianshi_goods')->delXianshiGoods(array('goods_id' => array('in', $goodsid_array)));
- //删除商品浏览记录
- Model('goods_browse')->delGoodsbrowse(array('goods_id' => array('in', $goodsid_array)));
- // 删除买家收藏表数据
- $this->table('favorites')->where(array('fav_id' => array('in', $goodsid_array), 'fav_type' => 'goods'))->delete();
- // 删除商品赠品
- Model('goods_gift')->delGoodsGift(array('goods_id' => array('in', $goodsid_array), 'gift_goodsid' => array('in', $goodsid_array), '_op' => 'or'));
- // 删除推荐组合
- Model('goods_combo')->delGoodsCombo(array('goods_id' => array('in', $goodsid_array), 'combo_goodsid' => array('in', $goodsid_array), '_op' => 'or'));
- }
- return $this->table('goods')->where($condition)->delete();
- }
- /**
- * 删除商品图片表信息
- *
- * @param array $condition
- * @return boolean
- */
- public function delGoodsImages($condition)
- {
- $image_list = $this->getGoodsImageList($condition, 'goods_commonid,color_id');
- if (empty($image_list)) {
- return true;
- }
- $result = $this->table('goods_images')->where($condition)->delete();
- if ($result) {
- foreach ($image_list as $val) {
- $this->_dGoodsImageCache($val['goods_commonid'] . '|' . $val['color_id']);
- }
- }
- return $result;
- }
- /**
- * 商品删除及相关信息
- *
- * @param array $condition 列表条件
- * @return boolean
- */
- public function delGoodsAll($condition)
- {
- $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid,store_id');
- if (empty($goods_list)) {
- return false;
- }
- $goodsid_array = array();
- $commonid_array = array();
- foreach ($goods_list as $val) {
- $goodsid_array[] = $val['goods_id'];
- $commonid_array[] = $val['goods_commonid'];
- // 商品公共缓存
- $this->_dGoodsCommonCache($val['goods_commonid']);
- // 商品规格缓存
- $this->_dGoodsSpecCache($val['goods_commonid']);
- }
- $commonid_array = array_unique($commonid_array);
- // 删除商品表数据
- $this->delGoods(array('goods_id' => array('in', $goodsid_array)));
- // 删除商品公共表数据
- $this->table('goods_common')->where(array('goods_commonid' => array('in', $commonid_array)))->delete();
- // 删除商品图片表数据
- $this->delGoodsImages(array('goods_commonid' => array('in', $commonid_array)));
- // 删除商品F码
- Model('goods_fcode')->delGoodsFCode(array('goods_commonid' => array('in', $commonid_array)));
- return true;
- }
- /**
- * 删除未锁定商品
- * @param unknown $condition
- */
- public function delGoodsNoLock($condition)
- {
- $condition['goods_lock'] = 0;
- $common_array = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
- $common_array = array_under_reset($common_array, 'goods_commonid');
- $commonid_array = array_keys($common_array);
- return $this->delGoodsAll(array('goods_commonid' => array('in', $commonid_array)));
- }
- /**
- * 发送店铺消息
- * @param string $code
- * @param int $store_id
- * @param array $param
- */
- private function _sendStoreMsg($code, $store_id, $param)
- {
- QueueClient::push('sendStoreMsg', array('code' => $code, 'store_id' => $store_id, 'param' => $param));
- }
- /**
- * 获得商品子分类的ID
- * @param array $condition
- * @return array
- */
- private function _getRecursiveClass($condition)
- {
- if (isset($condition['gc_id']) && !is_array($condition['gc_id'])) {
- $gc_list = Model('goods_class')->getGoodsClassForCacheModel();
- if (!empty($gc_list[$condition['gc_id']])) {
- $gc_id[] = $condition['gc_id'];
- $gcchild_id = empty($gc_list[$condition['gc_id']]['child']) ? array() : explode(',', $gc_list[$condition['gc_id']]['child']);
- $gcchildchild_id = empty($gc_list[$condition['gc_id']]['childchild']) ? array() : explode(',', $gc_list[$condition['gc_id']]['childchild']);
- $gc_id = array_merge($gc_id, $gcchild_id, $gcchildchild_id);
- $condition['gc_id'] = array('in', $gc_id);
- }
- }
- return $condition;
- }
- /**
- * 由ID取得在售单个虚拟商品信息
- * @param unknown $goods_id
- * @param string $field 需要取得的缓存键值, 例如:'*','goods_name,store_name'
- * @return array
- */
- public function getVirtualGoodsOnlineInfoByID($goods_id)
- {
- $goods_info = $this->getGoodsInfoByID($goods_id, '*');
- return $goods_info['is_virtual'] == 1 && $goods_info['virtual_indate'] >= time() ? $goods_info : array();
- }
- /**
- * 取得商品详细信息(优先查询缓存)(在售)
- * 如果未找到,则缓存所有字段
- * @param int $goods_id
- * @param string $field 需要取得的缓存键值, 例如:'*','goods_name,store_name'
- * @return array
- */
- public function getGoodsOnlineInfoByID($goods_id, $field = '*')
- {
- if ($field != '*') {
- $field .= ',goods_state,goods_verify';
- }
- $goods_info = $this->getGoodsInfoByID($goods_id, trim($field, ','));
- if ($goods_info['goods_state'] != self::STATE1 || $goods_info['goods_verify'] != self::VERIFY1) {
- $goods_info = array();
- }
- return $goods_info;
- }
- /**
- * 取得商品详细信息(优先查询缓存)
- * 如果未找到,则缓存所有字段
- * @param int $goods_id
- * @param string $fields 需要取得的缓存键值, 例如:'*','goods_name,store_name'
- * @return array
- */
- public function getGoodsInfoByID($goods_id, $fields = '*')
- {
- $goods_info = $this->_rGoodsCache($goods_id, $fields);
- if (empty($goods_info)) {
- $goods_info = $this->getGoodsInfo(array('goods_id' => $goods_id));
- $this->_wGoodsCache($goods_id, $goods_info);
- }
- return $goods_info;
- }
- /**
- * 验证是否为普通商品
- * @param array $goods 商品数组
- * @return boolean
- */
- public function checkIsGeneral($goods)
- {
- if ($goods['is_virtual'] == 1 || $goods['is_fcode'] == 1 || $goods['is_presell'] == 1) {
- return false;
- }
- return true;
- }
- /**
- * 验证是否允许送赠品
- * @param unknown $goods
- * @return boolean
- */
- public function checkGoodsIfAllowGift($goods)
- {
- if ($goods['is_virtual'] == 1) {
- return false;
- }
- return true;
- }
- public function checkGoodsIfAllowCombo($goods)
- {
- if ($goods['is_virtual'] == 1 || $goods['is_fcode'] == 1 || $goods['is_presell'] == 1 || $goods['is_appoint'] == 1) {
- return false;
- }
- return true;
- }
- /**
- * 获得商品规格数组
- * @param unknown $common_id
- */
- public function getGoodsSpecListByCommonId($common_id)
- {
- $spec_list = $this->_rGoodsSpecCache($common_id);
- if (empty($spec_list)) {
- $spec_array = $this->getGoodsList(array('goods_commonid' => $common_id), 'goods_spec,goods_id,store_id,goods_image,color_id,goods_price,goods_promotion_price,goods_serial,goods_storage,goods_storage_alarm');
- $spec_list['spec'] = serialize($spec_array);
- $this->_wGoodsSpecCache($common_id, $spec_list);
- }
- $spec_array = unserialize($spec_list['spec']);
- return $spec_array;
- }
- /**
- * 获得商品图片数组
- * @param int $goods_id
- * @param array $condition
- */
- public function getGoodsImageByKey($key)
- {
- $image_list = $this->_rGoodsImageCache($key);
- if (empty($image_list)) {
- $array = explode('|', $key);
- list($common_id, $color_id) = $array;
- $image_more = $this->getGoodsImageList(array('goods_commonid' => $common_id, 'color_id' => $color_id), 'goods_image');
- $image_list['image'] = serialize($image_more);
- $this->_wGoodsImageCache($key, $image_list);
- }
- $image_more = unserialize($image_list['image']);
- return $image_more;
- }
- /**
- * 读取商品缓存
- * @param int $goods_id
- * @param string $fields
- * @return array
- */
- private function _rGoodsCache($goods_id, $fields)
- {
- return rcache($goods_id, 'goods', $fields);
- }
- /**
- * 写入商品缓存
- * @param int $goods_id
- * @param array $goods_info
- * @return boolean
- */
- private function _wGoodsCache($goods_id, $goods_info)
- {
- return wcache($goods_id, $goods_info, 'goods');
- }
- /**
- * 删除商品缓存
- * @param int $goods_id
- * @return boolean
- */
- private function _dGoodsCache($goods_id)
- {
- return dcache($goods_id, 'goods');
- }
- /**
- * 读取商品公共缓存
- * @param int $goods_commonid
- * @param string $fields
- * @return array
- */
- private function _rGoodsCommonCache($goods_commonid, $fields)
- {
- return rcache($goods_commonid, 'goods_common', $fields);
- }
- /**
- * 写入商品公共缓存
- * @param int $goods_commonid
- * @param array $common_info
- * @return boolean
- */
- private function _wGoodsCommonCache($goods_commonid, $common_info)
- {
- return wcache($goods_commonid, $common_info, 'goods_common');
- }
- /**
- * 删除商品公共缓存
- * @param int $goods_commonid
- * @return boolean
- */
- private function _dGoodsCommonCache($goods_commonid)
- {
- return dcache($goods_commonid, 'goods_common');
- }
- /**
- * 读取商品规格缓存
- * @param int $goods_commonid
- * @param string $fields
- * @return array
- */
- private function _rGoodsSpecCache($goods_commonid)
- {
- return rcache($goods_commonid, 'goods_spec');
- }
- /**
- * 写入商品规格缓存
- * @param int $goods_commonid
- * @param array $spec_list
- * @return boolean
- */
- private function _wGoodsSpecCache($goods_commonid, $spec_list)
- {
- return wcache($goods_commonid, $spec_list, 'goods_spec');
- }
- /**
- * 删除商品规格缓存
- * @param int $goods_commonid
- * @return boolean
- */
- private function _dGoodsSpecCache($goods_commonid)
- {
- return dcache($goods_commonid, 'goods_spec');
- }
- /**
- * 读取商品图片缓存
- * @param int $key ($goods_commonid .'|'. $color_id)
- * @param string $fields
- * @return array
- */
- private function _rGoodsImageCache($key)
- {
- return rcache($key, 'goods_image');
- }
- /**
- * 写入商品图片缓存
- * @param int $key ($goods_commonid .'|'. $color_id)
- * @param array $image_list
- * @return boolean
- */
- private function _wGoodsImageCache($key, $image_list)
- {
- return wcache($key, $image_list, 'goods_image');
- }
- /**
- * 删除商品图片缓存
- * @param int $key ($goods_commonid .'|'. $color_id)
- * @return boolean
- */
- private function _dGoodsImageCache($key)
- {
- return dcache($key, 'goods_image');
- }
- private function _formatGoodsAttr($goods_attr)
- {
- $result_attr = array();
- foreach ($goods_attr as $key => $val) {
- $attr_item['goods_attr_id'] = intval($key);
- $attr_item['goods_attr_name'] = $val['name'];
- if ($attr_item['goods_attr_name'] === '功效' ||
- $attr_item['goods_attr_name'] === '品牌' ||
- $attr_item['goods_attr_name'] === '保质期'
- ) {
- $goods_attr_value = array();
- foreach ($val as $id => $name) {
- if ($id !== 'name') {
- $val_item['id'] = intval($id);
- $val_item['name'] = $name;
- array_push($goods_attr_value, $val_item);
- }
- }
- $attr_item['goods_attr_value'] = $goods_attr_value;
- array_push($result_attr, $attr_item);
- }
- }
- return $result_attr;
- }
- public function getGoodsSku($goods_id)
- {
- Log::record(__FUNCTION__ . " goods_id={$goods_id}.", Log::DEBUG);
- if (empty($goods_id) || $goods_id <= 0) {
- Log::record(" return null 1.", Log::DEBUG);
- return null;
- }
- // get goods_commonid
- $goods_info = $this->getGoodsInfoAndPromotionById($goods_id);
- if (empty($goods_info)) {
- Log::record(" return null 2.", Log::DEBUG);
- return null;
- }
- $goods_common_info = $this->getGoodeCommonInfoByID($goods_info['goods_commonid']);
- if (empty($goods_common_info)) {
- Log::record(" return null 3.", Log::DEBUG);
- return null;
- }
- Log::record("goods_common_info = " . (string)$goods_common_info, Log::DEBUG);
- $goods_common_info['goods_body'] = '';//base64_encode($goods_common_info['goods_body']);
- $goods_common_info['goods_attr'] = $this->_formatGoodsAttr(unserialize($goods_common_info['goods_attr']));
- // sku
- $goods_spec_list = $this->getGoodsSpecListByCommonId($goods_info['goods_commonid']);
- $spec = Model('spec');
- foreach ($goods_spec_list as $key => &$value) {
- $value['goods_image'] = cthumb($value['goods_image'], 1280);
- $goods_spec = unserialize($value['goods_spec']);
- $value['goods_spec'] = array();
- if (!empty($goods_spec)) {
- foreach ($goods_spec as $key => $val) {
- $spec_id = $spec->getSpecValueList(array('sp_value_id' => $key), 'sp_id');
- $spec_name = $spec->specList(array('sp_id' => $spec_id[0]['sp_id']), '', 'sp_name');
- $spec_value = array('key' => $key, 'name' => $spec_name[0]['sp_name'], 'value' => $goods_spec[$key]);
- array_push($value['goods_spec'], $spec_value);
- }
- }
- // xianshi
- $xianshi_item = Model('p_xianshi_goods')->getXianshiGoodsInfoByGoodsID($value['goods_id']);
- if (!empty($xianshi_item)) {
- $value['promotion_type'] = 'xianshi';
- $value['title'] = $xianshi_item['xianshi_title'];
- $value['remark'] = $xianshi_item['xianshi_title'];
- $value['promotion_price'] = $xianshi_item['xianshi_price'];
- $value['down_price'] = ncPriceFormat($value['goods_price'] - $xianshi_item['xianshi_price']);
- $value['lower_limit'] = $xianshi_item['lower_limit'];
- $value['explain'] = $xianshi_item['xianshi_explain'];
- }
- }
- // images
- $goods_images = $this->getGoodsImageListEx(array('goods_commonid' => $goods_info['goods_commonid']));
- foreach ($goods_images as $key => &$value) {
- $value['goods_image'] = cthumb($value['goods_image'], 1280);
- }
- $goods_common_info['skus'] = $goods_spec_list;
- $goods_common_info['images'] = $goods_images;
- $result = array();
- $result['request_goods_id'] = $goods_id;
- $result['goods_info'] = $goods_common_info;
- //$result['goods_info']['goods_id'] = $goods_id;
- Log::record(" return 4 result = {$result}.", Log::DEBUG);
- return $result;
- }
- /**
- * 获取单条商品信息
- *
- * @param int $goods_id
- * @return array
- */
- public function getGoodsDetail($goods_id)
- {
- if ($goods_id <= 0) {
- return null;
- }
- $result1 = $this->getGoodsInfoAndPromotionById($goods_id);
- if (empty($result1)) {
- return null;
- }
- $result2 = $this->getGoodeCommonInfoByID($result1['goods_commonid']);
- $goods_info = array_merge($result2, $result1);
- $goods_info['spec_value'] = unserialize($goods_info['spec_value']);
- $goods_info['spec_name'] = unserialize($goods_info['spec_name']);
- $goods_info['goods_spec'] = unserialize($goods_info['goods_spec']);
- $goods_info['goods_attr'] = unserialize($goods_info['goods_attr']);
- // 手机商品描述
- if ($goods_info['mobile_body'] != '') {
- $mobile_body_array = unserialize($goods_info['mobile_body']);
- if (is_array($mobile_body_array)) {
- $mobile_body = '';
- foreach ($mobile_body_array as $val) {
- switch ($val['type']) {
- case 'text':
- $mobile_body .= '<div>' . $val['value'] . '</div>';
- break;
- case 'image':
- $mobile_body .= '<img src="' . $val['value'] . '">';
- break;
- }
- }
- $goods_info['mobile_body'] = $mobile_body;
- }
- }
- // 查询所有规格商品
- $spec_array = $this->getGoodsSpecListByCommonId($goods_info['goods_commonid']);
- $spec_list = array(); // 各规格商品地址,js使用
- $spec_list_mobile = array(); // 各规格商品地址,js使用
- $spec_image = array(); // 各规格商品主图,规格颜色图片使用
- foreach ($spec_array as $key => $value) {
- $s_array = unserialize($value['goods_spec']);
- $tmp_array = array();
- if (!empty($s_array) && is_array($s_array)) {
- foreach ($s_array as $k => $v) {
- $tmp_array[] = $k;
- }
- }
- sort($tmp_array);
- $spec_sign = implode('|', $tmp_array);
- $tpl_spec = array();
- $tpl_spec['sign'] = $spec_sign;
- $tpl_spec['url'] = urlShop('goods', 'index', array('goods_id' => $value['goods_id']));
- $spec_list[] = $tpl_spec;
- //$spec_list_mobile[$spec_sign] = $value['goods_id'];
- $spec_list_mobile[$spec_sign] = $value;
- $spec_image[$value['color_id']] = thumb($value, 60);
- }
- $spec_list = json_encode($spec_list);
- // 商品多图
- $image_more = $this->getGoodsImageByKey($goods_info['goods_commonid'] . '|' . $goods_info['color_id']);
- $goods_image = array();
- $goods_image_mobile = array();
- if (!empty($image_more)) {
- foreach ($image_more as $val) {
- $goods_image[] = "{ title : '', levelA : '" . cthumb($val['goods_image'], 60, $goods_info['store_id']) . "', levelB : '" . cthumb($val['goods_image'], 360, $goods_info['store_id']) . "', levelC : '" . cthumb($val['goods_image'], 360, $goods_info['store_id']) . "', levelD : '" . cthumb($val['goods_image'], 1280, $goods_info['store_id']) . "'}";
- $goods_image_mobile[] = cthumb($val['goods_image'], 360, $goods_info['store_id']);
- }
- } else {
- $goods_image[] = "{ title : '', levelA : '" . thumb($goods_info, 60) . "', levelB : '" . thumb($goods_info, 360) . "', levelC : '" . thumb($goods_info, 360) . "', levelD : '" . thumb($goods_info, 1280) . "'}";
- $goods_image_mobile[] = thumb($goods_info, 360);
- }
- //抢购
- if (!empty($goods_info['groupbuy_info'])) {
- $goods_info['promotion_type'] = 'groupbuy';
- $goods_info['title'] = '抢购';
- $goods_info['remark'] = $goods_info['groupbuy_info']['remark'];
- $goods_info['promotion_price'] = $goods_info['groupbuy_info']['groupbuy_price'];
- $goods_info['down_price'] = ncPriceFormat($goods_info['goods_price'] - $goods_info['groupbuy_info']['groupbuy_price']);
- $goods_info['upper_limit'] = $goods_info['groupbuy_info']['upper_limit'];
- unset($goods_info['groupbuy_info']);
- }
- //限时折扣
- if (!empty($goods_info['xianshi_info'])) {
- $goods_info['promotion_type'] = 'xianshi';
- $goods_info['title'] = $goods_info['xianshi_info']['xianshi_title'];
- $goods_info['remark'] = $goods_info['xianshi_info']['xianshi_title'];
- $goods_info['promotion_price'] = $goods_info['xianshi_info']['xianshi_price'];
- $goods_info['down_price'] = ncPriceFormat($goods_info['goods_price'] - $goods_info['xianshi_info']['xianshi_price']);
- $goods_info['lower_limit'] = $goods_info['xianshi_info']['lower_limit'];
- $goods_info['explain'] = $goods_info['xianshi_info']['xianshi_explain'];
- unset($goods_info['xianshi_info']);
- }
- // 验证是否允许送赠品
- if ($this->checkGoodsIfAllowGift($goods_info)) {
- $gift_array = Model('goods_gift')->getGoodsGiftListByGoodsId($goods_id);
- if (!empty($gift_array)) {
- $goods_info['have_gift'] = 'gift';
- }
- }
- // 加入购物车按钮
- $goods_info['cart'] = true;
- //虚拟、F码、预售不显示加入购物车
- if ($goods_info['is_virtual'] == 1 || $goods_info['is_fcode'] == 1 || $goods_info['is_presell'] == 1) {
- $goods_info['cart'] = false;
- }
- // 立即购买文字显示
- $goods_info['buynow_text'] = '立即购买';
- if ($goods_info['is_presell'] == 1) {
- $goods_info['buynow_text'] = '预售购买';
- } elseif ($goods_info['is_fcode'] == 1) {
- $goods_info['buynow_text'] = 'F码购买';
- }
- //满即送
- $mansong_info = ($goods_info['is_virtual'] == 1) ? array() : Model('p_mansong')->getMansongInfoByStoreID($goods_info['store_id']);
- // 商品受关注次数加1
- $goods_info['goods_click'] = intval($goods_info['goods_click']) + 1;
- if (C('cache_open')) {
- $this->_wGoodsCache($goods_id, array('goods_click' => $goods_info['goods_click']));
- wcache('updateRedisDate', array($goods_id => $goods_info['goods_click']), 'goodsClick');
- } else {
- $this->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
- }
- $result = array();
- $result['goods_info'] = $goods_info;
- $result['spec_list'] = $spec_list;
- $result['spec_list_mobile'] = $spec_list_mobile;
- $result['spec_image'] = $spec_image;
- $result['goods_image'] = $goods_image;
- $result['goods_image_mobile'] = $goods_image_mobile;
- $result['mansong_info'] = $mansong_info;
- $result['gift_array'] = $gift_array;
- return $result;
- }
- public function getMobileBodyByCommonID($goods_commonid, $fields = 'mobile_body')
- {
- $common_info = $this->_rGoodsCommonCache($goods_commonid, $fields);
- if (empty($common_info)) {
- $common_info = $this->getGoodeCommonInfo(array('goods_commonid' => $goods_commonid));
- $this->_wGoodsCommonCache($goods_commonid, $common_info);
- }
- // 手机商品描述
- if ($common_info['mobile_body'] != '') {
- $mobile_body_array = unserialize($common_info['mobile_body']);
- if (is_array($mobile_body_array)) {
- $mobile_body = '';
- foreach ($mobile_body_array as $val) {
- switch ($val['type']) {
- case 'text':
- $mobile_body .= '<div>' . $val['value'] . '</div>';
- break;
- case 'image':
- $mobile_body .= '<img src="' . $val['value'] . '">';
- break;
- }
- }
- $common_info['mobile_body'] = $mobile_body;
- }
- }
- return $common_info;
- }
- public function click_goods($goods_id)
- {
- QueueClient::push('click_goods',['goods_id' => $goods_id]);
- }
- }
|