function toDelivery()
 {
     $order_id = $_POST['order_id'];
     $_POST['opid'] = $this->system->op_id;
     $_POST['opname'] = $this->system->op_name;
     $objOrder =& $this->system->loadModel('trading/order');
     $aItems = $objOrder->getItemList($_POST['order_id'], '', true);
     foreach ($_POST['send'] as $k => $v) {
         if ($aItems[0]['store'] < $v) {
             $store_statues = 1;
         }
     }
     if (!$store_staues) {
         $store_time_type = $this->system->getConf('system.store.time');
         if ($store_time_type == '3') {
             $oScare = new mdl_scare();
             if ($oScare->getOrderStastus($order_id, 'ship_status')) {
                 $scare_goods = $oScare->getOrderGoodsById($order_id);
                 if (isset($scare_goods)) {
                     foreach ($scare_goods as $k => $v) {
                         $oScare->reduceCount($v['goods_id'], $v['nums']);
                     }
                 }
             }
         }
     }
 }
 function check_order()
 {
     $order_id = $_POST['order_id'];
     $scareModel = new mdl_scare();
     $ordermodel =& $this->system->loadModel('trading/order');
     $order = $ordermodel->getList('*', array('order_id' => $order_id));
     $goodstr = $order[0]['tostr'];
     $goodlist = explode(',', $goodstr);
     foreach ($goodlist as $k => $good) {
         $pstr = strpos($good, '(限时抢购商品)');
         if ($pstr) {
             $goodsinfo = explode('@|', $good);
             $good = $goodsinfo[0] . '@|' . $goodsinfo[1] . '@|';
             $goods_id = $goodsinfo[1];
             $scareinfo = $scareModel->getScareByGoodsId($goods_id);
             $count = $scareModel->getScareOrder($good, $scareinfo);
             $num = explode('(', $goodsinfo[2]);
             $nums = explode(')', $num[1]);
             $allcount = $count + $nums[0];
             if ($allcount > $scareinfo['count']) {
                 $this->splash('failed', $_SERVER["HTTP_REFERER"], __('订单中限时抢购商品已售完,无法付款'));
             }
         }
     }
 }
示例#3
0
文件: cart.mdl.php 项目: noikiy/cxe
 function limitGoodsInCart($cart, &$limitGoodsCart)
 {
     $scareModel = new mdl_scare();
     foreach ($cart as $k => $c) {
         $tmp = explode('-', $k);
         $scareInfo = $scareModel->getFieldByGoodsId($tmp[0]);
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['scare_count'] > 0) {
             $limitGoodsCart[$k] = $c;
         }
     }
     return $limitGoodsCart ? true : false;
 }
示例#4
0
文件: order.mdl.php 项目: noikiy/cxe
 function create(&$aCart, &$aMember, &$aDelivery, &$aPayment, &$minfo, &$postInfo)
 {
     //$oSale = &$this->system->loadModel('trading/sale');
     $oSale =& new sale_mdl();
     $trading = $oSale->getCartObject($aCart, $aMember['member_lv_id'], true, true);
     //保存收货人地址
     $this->_saveAddr($aMember['member_id'], $aDelivery);
     $iProduct = 0;
     if (is_array($trading['products']) && count($trading['products'])) {
         $objGoods =& $this->system->loadModel('trading/goods');
         //生成订单前检查库存
         $objCart =& $this->system->loadModel('trading/cart');
         $arr = array();
         $aLinkId = array();
         foreach ($trading['products'] as $k => $p) {
             $aStore = $objGoods->getFieldById($p['goods_id'], array('marketable', 'disabled'));
             if ($aStore['marketable'] == 'false' || $aStore['disabled'] == 'true') {
                 /**
                  * trigger Smarty error
                  *
                  * @param string $error_msg
                  * @param integer $error_type
                  */
                 trigger_error($p['name'] . __('商品未发布不能下单。'), E_USER_ERROR);
                 return false;
                 exit;
             }
             if ($this->freez_time() == 'order') {
                 if (!$objCart->_checkStore($p['product_id'], $p['nums'])) {
                     trigger_error("商品“" . $p['name'] . "”库存不足", E_USER_ERROR);
                     return false;
                     exit;
                 }
             }
             //判断配件库存to检查变量
             if (count($p['adjList'])) {
                 foreach ($p['adjList'] as $pid => $num) {
                     if (!$objCart->_checkStore($pid, $num * $p['nums'])) {
                         trigger_error("商品配件库存不足", E_USER_ERROR);
                         return false;
                         exit;
                     }
                 }
             }
             $arr[] = $p['name'] . '(' . $p['nums'] . ')';
             $this->itemnum += $p['nums'];
             $aLinkId[] = $p['goods_id'];
             $trading['products'][$k]['addon']['minfo'] = $minfo[$p['product_id']];
             //将商品用户信息存入addon
             $trading['products'][$k]['minfo'] = $minfo[$p['product_id']];
             //将商品用户信息存入addon
             if ($p['goods_id']) {
                 $aP[] = $p['goods_id'];
             }
             $iProduct++;
         }
     }
     if ($trading['package'] || $trading['gift_e']) {
         $otherPhysical = true;
     } else {
         $otherPhysical = false;
     }
     if (count($aP) || $otherPhysical) {
         $return = $this->checkOrderDelivery($aP, $aDelivery, $otherPhysical, $aMember['member_id']);
         //检测实体商品配送信息的合法性
         if ($return) {
             $aDelivery['is_delivery'] = $return;
             if ($return == 'Y' && empty($aDelivery['shipping_id'])) {
                 trigger_error(__("提交不成功,请选择配送方式"), E_USER_ERROR);
                 return false;
                 exit;
             }
         } else {
             trigger_error(__("对不起,请完整填写配送信息"), E_USER_ERROR);
             return false;
             exit;
         }
     }
     $iPackage = 0;
     if (is_array($trading['package']) && count($trading['package'])) {
         $objCart =& $this->system->loadModel('trading/cart');
         foreach ($trading['package'] as $v) {
             if (!$objCart->_checkStore($v['goods_id'], $v['nums'])) {
                 trigger_error(__("捆绑商品库存不足"), E_USER_ERROR);
                 return false;
                 exit;
             }
             $iPackage++;
             $arr[] = $v['name'] . '(' . $v['nums'] . ')';
         }
     }
     if (is_array($trading['gift_e']) && count($trading['gift_e'])) {
         foreach ($trading['gift_e'] as $v) {
             $arr[] = $v['name'] . '(' . $v['nums'] . ')';
         }
     }
     if ($iProduct + $iPackage + count($trading['gift_p']) + count($trading['gift_e']) == 0) {
         trigger_error(__("购物车中无有效商品!"), E_USER_ERROR);
         return false;
     }
     //        $objProduct->updateRate($aLinkId);    //更新商品推荐度
     $oCur =& $this->system->loadModel('system/cur');
     $tdelivery = explode(':', $aDelivery['ship_area']);
     $area_id = $tdelivery[count($tdelivery) - 1];
     $oDelivery =& $this->system->loadModel('trading/delivery');
     $rows = $oDelivery->getDlTypeByArea($area_id, $trading['weight'], $aDelivery['shipping_id']);
     if ($trading['exemptFreight'] == 1) {
         //[exemptFreight] => 1免运费
         $aDelivery['cost_freight'] = 0;
     } else {
         $trading['cost_freight'] = $oCur->formatNumber(cal_fee($rows[0]['expressions'], $trading['weight'], $trading['pmt_b']['totalPrice'], $rows[0]['price']), false);
     }
     $trading['cost_freight'] = is_null($trading['cost_freight']) ? 0 : $trading['cost_freight'];
     if ($aDelivery['is_protect'][$aDelivery['shipping_id']] && $rows[0]['protect'] == 1) {
         $aDelivery['cost_protect'] = $oCur->formatNumber(max($trading['totalPrice'] * $rows[0]['protect_rate'], $rows[0]['minprice']), false);
         $aDelivery['is_protect'] = 'true';
     } else {
         $aDelivery['cost_protect'] = 0;
         $aDelivery['is_protect'] = 'false';
     }
     if ($aPayment['payment'] > 0 || $aPayment['payment'] == -1) {
         $oPayment =& $this->system->loadModel('trading/payment');
         $aPay = $oPayment->getPaymentById($aPayment['payment']);
         if ($aPay['pay_type'] == 'DEPOSIT' && $aMember['member_id'] == "") {
             trigger_error(__("未登录客户不能选择预存款支付!"), E_USER_ERROR);
             return false;
         }
         $config = unserialize($aPay['config']);
         $aPayment['fee'] = $aPay['fee'];
         if ($config['method'] == 2) {
             $aPayment['fee'] = $config['fee'];
             $aPayment['method'] = $config['method'];
         }
     } else {
         trigger_error(__("提交不成功,未选择支付方式!"), E_USER_ERROR);
         return false;
     }
     $currency = $oCur->getcur($aPayment['currency'], true);
     $aPayment['currency'] = $currency['cur_code'];
     if (!$this->checkPoint($aMember['member_id'], $trading)) {
         return false;
     }
     if (!$this->checkGift($trading['gift_p'])) {
         unset($trading['gift_p']);
         //直接不给
     }
     $orderInfo = $trading;
     $orderInfo['order_id'] = $this->gen_id();
     $orderInfo['cur_rate'] = $currency['cur_rate'] > 0 ? $currency['cur_rate'] : 1;
     $orderInfo['tostr'] = implode(',', $arr);
     $orderInfo['itemnum'] = $this->itemnum;
     getRefer($orderInfo);
     //推荐下单
     $aDelivery['ship_time'] = ($aDelivery['day'] == 'specal' ? $aDelivery['specal_day'] : $aDelivery['day']) . ' ' . $aDelivery['time'];
     $orderInfo = array_merge($orderInfo, $aDelivery, $aPayment);
     if ($aMember) {
         $orderInfo = array_merge($orderInfo, $aMember);
     }
     //限时抢购 减少库存
     $scareModel = new mdl_scare();
     foreach ($orderInfo['products'] as $k => $p) {
         $scareInfo = $scareModel->getFieldByGoodsId($p['goods_id']);
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['scare_count'] > 0) {
             //限时抢购于系统关联预展库存 2011-7-7 by zhangxuehui
             $store_time_type = $this->system->getConf('system.store.time');
             $p['nums'] = $store_time_type == '1' || $store_time_type == '0' ? $p['nums'] : '0';
             //限时抢购于系统关联预展库存 2011-7-7 by zhangxuehui
             $scareModel->reduceCount($p['goods_id'], $p['nums']);
         }
     }
     //end
     return $this->save($orderInfo, true, $postInfo);
 }
示例#5
0
文件: sale.mdl.php 项目: noikiy/cxe
 function _load_g(&$trading, $cart_g)
 {
     $oMath =& $this->system->loadModel('system/math');
     $product_ids = array();
     foreach ($cart_g['cart'] as $strKey => $num) {
         $aRow = explode('-', $strKey);
         if ($aRow[1] != '') {
             $product_ids[] = $aRow[1];
         }
     }
     reset($cart_g);
     if (count($product_ids) > 0) {
         $aProduct = $this->db->select('SELECT p.*,t.setting,g.score,g.brand_id,g.cat_id,g.type_id,g.image_default,g.thumbnail_pic,g.goods_id
                 FROM sdb_products AS p
                 LEFT JOIN sdb_goods AS g ON p.goods_id=g.goods_id
                 LEFT JOIN sdb_goods_type AS t ON g.type_id=t.type_id
                 WHERE p.product_id IN (' . implode(',', $product_ids) . ')');
     } else {
         $aProduct = array();
     }
     foreach ($aProduct as $k => $p) {
         if ($this->_mlvid) {
             $aMprice = $this->db->selectrow('SELECT price, dis_count FROM sdb_member_lv
                     LEFT JOIN sdb_goods_lv_price ON level_id = member_lv_id AND product_id=' . intval($p['product_id']) . '
                     WHERE member_lv_id=' . intval($this->_mlvid));
             if (floatval($aMprice['dis_count']) <= 0) {
                 $aMprice['dis_count'] = 1;
             }
         } else {
             $aMprice['dis_count'] = 1;
         }
         $items_g[$p['product_id']]['bn'] = $p['bn'] ? $p['bn'] : $this->system->getConf('system.product.autobn.prefix') . str_pad($p['product_id'] + $this->system->getConf('system.product.autobn.beginnum', 100), $this->system->getConf('system.product.autobn.length'), 0, STR_PAD_LEFT);
         $items_g[$p['product_id']]['sale_price'] = $p['price'];
         //限时抢购
         $scareModel = new mdl_scare();
         $scareInfo = $scareModel->getFieldByGoodsId($p['goods_id']);
         //特定时间生效
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['is_special_time'] == 1 && $scareInfo['scare_count'] > 0) {
             $specialTime = unserialize($scareInfo['special_time_bucket']);
             foreach ($specialTime as $key => $value) {
                 if ($value['week'] == date('N')) {
                     $today_special_time[] = $value;
                     //今天的限时抢购
                 }
             }
             if ($today_special_time) {
                 //求得最先开始的时间
                 foreach ($today_special_time as $key => $tTime) {
                     //过滤过时时间段
                     if (time() >= strtotime(date('y-m-d')) + $tTime['ethour']) {
                         continue;
                     }
                     if (time() >= strtotime(date('Y-m-d')) + $tTime['sthour'] && time() < strtotime(date('Y-m-d')) + $tTime['ethour']) {
                         if (!isset($today_min_stime)) {
                             $today_min_stime = $today_special_time[$key]['sthour'];
                             $today_min_stime_key = $key;
                         }
                         //$today_min_stime_key=($today_min_stime>$tTime['sthour']) ? $key : $initializeKey ;
                         if ($today_min_stime > $tTime['sthour']) {
                             $today_min_stime = $tTime['sthour'];
                             $today_min_stime_key = $key;
                         }
                     }
                 }
                 //$scareInfo['time']=strtotime(date('Y-m-d'))+$today_special_time[$today_min_stime_key]['ethour']-strtotime('now');
                 if (!isset($today_min_stime_key)) {
                     unset($scareInfo);
                 }
             } else {
                 unset($scareInfo);
             }
         }
         //计算限时抢购价
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['scare_count'] > 0) {
             $items_g[$p['product_id']]['name'] = $p['name'] . '(限时抢购商品)' . '@|' . $scareInfo['goods_id'] . '@|';
             if (!is_null($scareInfo['goodscore']) && $scareInfo['goodscore'] != '') {
                 $items_g[$p['product_id']]['limitGoodsScore'] = $scareInfo['goodscore'];
             }
             if ($scareInfo['is_mprice'] == 1) {
                 $scareMprice = unserialize($scareInfo['scare_mprice']);
                 $items_g[$p['product_id']]['price'] = $scareMprice[$this->_mlvid] ? $scareMprice[$this->_mlvid] : $oMath->getOperationNumber($oMath->getOperationNumber($scareInfo['scare_price']) * $aMprice['dis_count']);
             } else {
                 $items_g[$p['product_id']]['price'] = $scareInfo['scare_price'];
             }
         } else {
             $items_g[$p['product_id']]['name'] = $p['name'] . ($p['pdt_desc'] ? ' (' . $p['pdt_desc'] . ')' : '');
             $items_g[$p['product_id']]['price'] = $aMprice['price'] ? $aMprice['price'] : $oMath->getOperationNumber($oMath->getOperationNumber($p['price']) * $aMprice['dis_count']);
         }
         //end
         $items_g[$p['product_id']]['type_id'] = $p['type_id'];
         $items_g[$p['product_id']]['weight'] = $p['weight'];
         $items_g[$p['product_id']]['store'] = $p['store'];
         $items_g[$p['product_id']]['cost'] = $p['cost'];
         $items_g[$p['product_id']]['addon'] = array_merge(unserialize($p['props']), unserialize($p['setting']));
         $items_g[$p['product_id']]['pdt_desc'] = $p['pdt_desc'];
         $items_g[$p['product_id']]['goods_id'] = $p['goods_id'];
         $items_g[$p['product_id']]['product_id'] = $p['product_id'];
         $items_g[$p['product_id']]['image_default'] = $p['image_default'];
         $items_g[$p['product_id']]['thumbnail_pic'] = $p['thumbnail_pic'];
         $items_g[$p['product_id']]['score'] = $p['score'];
     }
     unset($aProduct);
     $oCur =& $this->system->loadModel('system/cur');
     $aItems = array();
     //循环处理购物车各商品
     foreach ($cart_g['cart'] as $strKey => $num) {
         $aRow = explode('-', $strKey);
         //如果存在商品id
         if ($aRow[0] != '' && $items_g[$aRow[1]]) {
             $strName = '';
             //初始化显示名称
             $adjPrice = 0;
             //初始化配件价格
             $adjCost = 0;
             //初始化配件成本价格
             $adjWeight = 0;
             //如果存在配件
             $adjList = array();
             //初始化配件购买量数组 array(<配件id>=><购买量>)
             if ($aRow[2] != 'na') {
                 $aAdj = explode('|', $aRow[2]);
                 //取配件配置列表,配件格式:配件id_配件组_配件数量|
                 $tmpAdjList = array();
                 $tmpAdjGrp = array();
                 $tmpAdjId = array();
                 //初始化配件id数组(<product_id>=>array(<id1>,<id2>...))
                 $strAdj = '';
                 foreach ($aAdj as $val) {
                     $adjItem = explode('_', $val);
                     if ($adjItem[0] > 0 && $adjItem[2] > 0) {
                         $tmpAdjList[] = $adjItem[2];
                         //设置配件购买量
                         $tmpAdjGrp[] = $adjItem[1];
                         //配件栏位
                         $tmpAdjId['product_id'][] = $adjItem[0];
                         //配件id数组
                     }
                 }
                 if (count($tmpAdjId)) {
                     $objGoods =& $this->system->loadModel('trading/goods');
                     $strAdjunct = $objGoods->getGoodsMemo($aRow[0], 'adjunct');
                     //取本商品配件栏位定义
                     $aAdj = unserialize($strAdjunct);
                     $objProduct =& $this->system->loadModel('goods/finderPdt');
                     $adjName = $objProduct->getList('product_id, name, price, cost, weight', $tmpAdjId, 0, -1);
                     if ($adjName) {
                         foreach ($adjName as $val) {
                             //处理各配件
                             $aAdjuncts[$val['product_id']] = $val;
                         }
                         foreach ($tmpAdjId['product_id'] as $key => $pid) {
                             if ($aAdj[$tmpAdjGrp[$key]] && $aAdjuncts[$pid]) {
                                 //如果存在对应栏位定义 和 商品库中存在这个配件
                                 //描述文字 = +配件名称(购买量)
                                 $strName .= '+' . $aAdjuncts[$pid]['name'] . '(' . $tmpAdjList[$key] . ')';
                                 //如果本栏位设定了配件价格的优惠金额
                                 if ($aAdj[$tmpAdjGrp[$key]]['set_price'] == 'minus') {
                                     //配件总价 += (配件销售价+设定的配件调整额)*配件购买量
                                     $adjPrice += $oMath->minus(array($aAdjuncts[$pid]['price'], $aAdj[$tmpAdjGrp[$key]]['price'])) * $tmpAdjList[$key];
                                 } else {
                                     //否则即为折扣方式
                                     //配件总价 += 配件销售价*购买量*设定的优惠倍率
                                     $adjDiscount = abs($aAdj[$tmpAdjGrp[$key]]['price']) ? abs($aAdj[$tmpAdjGrp[$key]]['price']) : 1;
                                     $adjPrice += $oMath->getOperationNumber($oMath->getOperationNumber($aAdjuncts[$pid]['price']) * $tmpAdjList[$key] * $adjDiscount);
                                 }
                                 $adjList[$pid] += $tmpAdjList[$key];
                                 $strAdj .= $pid . '_' . $tmpAdjGrp[$key] . '_' . $tmpAdjList[$key] . '|';
                                 $adjCost += $oMath->getOperationNumber($aAdjuncts[$pid]['cost']) * $tmpAdjList[$key];
                                 $adjWeight += $aAdjuncts[$pid]['weight'] * $tmpAdjList[$key];
                             }
                         }
                     } else {
                         $strAdj = 'na';
                     }
                 } else {
                     $strAdj = 'na';
                 }
             } else {
                 $strAdj = 'na';
             }
             $strKey = $aRow[0] . '-' . $aRow[1] . '-' . $strAdj;
             $linkKey = $aRow[0] . '@' . $aRow[1] . '@' . $strAdj;
             //重组货品字符串
             $aGoods = $items_g[$aRow[1]];
             $aGoods['addon']['adjinfo'] = $strAdj;
             //= 配件id_配件组序号_配件数量|
             $aGoods['addon']['adjname'] = $strName;
             //用于描述文字 +配件名称(购买量)
             $aGoods['adjList'] = $adjList;
             //array(<配件id>=><购买量>)
             $aGoods['price'] = $oMath->plus(array($aGoods['price'], $adjPrice));
             //+配件总价
             $aGoods['cost'] = $oMath->plus(array($aGoods['cost'], $adjCost));
             //+配件总成本价
             $aGoods['amount'] = $oMath->getOperationNumber($aGoods['price']) * $num;
             $aGoods['price'] = $oCur->formatNumber($aGoods['price'], false);
             $aGoods['key'] = $strKey;
             //存在购物车数组的key
             $aGoods['link_key'] = $linkKey;
             //存在购物车数组的key
             $aGoods['enkey'] = base64_encode($strKey);
             $aGoods['nums'] = $num;
             $aGoods['pmt_id'] = intval($cart_g['pmt'][$aRow[0]]);
             $aGoods['weight'] += $adjWeight;
             switch ($this->system->getConf('point.get_policy')) {
                 case 0:
                     $aGoods['score'] = 0;
                     break;
                 case 1:
                     $aGoods['score'] = $aGoods['price'] * $this->system->getConf('point.get_rate');
                     break;
                 default:
                     break;
             }
             //限时抢购商品积分
             if (isset($aGoods['limitGoodsScore'])) {
                 $aGoods['score'] = $aGoods['limitGoodsScore'];
                 unset($aGoods['limitGoodsScore']);
             }
             //end
             $aItems[] = $aGoods;
             $trading['totalPrice'] = $oMath->plus(array($trading['totalPrice'], $aGoods['amount']));
             $trading['totalGainScore'] += $aGoods['score'] * $num;
             $trading['weight'] += $aGoods['weight'] * $num;
         }
     }
     unset($items_g);
     $trading['products'] =& $aItems;
 }
示例#6
0
 function addGoodsToCart($gid = 0, $pid = 0, $stradj = '', $pmtid = 0, $num = 1)
 {
     $aParams = $this->objCart->getParams($_POST['goods'], $gid, $pid, $stradj, $pmtid);
     //限时抢购
     $scareModel = new mdl_scare();
     $scareInfo = $scareModel->getFieldByGoodsId($gid);
     $scareCart = $this->objCart->getCart();
     $scarenum_id = 0;
     foreach ($scareCart['g'] as $k => $v) {
         foreach ($v as $kal => $val) {
             $kala = explode('-', $kal);
             if ($gid != 0) {
                 if ($kala[0] == $gid) {
                     $scarenum_id = $scarenum_id + $val;
                 }
             } else {
                 if ($kala[0] == $_POST['goods']['goods_id']) {
                     $scarenum_id = $scarenum_id + $val;
                 }
             }
         }
     }
     if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now')) {
         if ($scareInfo['buycountlimit']) {
             if (!$_POST['goods']['num']) {
                 $goods_nums = $scarenum_id + $num;
             } else {
                 $goods_nums = $scarenum_id + $_POST['goods']['num'];
             }
             if (intval($scareInfo['buycountlimit']) < intval($goods_nums)) {
                 $this->begin($_SERVER['HTTP_REFERER']);
                 $this->setError(10003);
                 if ($_POST['mini_cart']) {
                     header("HTTP/1.0 404 Not Found");
                 }
                 trigger_error('加入购物车失败:超出限购数量!', E_USER_ERROR);
                 $this->end();
                 exit;
             }
         }
     }
     if ($aParams['pid'] == -1) {
         $this->begin($_SERVER['HTTP_REFERER']);
         trigger_error(__('加入购物车失败:无此货品'), E_USER_ERROR);
         $this->end();
     }
     $_num = intval($aParams['num']);
     if ($_num) {
         $num = $_num;
     } else {
         $num = intval($num);
     }
     if (!$num) {
         $num = 1;
     }
     $status = $this->objCart->addToCart('g', $aParams, $num);
     if ($status === 'notify') {
         $this->begin($this->system->mkUrl("product", "gnotify", array($gid, $pid)));
         $this->setError(10001);
         if ($_POST['mini_cart']) {
             header("HTTP/1.0 404 Not Found");
         }
         trigger_error(__('加入购物车失败:商品缺货,转入缺货登记'), E_USER_ERROR);
         $this->end();
     } elseif (!$status) {
         $this->begin($_SERVER['HTTP_REFERER']);
         $this->setError(10002);
         if ($_POST['mini_cart']) {
             header("HTTP/1.0 404 Not Found");
         }
         trigger_error(__('加入购物车失败: 商品库存不足或者提交参数错误!'), E_USER_ERROR);
         $this->end();
     } else {
         if ($_POST['fastbuy']) {
             $this->checkout();
         } else {
             if ($_POST['mini_cart']) {
                 $this->view(1);
                 exit;
             }
             $this->redirect('cart');
         }
     }
     //parent::addGoodsToCart($gid=0, $pid=0, $stradj='', $pmtid=0, $num=1);
 }
 function toAdd()
 {
     $data = $_POST['goods'];
     $data['spec_desc'] = urldecode($data['spec_desc']);
     //        $data['spec_desc'] = addslashes_array($data['spec_desc']);
     $data['params'] = stripslashes_array($data['params']);
     if (!$data['goods_id']) {
         unset($data['goods_id']);
     }
     switch ($_GET['but']) {
         case 3:
             if ($data['goods_id']) {
                 $but_type = 'edit';
                 $url_href = 'index.php?ctl=goods/product&act=edit&p[0]=' . $data['goods_id'];
             } else {
                 $but_type = 'new';
                 $url_href = 'index.php?ctl=goods/product&act=index';
             }
             break;
         case 1:
             //$url_href = 'index.php?ctl=goods/product&act=addNew&p[0]='.$data['cat_id'].'&p[1]='.$data['type_id'].'&p[2]='.$data['brand_id'];
             $url_href = 'index.php?ctl=goods/product&act=addNew&p[0]=&p[1]=';
             break;
         default:
             $url_href = 'index.php?ctl=goods/product&act=index';
             break;
     }
     $this->begin($url_href);
     if (count(explode('.', $_POST['scareInfo']['goodscore'])) >= 2) {
         $this->end(false, __('积分请用整数'));
         exit;
     }
     if (is_array($_POST['bn'])) {
         foreach ($_POST['bn'] as $aTmpBnk => $aTmpBn) {
             $_POST['bn'][$aTmpBnk] = trim($aTmpBn);
         }
     }
     $data['bn'] = trim($data['bn']);
     $data['product_bn'] = trim($data['product_bn']);
     $image_file = $data['image_file'];
     unset($data['image_file']);
     $udfimg = $data['udfimg'];
     unset($data['udfimg']);
     $data['marketable'] = $data['marketable'] ? $data['marketable'] : false;
     $data['adjunct'] = $_POST['adjunct'];
     if (count($_POST['price']) > 0) {
         //开启规格 多货品
         foreach ($_POST['vars'] as $vark => $varv) {
             $data['spec'][$vark] = $varv;
         }
         $data['spec'] = serialize($data['spec']);
         $sameProFlag = array();
         foreach ($_POST['price'] as $k => $price) {
             //设置销售多货品销售价等价格
             $data['price'] = $data['price'] ? min($price, $data['price']) : $price;
             //取最小商品价格
             $data['cost'] = $data['cost'] ? min($_POST['cost'][$k], $data['cost']) : $_POST['cost'][$k];
             $data['weight'] = $data['weight'] ? min($_POST['weight'][$k], $data['weight']) : $_POST['weight'][$k];
             if (!$_POST['mktprice'][$k]) {
                 //没有市场价
                 $oMath =& $this->system->loadModel('system/math');
                 if ($this->system->getConf('site.show_mark_price')) {
                     if ($this->system->getConf('site.market_price') == '1') {
                         $_POST['mktprice'][$k] = $this->system->getConf('site.market_rate') * $oMath->getOperationNumber($price);
                     }
                     if ($this->system->getConf('site.market_price') == '2') {
                         $_POST['mktprice'][$k] = $this->system->getConf('site.market_rate') + $oMath->getOperationNumber($price);
                     }
                 }
             }
             $products[$k]['price'] = $price;
             $products[$k]['bn'] = $_POST['bn'][$k];
             $products[$k]['store'] = trim($_POST['store'][$k]) === '' ? null : intval($_POST['store'][$k]);
             $products[$k]['alert'] = $_POST['alert'][$k];
             $products[$k]['cost'] = $_POST['cost'][$k];
             $products[$k]['weight'] = $_POST['weight'][$k];
             $products[$k]['mktprice'] = $_POST['mktprice'][$k];
             $products[$k]['store_place'] = $_POST['store_place'][$k];
             $products[$k]['marketable'] = $_POST['marketable'][$k];
             //数量
             $store += $products[$k]['store'];
             //end
             $data['mktprice'] = $data['mktprice'] ? min($_POST['mktprice'][$k], $data['mktprice']) : $_POST['mktprice'][$k];
             $newSpecI = 0;
             $proSpecFlag = '';
             foreach ($_POST['vars'] as $i => $v) {
                 $products[$k]['props']['spec'][$i] = urldecode(trim($_POST['val'][$i][$k]));
                 //array('规格(颜色)序号'=>'规格值(红色)')
                 $products[$k]['props']['spec_private_value_id'][$i] = trim($_POST['pSpecId'][$i][$k]);
                 $products[$k]['props']['spec_value_id'][$i] = trim($_POST['specVId'][$i][$k]);
                 if (trim($products[$k]['props']['spec'][$i]) === '') {
                     trigger_error(__('请为所有货品定义规格值'), E_USER_ERROR);
                     $this->end(false, __('请为所有货品定义规格值'));
                     exit;
                 }
                 $proSpecFlag .= $products[$k]['props']['spec_private_value_id'][$i] . '_';
             }
             if (in_array($proSpecFlag, $sameProFlag)) {
                 trigger_error(__('不能添加相同规格货品'), E_USER_ERROR);
                 $this->end(false, __('不能添加相同规格货品'));
                 exit;
             }
             $sameProFlag[$k] = $proSpecFlag;
             reset($proSpecFlag);
             reset($_POST['vars'], $_POST['pSpecId']);
             $products[$k]['pdt_desc'] = implode('、', $products[$k]['props']['spec']);
             //物品描述
             $products[$k]['pdt_desc'] = addslashes_array($products[$k]['pdt_desc']);
             foreach ($_POST['idata'] as $i => $v) {
                 $products[$k]['props']['idata'][$i] = $v[$k];
             }
             //设置会员价格
             if (is_array($_POST['mprice'])) {
                 foreach ($_POST['mprice'] as $levelid => $rows) {
                     $products[$k]['mprice'][$levelid] = floatval($rows[$k]);
                 }
             }
         }
         unset($sameProFlag);
         $data['products'] =& $products;
     } else {
         if (!$data['mktprice']) {
             $oMath =& $this->system->loadModel('system/math');
             if ($this->system->getConf('site.show_mark_price')) {
                 if ($this->system->getConf('site.market_price') == '1') {
                     $data['mktprice'] = $this->system->getConf('site.market_rate') * $oMath->getOperationNumber($data['price']);
                 }
                 if ($this->system->getConf('site.market_price') == '2') {
                     $data['mktprice'] = $this->system->getConf('site.market_rate') + $oMath->getOperationNumber($data['price']);
                 }
             }
         }
         $data['props']['idata'] = $_POST['idata'];
         //数量
         $store = $data['store'];
         //end
     }
     $objGoods =& $this->system->loadModel('trading/goods');
     foreach ($products as $k => $p) {
         if (empty($p['bn'])) {
             continue;
         }
         if ($objGoods->checkProductBn($p['bn'], $data['goods_id'])) {
             trigger_error(__('您所填写的货号已被使用,请检查!'), E_USER_ERROR);
             $this->end(false, __('您所填写的货号已被使用,请检查!'));
             exit;
         }
         $aBn[] = $p['bn'];
     }
     if (!empty($data['product_bn'])) {
         if ($objGoods->checkProductBn($data['product_bn'], $data['goods_id'])) {
             trigger_error(__('您所填写的货号已被使用,请检查!'), E_USER_ERROR);
             $this->end(false, __('您所填写的货号已被使用,请检查!'));
             exit;
         }
     }
     if (count($aBn) > count(array_unique($aBn))) {
         trigger_error(__('您所填写的货号已被使用,请检查!'), E_USER_ERROR);
         $this->end(false, __('您所填写的货号已被使用,请检查!'));
         exit;
     }
     if (!$data['type_id']) {
         $objCat =& $this->system->loadModel('goods/productCat');
         $aCat = $objCat->getFieldById($data['cat_id'], array('type_id'));
         $data['type_id'] = $aCat['type_id'];
     }
     //限时抢购
     if ($_POST['goods']['iflimit'] == 1) {
         if ($store) {
             if ($store < $_POST['scareInfo']['scare_count']) {
                 trigger_error(__('您所填写的限购数量超出库存,请检查!'), E_USER_ERROR);
                 $this->end(false, __('您所填写的限购数量超出库存,请检查!'));
                 exit;
             }
         }
         if (!empty($_POST['scareInfo']['s_hour'])) {
             if (!preg_match('/^[0-1]?[0-9]|2[0-3]:[0-5][0-9]$/', $_POST['scareInfo']['s_hour'])) {
                 trigger_error(__('请正确填写时间格式!'), E_USER_ERROR);
                 $this->end(false, __('请正确填写时间格式!'));
                 exit;
             }
             $_POST['scareInfo']['s_hour'] = explode(':', $_POST['scareInfo']['s_hour']);
         }
         if (!empty($_POST['scareInfo']['e_hour'])) {
             if (!preg_match('/^[0-1]?[0-9]|2[0-3]:[0-5][0-9]$/', $_POST['scareInfo']['e_hour'])) {
                 trigger_error(__('请正确填写时间格式!'), E_USER_ERROR);
                 $this->end(false, __('请正确填写时间格式!'));
                 exit;
             }
             $_POST['scareInfo']['e_hour'] = explode(':', $_POST['scareInfo']['e_hour']);
         }
         $data['s_time'] = strtotime($_POST['scareInfo']['s_date']) + intval($_POST['scareInfo']['s_hour'][0]) * 3600 + intval($_POST['scareInfo']['s_hour'][1]) * 60;
         $data['e_time'] = strtotime($_POST['scareInfo']['e_date']) + intval($_POST['scareInfo']['e_hour'][0]) * 3600 + intval($_POST['scareInfo']['e_hour'][1]) * 60;
         if ($data['s_time'] >= $data['e_time']) {
             trigger_error(__('您所填写的结束时间小于开始时间,请检查!'), E_USER_ERROR);
             $this->end(false, __('您所填写的结束时间小于开始时间,请检查!'));
             exit;
         }
         $special_time_bucket = array();
         if ($_POST['scareInfo']['is_special_time'] == 1) {
             $_POST['scareInfo']['specialTime'] = array_unique($_POST['scareInfo']['specialTime']);
             foreach ($_POST['specialTime'] as $key => $value) {
                 if ($value == '1|-1|-1') {
                     trigger_error(__('所填写的时间格式有误,请检查!'), E_USER_ERROR);
                     $this->end(false, __('所填写的时间格式有误,请检查!'));
                     exit;
                 }
                 $special_time = explode('|', $value);
                 if (!preg_match('/^[0-1]?[0-9]|2[0-3]:[0-5][0-9]$/', $special_time[1])) {
                     trigger_error(__('所填写的时间格式有误,请检查!'), E_USER_ERROR);
                     $this->end(false, __('所填写的时间格式有误,请检查!'));
                     exit;
                 }
                 if (!preg_match('/^[0-1]?[0-9]|2[0-3]:[0-5][0-9]$/', $special_time[2])) {
                     trigger_error(__('所填写的时间格式有误,请检查!'), E_USER_ERROR);
                     $this->end(false, __('所填写的时间格式有误,请检查!'));
                     exit;
                 }
                 $special_stime = explode(':', $special_time[1]);
                 $special_etime = explode(':', $special_time[2]);
                 $special_stime = intval($special_stime[0]) * 3600 + intval($special_stime[1]) * 60;
                 $special_etime = intval($special_etime[0]) * 3600 + intval($special_etime[1]) * 60;
                 if ($special_stime >= $special_etime) {
                     trigger_error(__('生效结束时间必须大于生效开始时间!'), E_USER_ERROR);
                     $this->end(false, __('生效结束时间必须大于生效开始时间!'));
                     exit;
                 }
                 $special_time_bucket[$key]['week'] = $special_time[0];
                 $special_time_bucket[$key]['sohour'] = $special_time[1];
                 $special_time_bucket[$key]['sthour'] = $special_stime;
                 $special_time_bucket[$key]['eohour'] = $special_time[2];
                 $special_time_bucket[$key]['ethour'] = $special_etime;
                 $special_time_bucket[$key]['original'] = $value;
                 //$special_time_bucket[]=$special_time[0].'|'.$special_stime.'|'.$special_etime;
             }
         }
     } else {
         $data['s_time'] = 0;
         $data['e_time'] = 0;
     }
     //end
     if (!($gid = $objGoods->save($data))) {
         $this->end(false, __('保存失败,请重试!'));
         exit;
     }
     //限时抢购
     $scareModel = new mdl_scare();
     if ($_POST['goods']['iflimit'] == 1) {
         $scareData = $_POST['scareInfo'];
         $scareData['goods_id'] = $gid;
         $scareData['s_time'] = $data['s_time'];
         $scareData['e_time'] = $data['e_time'];
         $scareData['iflimit'] = $_POST['goods']['iflimit'];
         $scareData['special_time_bucket'] = serialize($special_time_bucket);
         unset($pt);
         if ($scareData['forenotice_on'] == 1) {
             $scareData['forenotice_time'] = intval($scareData['forenotice_hour']) * 3600 + intval($scareData['forenotice_min']) * 60 + intval($scareData['forenotice_sec']);
         } else {
             $scareData['forenotice_time'] = 0;
         }
         if ($scareData['is_mprice'] == 1) {
             $memberLevel =& $this->system->loadModel('member/level');
             $memberLevel_scare = $memberLevel->getList('member_lv_id,name,dis_count,name');
             foreach ($_POST['scareMprice'] as $mlevel => $mprice) {
                 $scareData['scare_mprice'][$mlevel] = $mprice;
                 if (!$scareData['scare_mprice'][$mlevel]) {
                     foreach ($memberLevel_scare as $level) {
                         if ($mlevel == $level['member_lv_id']) {
                             $level['dis_count'] = $level['dis_count'] > 0 ? $level['dis_count'] : 1;
                             $scareData['scare_mprice'][$mlevel] = $level['dis_count'] * $_POST['scareInfo']['scare_price'];
                         }
                     }
                 }
             }
             $scareData['scare_mprice'] = $scareData['scare_mprice'] ? serialize($scareData['scare_mprice']) : 'null';
         }
         $scareData['count'] = $scareData['scare_count'];
         $scareModel->save($scareData);
     } else {
         $scareModel->delByGoodsId($gid);
     }
     //end
     $scheduled = array();
     $now = time();
     foreach ($_POST['scheduled'] as $time => $action) {
         if ($time > $now) {
             $scheduled[] = array('tasktime' => $time, 'action' => $action);
         }
     }
     $objGoods->set_auto_task($gid, $scheduled);
     $keywords = array();
     foreach ($objGoods->getKeywords($gid) as $keywordvalue) {
         $keywords[] = $keywordvalue['keyword'];
     }
     $keyword = implode('|', $keywords);
     if ($keyword != $_POST['keywords']['keyword']) {
         $objGoods->deleteKeywords($gid);
         if ($_POST['keywords']['keyword']) {
             $objGoods->addKeywords($gid, explode('|', $_POST['keywords']['keyword']));
         }
     }
     //处理商品图片
     $gimage =& $this->system->loadModel('goods/gimage');
     $gimage->saveImage($data['goods_id'], $data['db_thumbnail_pic'], $_POST['image_default'], $image_file, $udfimg, $_FILES);
     //相关商品
     foreach ($_POST['linkid'] as $k => $id) {
         $aLink[] = array('goods_1' => $data['goods_id'], 'goods_2' => $id, 'manual' => $_POST['linktype'][$id], 'rate' => 100);
     }
     $objProduct =& $this->system->loadModel('goods/products');
     $objProduct->toInsertLink($data['goods_id'], $aLink);
     /*
     * tag独立处理
     //处理TAG
     $objTag = &$this->system->loadModel('system/tag');
     $objTag->removeObjTag($data['goods_id']);
     foreach(space_split($_POST['tags']) as $tagName){
     $tagName = trim($tagName);
     if($tagName){
     if(!($tagid = $objTag->getTagByName('goods', $tagName))){
     $tagid = $objTag->newTag($tagName, 'goods');
     }
     $objTag->addTag($tagid, $data['goods_id']);
     }
     }
     */
     $oSupplier = $this->system->loadModel('distribution/supplier');
     if ($_POST['supplier_id']) {
         $newBn = array();
         if (isset($_POST['bn']) && is_array($_POST['bn'])) {
             foreach ($_POST['bn'] as $nbnk => $nbnv) {
                 $newBn[$_POST['old_bn'][$nbnk]] = $nbnv;
                 unset($_POST['source_bn'][$_POST['old_bn'][$nbnk]]);
             }
         } else {
             $newBn[$_POST['old_bn']] = $_POST['goods']['product_bn'];
             unset($_POST['src_bn']);
         }
         $oSupplier->updateSupplierPdtBn($newBn, $_POST['source_bn'], $_POST['supplier_id']);
     }
     if (isset($_POST['commandType'])) {
         if (in_array($_POST['commandType'], array('4', '5', '6'))) {
             $oSupplier->updateSyncStatus($_POST['command_id'], $_POST['supplier_id'], 'done');
         }
     }
     $oseo =& $this->system->loadModel('system/seo');
     $aData = array('keywords' => $_POST['goods']['seo']['meta_keywords'], 'descript' => $_POST['goods']['seo']['meta_description'], 'title' => $_POST['goods']['seo']['seo_title']);
     $oseo->set_seo('goods', $gid, $aData);
     //###
     if ($but_type == 'new') {
         $this->end(true, __('保存成功') . '<input type=hidden id="g_id" value=' . $gid . '>', 'index.php?ctl=goods/product&act=edit&p[0]=' . $gid);
     } else {
         if ($_GET['but'] == 1) {
             $this->end(true, __('保存成功') . '<input type=hidden id="g_id" value=' . $gid . '>', $url_href . $gid);
         } else {
             $this->end(true, __('保存成功') . '<input type=hidden id="g_id" value=' . $gid . '>');
         }
     }
 }
 function index($view, $cat_id = '', $urlFilter = null, $orderBy = 0, $tab = null, $page = 1, $cat_type = null)
 {
     if ($orderBy == 5 || $orderBy == 6) {
         $this->noCache = true;
     }
     if ($cat_type) {
         $this->type = 'virtualcat';
         $this->cat_type = $cat_type;
         $virtualCat =& $this->system->loadModel('goods/virtualcat');
         $vcat = $virtualCat->instance($cat_type);
         //print_r($vcat);exit;
         parse_str($vcat['filter'], $type_filter);
     }
     $this->customer_template_type = 'gallery';
     $this->customer_template_id = $cat_id;
     $urlFilter = htmlspecialchars(urldecode($urlFilter));
     if ($cat_id == '_ANY_') {
         unset($cat_id);
     }
     if ($cat_id) {
         $cat_id = explode(",", $cat_id);
         foreach ($cat_id as $k => $v) {
             if ($v) {
                 $cat_id[$k] = intval($v);
             }
         }
         $this->id = implode(",", $cat_id);
     }
     if (!$cat_id) {
         $cat_id = array('');
         $this->id = '';
     }
     //{{{初始化操作
     $pageLimit = $this->system->getConf('gallery.display.listnum');
     $this->pagedata['pdtPic'] = array('width' => 100, 'heigth' => 100);
     //        $orderBy = (!$orderBy)?3:$orderBy;
     $this->pagedata['args'] = array($this->id, urlencode($urlFilter), $orderBy, $tab, $page, $cat_type);
     $this->pagedata['curView'] = $view;
     $productCat =& $this->system->loadModel('goods/productCat');
     if ($cat_type) {
         $this->pagedata['childnode'] = $virtualCat->getCatParentById($cat_type, $view);
     } else {
         $this->pagedata['childnode'] = $productCat->getCatParentById($cat_id, $view);
     }
     $brandGroup =& $this->system->loadModel('goods/brand');
     $objGoods =& $this->system->loadModel('goods/products');
     $brandResult = $brandGroup->getBrandGroup($cat_id);
     $this->productCat =& $productCat;
     $cat = $productCat->get($cat_id, $view, $type_filter['type_id']);
     //echo "<pre>";print_r($cat);exit;
     if (!in_array($view, $cat['setting']['list_tpl'])) {
         header('Location: ' . $this->system->mkUrl('gallery', current($cat['setting']['list_tpl']), $this->pagedata['args']), true, 301);
     }
     if ($cat_type) {
         $vcat['addon'] = unserialize($vcat['addon']);
         if (trim($vcat['addon']['meta']['keywords'])) {
             $this->keywords = trim($vcat['addon']['meta']['keywords']);
         }
         if (trim($vcat['addon']['meta']['description'])) {
             $this->desc = trim($vcat['addon']['meta']['description']);
         }
         if (trim($vcat['addon']['meta']['title'])) {
             $this->title = trim($vcat['addon']['meta']['title']);
         }
     } else {
         if (trim($cat['addon'])) {
             $cat['addon'] = unserialize($cat['addon']);
             if (trim($cat['addon']['meta']['keywords'])) {
                 $this->keywords = trim($cat['addon']['meta']['keywords']);
             }
             if (trim($cat['addon']['meta']['description'])) {
                 $this->desc = trim($cat['addon']['meta']['description']);
             }
             if (trim($cat['addon']['meta']['title'])) {
                 $this->title = trim($cat['addon']['meta']['title']);
             }
         }
     }
     if ($this->system->getConf('system.seo.noindex_catalog')) {
         $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />';
     }
     $searchtools =& $this->system->loadModel('goods/search');
     $path = array();
     $filter = $searchtools->decode($urlFilter, $path, $cat);
     $this->filter =& $filter;
     /*if(!$cat_type){
       $this->title = $cat['cat_name'];
       }*/
     if (is_array($filter)) {
         $filter = array_merge(array('cat_id' => $cat_id, 'marketable' => 'true'), $filter);
         if (($filter['cat_id'][0] === '' || $filter['cat_id'][0] === null) && !isset($filter['cat_id'][1])) {
             unset($filter['cat_id']);
         }
         if (($filter['tag'][0] === '' || $filter['tag'][0] === null) && !isset($filter['tag'][1])) {
             unset($filter['tag']);
         }
         if (($filter['brand_id'][0] === '' || $filter['brand_id'][0] === null) && !isset($filter['brand_id'][1])) {
             unset($filter['brand_id']);
         }
     } else {
         $filter = array('cat_id' => $cat_id, 'marketable' => 'true');
     }
     //--------获取类型关联的规格
     if ($vcat['type_id']) {
         $type_id = $vcat['type_id'];
     } else {
         $type = $productCat->getFieldById($this->id, array('type_id'));
         $type_id = $type['type_id'];
     }
     $gType =& $this->system->loadModel('goods/gtype');
     $SpecList = $gType->getSpec($type_id, 1);
     //--------
     foreach ($path as $p) {
         $arg = unserialize(serialize($this->pagedata['args']));
         $arg[1] = $p['str'];
         $title = array();
         if (is_numeric($p['type'])) {
             $cat_tmp = $productCat->get($cat_id, $view, $filter['type_id'][0]);
             foreach ($p['data'] as $i) {
                 $name = $cat_tmp['props'][$p['type']]['options'][$i];
                 $title[] = $name ? $name : $i;
                 $tip = $cat_tmp['props'][$p['type']]['name'];
             }
         } elseif ($p['type'] == 'brand_id') {
             $brand = array();
             foreach ($cat['brand'] as $b) {
                 $brand[$b['brand_id']] = $b['brand_name'];
             }
             foreach ($p['data'] as $i) {
                 $title[] = $brand[$i];
                 $tip = __("品牌");
             }
             unset($brand);
         } elseif (substr($p['type'], 0, 2) == 's_') {
             $spec = array();
             foreach ($p['data'] as $spk => $spv) {
                 $tmp = explode(",", $spv);
                 $tip = $SpecList[$tmp[0]]['name'];
                 $title[] = $SpecList[$tmp[0]]['spec_value'][$tmp[1]]['spec_value'];
             }
             $curSpec[$tmp[0]] = $tmp[1];
         }
         $title = implode(',', $title);
         if ($title) {
             //$this->title=' '.$title;
             $this->path[] = array('title' => " " . $title, 'link' => $this->system->mkUrl('gallery', $view, $arg), 'tips' => $tip);
         }
     }
     //-----------
     if ($this->system->getConf('system.seo.noindex_catalog')) {
         $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />';
     }
     $filter['cat_id'] = $cat_id;
     $filter['goods_type'] = 'normal';
     $filter['marketable'] = 'true';
     //-----查找当前类别子类别的关联类型ID
     if ($urlFilter) {
         if ($vcat['type_id']) {
             //$filter['type_id']=$vcat['type_id'];
             $filter['type_id'] = null;
         }
     }
     //--------
     $this->pagedata['tabs'] = $cat['tabs'];
     $this->pagedata['cat_id'] = implode(",", $cat_id);
     $this->pagedata['views'] = $cat['setting']['list_tpl'];
     $this->pagedata['orderBy'] = $objGoods->orderBy();
     if ($cat['tabs'][$tab]) {
         parse_str($cat['tabs'][$tab]['filter'], $_filter);
         $filter = array_merge($filter, $_filter);
     }
     if ($GLOBALS['runtime']['member_lv']) {
         $filter['mlevel'] = $GLOBALS['runtime']['member_lv'];
     }
     if (!isset($this->pagedata['orderBy'][$orderBy])) {
         $this->system->error(404);
     } else {
         $orderby = $this->pagedata['orderBy'][$orderBy]['sql'];
     }
     foreach ($brandResult as $v => $k) {
         $brand_count[$k['brand_id']]['plus'] = $k['brand_cat'];
     }
     $selector = array();
     $search = array();
     if (!is_array($cat_id) && $cat_id || $cat_id[0] || $cat_type) {
         $goods_relate = $objGoods->getList("*", $filter, 0, -1);
     }
     if ($goods_relate) {
         unset($tmpSpecValue);
         foreach ($goods_relate as $grk => $grv) {
             if ($grv['spec_desc']) {
                 $tmpSdesc = unserialize($grv['spec_desc']);
                 if (is_array($tmpSdesc)) {
                     foreach ($tmpSdesc as $tsk => $tsv) {
                         foreach ($tsv as $tk => $tv) {
                             if (!in_array($tv['spec_value_id'], $tmpSpecValue)) {
                                 $tmpSpecValue[] = $tv['spec_value_id'];
                             }
                         }
                     }
                 }
             }
         }
     }
     /***********************/
     if ($SpecList) {
         if ($curSpec) {
             $curSpecKey = array_keys($curSpec);
         }
         foreach ($SpecList as $spk => $spv) {
             $selected = 0;
             /*
                             $existsSV=0;
                             foreach($spv['spec_value'] as $spvk => $spvv){
                             if (!in_array($spvk,$tmpSpecValue))
                             unset($spv['spec_value'][$spvk]);
                             else
                             $existsSV=1;
                             }
                             if ($existsSV){*/
             if ($curSpecKey && in_array($spk, $curSpecKey)) {
                 $spv['spec_value'][$curSpec[$spk]]['selected'] = true;
                 $selected = 1;
             }
             if ($spv['spec_style'] == "select") {
                 //下拉
                 $SpecSelList[$spk] = $spv;
                 if ($selected) {
                     $SpecSelList[$spk]['selected'] = true;
                 }
             } elseif ($spv['spec_style'] == "flat") {
                 $SpecFlatList[$spk] = $spv;
                 if ($selected) {
                     $SpecFlatList[$spk]['selected'] = true;
                 }
             }
             //}
         }
     }
     $this->pagedata['SpecFlatList'] = $SpecFlatList;
     $this->pagedata['specimagewidth'] = $this->system->getConf('spec.image.width');
     $this->pagedata['specimageheight'] = $this->system->getConf('spec.image.height');
     /************************/
     if (is_array($cat['brand'])) {
         foreach ($cat['brand'] as $bk => $bv) {
             $bCount = 0;
             $brand = array('name' => __('品牌'), 'value' => array_flip($filter['brand_id']));
             foreach ($goods_relate as $gk => $gv) {
                 if ($gv['brand_id']) {
                     if ($gv['brand_id'] == $bv['brand_id']) {
                         $bCount++;
                     }
                 }
             }
             if ($bCount > 0) {
                 $tmpOp[$bv['brand_id']] = $bv['brand_name'] . "<span class='num'>(" . $bCount . ")</span>";
             }
         }
         $brand['options'] = $tmpOp;
         $selector['brand_id'] = $brand;
     }
     foreach ($cat['props'] as $prop_id => $prop) {
         if ($prop['search'] == 'select') {
             $prop['options'] = array_merge($prop['options']);
             $prop['value'] = $filter['p_' . $prop_id][0];
             $searchSelect[$prop_id] = $prop;
         } elseif ($prop['search'] == 'input') {
             $prop['value'] = $filter['p_' . $prop_id][0];
             $searchInput[$prop_id] = $prop;
         } elseif ($prop['search'] == 'nav') {
             $prop['value'] = array_flip($filter['p_' . $prop_id]);
             $plugadd = array();
             foreach ($goods_relate as $k => $v) {
                 if ($v["p_" . $prop_id] != null) {
                     if ($plugadd[$v["p_" . $prop_id]]) {
                         $plugadd[$v["p_" . $prop_id]] = $plugadd[$v["p_" . $prop_id]] + 1;
                     } else {
                         $plugadd[$v["p_" . $prop_id]] = 1;
                     }
                 }
                 $aFilter['goods_id'][] = $v['goods_id'];
                 //当前的商品结果集
             }
             $navselector = 0;
             foreach ($prop['options'] as $q => $e) {
                 if ($plugadd[$q]) {
                     $prop['options'][$q] = $prop['options'][$q] . "<span class='num'>(" . $plugadd[$q] . ")</span>";
                     if (!$navselector) {
                         $navselector = 1;
                     }
                 } else {
                     unset($prop['options'][$q]);
                 }
             }
             $selector[$prop_id] = $prop;
         }
     }
     if ($navselector) {
         $nsvcount = 0;
         $noshow = 0;
         foreach ($selector as $sk => $sv) {
             if ($sv['value']) {
                 $nsvcount++;
             }
             if (is_numeric($sk) && !$sv['show']) {
                 $noshow++;
             }
         }
         if ($nsvcount == intval(count($selector) - $noshow)) {
             $navselector = 0;
         }
     }
     foreach ($cat['spec'] as $spec_id => $spec_name) {
         $sId['spec_id'][] = $spec_id;
     }
     $cat['ordernum'] = $cat['ordernum'] ? $cat['ordernum'] : array('' => 2);
     if ($cat['ordernum']) {
         if ($selector) {
             foreach ($selector as $key => $val) {
                 if (!in_array($key, $cat['ordernum']) && $val) {
                     $selectorExd[$key] = $val;
                 }
             }
         }
     }
     $selector['ordernum'] = $cat['ordernum'];
     $objGoods->appendCols .= ',big_pic';
     /*appendCols big_pic update 2009年9月25日13:46:45*/
     $aProduct = $objGoods->getList(null, $filter, $pageLimit * ($page - 1), $pageLimit, $orderby);
     //限时抢购
     $scareModel = new mdl_scare();
     foreach ($aProduct as $k => $p_scare) {
         $scareInfo = $scareModel->getFieldByGoodsId($p_scare['goods_id']);
         $fscareInfo = $scareInfo;
         if ($fscareInfo && strtotime('now') < $fscareInfo['s_time'] && strtotime('now') + $fscareInfo['forenotice_time'] > $fscareInfo['s_time'] && $fscareInfo['forenotice_on'] == 1) {
             $aProduct[$k]['scareInfo_forenotice']['forenotice_time'] = $this->tran_time($fscareInfo['s_time'], strtotime('now'));
             $aProduct[$k]['scareInfo_forenotice']['forenotice_key'] = 1;
             if ($fscareInfo['is_mprice'] == 1 && $_COOKIE['MLV']) {
                 $scareMprice = unserialize($fscareInfo['scare_mprice']);
                 $fscareInfo['scare_price'] = $scareMprice[$_COOKIE['MLV']];
             }
             $aProduct[$k]['scareInfo_forenotice']['price'] = $fscareInfo['scare_price'];
         }
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['scare_count'] > 0) {
             if ($scareInfo['is_mprice'] && $_COOKIE['MLV']) {
                 $scareMprice = unserialize($scareInfo['scare_mprice']);
                 $scareInfo['scare_price'] = $scareMprice[$_COOKIE['MLV']];
             }
             //特定时间生效
             if ($scareInfo['is_special_time'] == 1) {
                 $specialTime = unserialize($scareInfo['special_time_bucket']);
                 foreach ($specialTime as $key => $value) {
                     if ($value['week'] == date('N')) {
                         $today_special_time[] = $value;
                         //今天的限时抢购
                     }
                 }
                 if ($today_special_time) {
                     //求得最先开始的时间
                     foreach ($today_special_time as $key => $tTime) {
                         //过滤过时时间段
                         if (time() >= strtotime(date('y-m-d')) + $tTime['ethour']) {
                             continue;
                         }
                         if (time() >= strtotime(date('Y-m-d')) + $tTime['sthour'] && time() < strtotime(date('Y-m-d')) + $tTime['ethour']) {
                             if (!isset($today_min_stime)) {
                                 $today_min_stime = $today_special_time[$key]['sthour'];
                                 $today_min_stime_key = $key;
                             }
                             //$today_min_stime_key=($today_min_stime>$tTime['sthour']) ? $key : $initializeKey ;
                             if ($today_min_stime > $tTime['sthour']) {
                                 $today_min_stime = $tTime['sthour'];
                                 $today_min_stime_key = $key;
                             }
                         }
                     }
                     //$scareInfo['time']=strtotime(date('Y-m-d'))+$today_special_time[$today_min_stime_key]['ethour']-strtotime('now');
                     if (!isset($today_min_stime_key)) {
                         unset($scareInfo);
                     }
                 } else {
                     unset($scareInfo);
                 }
             }
             if (ceil($scareInfo['scare_price']) == 0) {
                 unset($scareInfo['scare_price']);
             }
             $aProduct[$k]['scareInfo'] = $scareInfo;
         }
     }
     //end
     //  print_r($aProduct);exit;
     $count = $objGoods->count($filter);
     $this->pagedata['mask_webslice'] = $this->system->getConf('system.ui.webslice') ? ' hslice' : null;
     $this->pagedata['searchInput'] =& $searchInput;
     $this->pagedata['selectorExd'] = $selectorExd;
     $this->cat_id = $cat_id;
     $this->_plugins['function']['selector'] = array(&$this, '_selector');
     $this->pagedata['pager'] = array('current' => $page, 'total' => ceil($count / $pageLimit), 'link' => $this->system->mkUrl('gallery', $view, array(implode(',', $cat_id), urlencode($p['str']), $orderBy, $tab, $tmp = time(), $cat_type)), 'token' => $tmp);
     if ($page != 1 && $page > $this->pagedata['pager']['total']) {
         $this->system->error(404);
     }
     if (!$count) {
         $this->pagedata['emtpy_info'] = $this->system->getConf('errorpage.searchempty');
     }
     $objImage =& $this->system->loadModel('goods/gimage');
     $this->pagedata['searchtotal'] = $count;
     if (is_array($aProduct) && count($aProduct) > 0) {
         $objGoods->getSparePrice($aProduct, $GLOBALS['runtime']['member_lv']);
         if ($this->system->getConf('site.show_mark_price')) {
             $setting['mktprice'] = $this->system->getConf('site.market_price');
         } else {
             $setting['mktprice'] = 0;
         }
         $setting['saveprice'] = $this->system->getConf('site.save_price');
         $setting['buytarget'] = $this->system->getConf('site.buy.target');
         $this->pagedata['setting'] = $setting;
         $this->pagedata['products'] =& $aProduct;
     }
     //print_r($this->pagedata['products']);exit;
     if ($GLOBALS['runtime']['member_lv'] < 0) {
         $this->pagedata['LOGIN'] = '******';
     }
     if ($SpecSelList) {
         $this->pagedata['SpecSelList'] = $SpecSelList;
     }
     if ($searchSelect) {
         $this->pagedata['searchSelect'] =& $searchSelect;
     }
     $this->pagedata['selector'] =& $selector;
     $this->pagedata['cat_type'] = $cat_type;
     $this->pagedata['search_array'] = implode("+", $GLOBALS['search_array']);
     //$this->pagedata['_PDT_LST_TPL'] = 'file:'.$cat['tpl'];
     //$this->pagedata['_PDT_LST_TPL'] = 'file:D:\www\485_2\src\plugins\app\scareBuying\view\shop\gallery\type\list.html';
     //var_dump($this->pagedata['_PDT_LST_TPL']);exit;
     $s_view = $view == 'index' ? 'list' : $view;
     $this->pagedata['_PDT_LST_TPL'] = 'file:' . dirname(__FILE__) . '/view/shop/gallery/type/' . $s_view . '.html';
     //var_dump(dirname(__FILE__).'/view/shop/gallery/type/'.$view.'.html');exit;
     //$this->pagedata['_MAIN_'] = 'gallery/index.html';
     $this->pagedata['_MAIN_'] = dirname(__FILE__) . '/view/shop/gallery/index.html';
     $this->pagedata['localhostpic_url'] = dirname('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
     $this->getGlobal($this->seoTag, $this->pagedata);
     $this->output();
 }
 function index($gid, $specImg = '', $spec_id = '')
 {
     $appmgr = $this->system->loadModel('system/appmgr');
     $status = $appmgr->getPluginInfoByident('group_activity', 'disabled');
     if ($status['disabled'] == 'false') {
         $group_activity_model_test = $this->system->loadModel('plugins/group_activity/group_activity');
         $group_activity_model_test->chgStateByGid($gid);
         $goodsActivityInfo_test = $group_activity_model_test->getOpenActivityByGid($gid);
     }
     if ($goodsActivityInfo_test) {
         require_once PLUGIN_DIR . '/app/group_activity/group_activity_shop_ctl_product.php';
         $group_activity_ctl_product = new group_activity_shop_ctl_product();
         $group_activity_ctl_product->index($gid, $specImg, $spec_id);
     } else {
         //限时抢购
         $scareModel = new mdl_scare();
         $scareInfo = $scareModel->getFieldByGoodsId($gid);
         //print_r($scareInfo);exit;
         $fscareInfo = $scareInfo;
         if ($scareInfo && $scareInfo['iflimit'] == 1 && $scareInfo['e_time'] > strtotime('now') && $scareInfo['s_time'] < strtotime('now') && $scareInfo['scare_count'] > 0) {
             if ($scareInfo['is_mprice'] == 1 && $_COOKIE['MLV']) {
                 $scareMprice = unserialize($scareInfo['scare_mprice']);
                 $scareInfo['scare_price'] = $scareMprice[$_COOKIE['MLV']];
                 $this->pagedata['scareInfo_forenotice']['price'] = $scareInfo['scare_price'];
             }
             $scareInfo['time'] = $this->tran_time($scareInfo['e_time'], strtotime('now'));
             //特定时间生效
             if ($scareInfo['is_special_time'] == 1) {
                 $specialTime = unserialize($scareInfo['special_time_bucket']);
                 foreach ($specialTime as $key => $value) {
                     if ($value['week'] == date('N')) {
                         $today_special_time[] = $value;
                         //今天的限时抢购
                     }
                 }
                 if ($today_special_time) {
                     //求得最先开始的时间
                     foreach ($today_special_time as $key => $tTime) {
                         if (time() >= strtotime(date('y-m-d')) + $tTime['ethour']) {
                             continue;
                         }
                         if (time() >= strtotime(date('y-m-d')) + $tTime['sthour'] && time() < strtotime(date('y-m-d')) + $tTime['ethour']) {
                             if (!isset($today_min_stime)) {
                                 $today_min_stime = $today_special_time[$key]['sthour'];
                                 $today_min_stime_key = $key;
                             }
                             if ($today_min_stime > $tTime['sthour']) {
                                 $today_min_stime = $tTime['sthour'];
                                 $today_min_stime_key = $key;
                             }
                             //$today_min_stime=($today_min_stime>$tTime['sthour']) ? $tTime['sthour'] : $today_min_stime;
                             //$today_min_stime_key=($today_min_stime>$tTime['sthour']) ? $key : $today_min_stime_key ;
                         }
                         if (time() < strtotime(date('y-m-d')) + $tTime['sthour']) {
                             if (!isset($today_min_stime)) {
                                 $today_min_stime = $today_special_time[$key]['sthour'];
                             }
                             $today_min_stime = $today_min_stime > $tTime['sthour'] ? $tTime['sthour'] : $today_min_stime;
                         }
                     }
                     if (isset($today_min_stime_key)) {
                         $scareInfo['time'] = $this->tran_time(strtotime(date('Y-m-d')) + $today_special_time[$today_min_stime_key]['ethour'], strtotime('now'));
                     } else {
                         unset($scareInfo);
                     }
                 } else {
                     unset($scareInfo);
                 }
             }
             if (ceil($scareInfo['scare_price']) == 0) {
                 unset($scareInfo['scare_price']);
             }
             $this->pagedata['scareInfo'] = $scareInfo;
         }
         if ($today_min_stime && !isset($today_min_stime_key)) {
             $fscareInfo['s_time'] = strtotime(date('Y-m-d')) + $today_min_stime;
         }
         $this->pagedata['js_url'] = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php?action_scarebuying.html';
         //限时抢购倒计时开始
         if ($fscareInfo && strtotime('now') < $fscareInfo['s_time'] && strtotime('now') + $fscareInfo['forenotice_time'] > $fscareInfo['s_time'] && $fscareInfo['forenotice_on'] == 1) {
             $this->pagedata['scareInfo_forenotice']['forenotice_time'] = $fscareInfo['s_time'];
             $this->pagedata['scareInfo_forenotice']['forenotice_key'] = 1;
             if ($fscareInfo['is_mprice'] == 1 && $_COOKIE['MLV']) {
                 $scareMprice = unserialize($fscareInfo['scare_mprice']);
                 $fscareInfo['scare_price'] = $scareMprice[$_COOKIE['MLV']];
             }
             $this->pagedata['scareInfo_forenotice']['price'] = $fscareInfo['scare_price'];
         }
         unset($fscareInfo);
         //end
         $this->pagedata['_MAIN_'] = dirname(__FILE__) . '/view/shop/product/index.html';
         //parent::index($gid,$specImg,$spec_id);
         $this->id = $gid;
         $this->customer_source_type = 'product';
         $this->customer_template_type = 'product';
         $this->customer_template_id = $gid;
         $oseo =& $this->system->loadModel('system/seo');
         $seo_info = $oseo->get_seo('goods', $gid);
         $this->title = $seo_info['title'] ? $seo_info['title'] : $this->system->getConf('site.goods_title');
         $this->keywords = $seo_info['keywords'] ? $seo_info['keywords'] : $this->system->getConf('site.goods_meta_key_words');
         $this->desc = $seo_info['descript'] ? $seo_info['descript'] : $this->system->getConf('site.goods_meta_desc');
         $member_lv = intval($this->system->request['member_lv']);
         $objProduct =& $this->system->loadModel('goods/products');
         $objGoods =& $this->system->loadModel('trading/goods');
         if (!($aGoods = $objGoods->getGoods($gid, $member_lv))) {
             $this->system->responseCode(404);
         }
         if ($aGoods['goods_type'] == 'bind') {
             //如果捆绑商品跳转到捆绑列表
             $this->redirect('package', 'index');
             exit;
         }
         if (!$aGoods || $aGoods['disabled'] == 'true' || empty($aGoods['products']) && empty($aGoods['product_id'])) {
             $this->system->error(404);
             exit;
         }
         $objCat =& $this->system->loadModel('goods/productCat');
         $aCat = $objCat->getFieldById($aGoods['cat_id'], array('cat_name', 'addon'));
         $aCat['addon'] = unserialize($aCat['addon']);
         if ($aGoods['seo']['meta_keywords']) {
             if (empty($this->keyWords)) {
                 $this->keyWords = $aGoods['seo']['meta_keywords'];
             }
         } else {
             if (trim($aCat['addon']['meta']['keywords'])) {
                 $this->keyWords = trim($aCat['addon']['meta']['keywords']);
             }
         }
         if ($aGoods['seo']['meta_description']) {
             $this->metaDesc = $aGoods['seo']['meta_description'];
         } else {
             if (trim($aCat['addon']['meta']['description'])) {
                 $this->metaDesc = trim($aCat['addon']['meta']['description']);
             }
         }
         $tTitle = (empty($aGoods['seo']['seo_title']) ? $aGoods['name'] : $aGoods['seo']['seo_title']) . (empty($aCat['cat_name']) ? "" : " - " . $aCat['cat_name']);
         if (empty($this->title)) {
             $this->title = $tTitle;
         }
         $objPdtFinder =& $this->system->loadModel('goods/finderPdt');
         foreach ($aGoods['adjunct'] as $key => $rows) {
             //loop group
             if ($rows['set_price'] == 'minus') {
                 $cols = 'product_id,goods_id,name, pdt_desc, store, freez, price, price-' . intval($rows['price']) . ' AS adjprice';
             } else {
                 $cols = 'product_id,goods_id,name, pdt_desc, store, freez, price, price*' . ($rows['price'] ? $rows['price'] : 1) . ' AS adjprice';
             }
             if ($rows['type'] == 'goods') {
                 if (!$rows['items']['product_id']) {
                     $rows['items']['product_id'] = array(-1);
                 }
                 $arr = $rows['items'];
             } else {
                 parse_str($rows['items'] . '&dis_goods[]=' . $gid, $arr);
             }
             if ($aAdj = $objPdtFinder->getList($cols, $arr, 0, -1)) {
                 $aAdjGid = array();
                 foreach ($aAdj as $item) {
                     $aAdjGid['goods_id'][] = $item['goods_id'];
                 }
                 if (!empty($aAdjGid)) {
                     foreach ($objProduct->getList('marketable,disabled', $aAdjGid, 0, 1000) as $item) {
                         $aAdjGid[$item['goods_id']] = $item;
                     }
                     foreach ($aAdj as $k => $item) {
                         $aAdj[$k]['marketable'] = $aAdjGid[$item['goods_id']]['marketable'];
                         $aAdj[$k]['disabled'] = $aAdjGid[$item['goods_id']]['disabled'];
                     }
                 }
                 $aGoods['adjunct'][$key]['items'] = $aAdj;
             } else {
                 unset($aGoods['adjunct'][$key]);
             }
         }
         $this->_plugins['function']['selector'] = array(&$this, '_selector');
         //初始化货品
         if (!empty($aGoods['products'])) {
             foreach ($aGoods['products'] as $key => $products) {
                 $a = array();
                 foreach ($products['props']['spec'] as $k => $v) {
                     $a[] = trim($k) . ':' . trim($v);
                 }
                 $aGoods['products'][$key]['params_tr'] = implode('-', $a);
                 $aPdtIds[] = $products['product_id'];
                 if ($aGoods['price'] > $products['price']) {
                     $aGoods['price'] = $products['price'];
                     //前台默认进来显示商品的最小价格
                 }
             }
         } else {
             $aPdtIds[] = $aGoods['product_id'];
         }
         if ($this->system->getConf('site.show_mark_price')) {
             $aGoods['setting']['mktprice'] = $this->system->getConf('site.market_price');
         } else {
             $aGoods['setting']['mktprice'] = 0;
         }
         $aGoods['setting']['saveprice'] = $this->system->getConf('site.save_price');
         $aGoods['setting']['buytarget'] = $this->system->getConf('site.buy.target');
         $aGoods['setting']['score'] = $this->system->getConf('point.get_policy');
         $aGoods['setting']['scorerate'] = $this->system->getConf('point.get_rate');
         if ($aGoods['setting']['score'] == 1) {
             $aGoods['score'] = intval($aGoods['price'] * $aGoods['setting']['scorerate']);
         }
         /*--------------规格关联商品图片--------------*/
         if (!empty($specImg)) {
             $tmpImgAry = explode("_", $specImg);
             if (is_array($tmpImgAry)) {
                 foreach ($tmpImgAry as $key => $val) {
                     $tImgAry = explode("@", $val);
                     if (is_array($tImgAry)) {
                         $spec[$tImgAry[0]] = $val;
                         $imageGroup[] = substr($tImgAry[1], 0, strpos($tImgAry[1], "|"));
                         $imageGstr .= substr($tImgAry[1], 0, strpos($tImgAry[1], "|")) . ",";
                         $spec_value_id = substr($tImgAry[1], strpos($tImgAry[1], "|") + 1);
                         if ($aGoods['specVdesc'][$tImgAry[0]]['value'][$spec_value_id]['spec_value']) {
                             $specValue[] = $aGoods['specVdesc'][$tImgAry[0]]['value'][$spec_value_id]['spec_value'];
                         }
                         if ($aGoods['FlatSpec'] && array_key_exists($tImgAry[0], $aGoods['FlatSpec'])) {
                             $aGoods['FlatSpec'][$tImgAry[0]]['value'][$spec_value_id]['selected'] = true;
                         }
                         if ($aGoods['SelSpec'] && array_key_exists($tImgAry[0], $aGoods['SelSpec'])) {
                             $aGoods['SelSpec'][$tImgAry[0]]['value'][$spec_value_id]['selected'] = true;
                         }
                     }
                 }
                 if ($imageGstr) {
                     $imageGstr = substr($imageGstr, 0, -1);
                 }
             }
             /****************设置规格链接地址**********************/
             if (is_array($aGoods['specVdesc'])) {
                 foreach ($aGoods['specVdesc'] as $gk => $gv) {
                     if (is_array($gv['value'])) {
                         foreach ($gv['value'] as $gkk => $gvv) {
                             if (is_array($spec)) {
                                 $specId = substr($gvv['spec_goods_images'], 0, strpos($gvv['spec_goods_images'], "@"));
                                 foreach ($spec as $sk => $sv) {
                                     if ($specId != $sk) {
                                         $aGoods['specVdesc'][$gk]['value'][$gkk]['spec_goods_images'] .= "_" . $sv;
                                         if ($aGoods['FlatSpec'] && array_key_exists($gk, $aGoods['FlatSpec'])) {
                                             $aGoods['FlatSpec'][$gk]['value'][$gkk]['spec_goods_images'] .= "_" . $sv;
                                         }
                                         if ($aGoods['SelSpec'] && array_key_exists($gk, $aGoods['SelSpec'])) {
                                             $aGoods['SelSpec'][$gk]['value'][$gkk]['spec_goods_images'] .= "_" . $sv;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             /*************************************/
             //页面提示所选规格名称
             $this->pagedata['SelectSpecValue'] = array('value' => implode("、", $specValue), 'selected' => 1);
         } else {
             if (is_array($aGoods['FlatSpec']) && count($aGoods['FlatSpec']) > 0) {
                 foreach ($aGoods['FlatSpec'] as $agk => $agv) {
                     $specValue[] = $agv['name'];
                 }
             }
             if (is_array($aGoods['SelSpec']) && count($aGoods['SelSpec']) > 0) {
                 foreach ($aGoods['SelSpec'] as $agk => $agv) {
                     $specValue[] = $agv['name'];
                 }
             }
             $this->pagedata['SelectSpecValue'] = array('value' => implode("、", $specValue), 'selected' => 0);
         }
         $this->pagedata['specShowItems'] = $specValue;
         /*--------------*/
         //$gImages=$this->goodspics($gid,$imageGroup,$imageGstr);
         if (is_array($gImages) && count($gImages) > 0) {
             $this->pagedata['images']['gimages'] = $gImages;
         } else {
             /*-------------商品图片--------------*/
             $gimage =& $this->system->loadModel('goods/gimage');
             $this->pagedata['images']['gimages'] = $gimage->get_by_goods_id($gid);
             /*----------------- 8< --------------*/
         }
         //限时抢购
         if ($this->pagedata['scareInfo']) {
             foreach ($aGoods['product2spec'] as $k => $ps) {
                 $aGoods['product2spec'][$k]['store'] = $this->pagedata['scareInfo']['scare_count'];
                 //$aGoods['product2spec'][$k]['price']=$this->pagedata['scareInfo']['scare_price'];
             }
         }
         //end
         /********-------------------*********/
         $aGoods['product2spec'] = json_encode($aGoods['product2spec']);
         $aGoods['spec2product'] = json_encode($aGoods['spec2product']);
         $this->pagedata['goods'] = $aGoods;
         if ($this->pagedata['goods']['products']) {
             $priceArea = array();
             if ($_COOKIE['MLV']) {
                 $MLV = $_COOKIE['MLV'];
             } else {
                 $level =& $this->system->loadModel('member/level');
                 $MLV = $level->getDefauleLv();
             }
             if ($MLV) {
                 foreach ($this->pagedata['goods']['products'] as $gpk => $gpv) {
                     $priceArea[] = $gpv['mprice'][$MLV];
                     $mktpriceArea[] = $gpv['mktprice'];
                 }
                 if (count($priceArea) > 1) {
                     $minprice = min($priceArea);
                     $maxprice = max($priceArea);
                     if ($minprice != $maxprice) {
                         $this->pagedata['goods']['minprice'] = $minprice;
                         $this->pagedata['goods']['maxprice'] = $maxprice;
                     }
                 }
                 if (count($mktpriceArea) > 1) {
                     $mktminprice = min($mktpriceArea);
                     $mktmaxprice = max($mktpriceArea);
                     if ($mktminprice != $mktmaxprice) {
                         $this->pagedata['goods']['minmktprice'] = $mktminprice;
                         $this->pagedata['goods']['maxmktprice'] = $mktmaxprice;
                     }
                 }
                 //增加了市场价范围
             }
             //计算货品冻结库存总和
             foreach ($this->pagedata['goods']['products'] as $key => $val) {
                 $totalFreez += $val['freez'];
             }
         } else {
             $totalFreez = $this->pagedata['goods']['freez'];
         }
         $mLevelList = $objProduct->getProductLevel($aPdtIds);
         $this->pagedata['mLevel'] = $mLevelList;
         /**** begin 商品品牌 ****/
         if ($this->pagedata['goods']['brand_id'] > 0) {
             $brandObj =& $this->system->loadModel('goods/brand');
             $aBrand = $brandObj->getFieldById($this->pagedata['goods']['brand_id'], array('brand_name'));
         }
         $this->pagedata['goods']['brand_name'] = $aBrand['brand_name'];
         /**** begin 商品品牌 ****/
         /**** begin 商品评论 ****/
         $aComment['switch']['ask'] = $this->system->getConf('comment.switch.ask');
         $aComment['switch']['discuss'] = $this->system->getConf('comment.switch.discuss');
         foreach ($aComment['switch'] as $item => $switchStatus) {
             if ($switchStatus == 'on') {
                 $objComment =& $this->system->loadModel('comment/comment');
                 $commentList = $objComment->getGoodsIndexComments($gid, $item);
                 $aComment['list'][$item] = $commentList['data'];
                 $aComment[$item . 'Count'] = $commentList['total'];
                 $aId = array();
                 if ($commentList['total']) {
                     foreach ($aComment['list'][$item] as $rows) {
                         $aId[] = $rows['comment_id'];
                     }
                     if (count($aId)) {
                         $aReply = $objComment->getCommentsReply($aId, true);
                     }
                     reset($aComment['list'][$item]);
                     foreach ($aComment['list'][$item] as $key => $rows) {
                         foreach ($aReply as $rkey => $rrows) {
                             if ($rows['comment_id'] == $rrows['for_comment_id']) {
                                 $aComment['list'][$item][$key]['items'][] = $aReply[$rkey];
                             }
                         }
                         reset($aReply);
                     }
                 } else {
                     $aComment['null_notice'][$item] = $this->system->getConf('comment.null_notice.' . $item);
                 }
             }
         }
         $this->pagedata['comment'] = $aComment;
         /**** end 商品评论 ****/
         /**** begin 相关商品 ****/
         $aLinkId['goods_id'] = array();
         foreach ($objGoods->getLinkList($gid) as $rows) {
             if ($rows['goods_1'] == $gid) {
                 $aLinkId['goods_id'][] = $rows['goods_2'];
             } else {
                 $aLinkId['goods_id'][] = $rows['goods_1'];
             }
         }
         if (count($aLinkId['goods_id']) > 0) {
             $aLinkId['marketable'] = 'true';
             $objProduct =& $this->system->loadModel('goods/products');
             $this->pagedata['goods']['link'] = $objProduct->getList('*', $aLinkId, 0, 500);
             $this->pagedata['goods']['link_count'] = $objProduct->count($aLinkId);
         }
         /**** end 相关商品 ****/
         //更多商品促销活动
         $PRICE = $this->pagedata['goods']['price'];
         //todo 此处PRICE 为会员价格,需要统一接口
         $oPromotion =& $this->system->loadModel('trading/promotion');
         $aPmt = $oPromotion->getGoodsPromotion($gid, $this->pagedata['goods']['cat_id'], $this->pagedata['goods']['brand_id'], $member_lv);
         if ($aPmt) {
             $this->pagedata['goods']['pmt_id'] = $aPmt['pmt_id'];
             $arr = $oPromotion->getPromotionList($aPmt['pmta_id']);
             $MLV = $_COOKIE['MLV'];
             foreach ($arr as $keys => $vals) {
                 $arr[$keys]['pmt_solution'] = unserialize($arr[$keys]['pmt_solution']);
                 if (!in_array($MLV, $arr[$keys]['pmt_solution']['condition'][0][1])) {
                     unset($arr[$keys]);
                 }
             }
             $this->pagedata['promotions'] = $arr;
             $aTrading = array('price' => $this->pagedata['goods']['price'], 'score' => $this->pagedata['goods']['score'], 'gift' => array(), 'coupon' => array());
             $oPromotion->apply_single_pdt_pmt($aTrading, unserialize($aPmt['pmt_solution']), $member_lv);
             $oGift =& $this->system->loadModel('trading/gift');
             if (!empty($aTrading['gift'])) {
                 $this->pagedata['gift'] = $oGift->getGiftByIds($aTrading['gift']);
             }
             $oCoupon =& $this->system->loadModel('trading/coupon');
             if (!empty($aTrading['coupon'])) {
                 $this->pagedata['coupon'] = $oCoupon->getCouponByIds($aTrading['coupon']);
             }
             $this->pagedata['trading'] = $aTrading;
         }
         $oPackage =& $this->system->loadModel('trading/package');
         if (!empty($aPdtIds)) {
             $aPkgList = $oPackage->findPmtPkg($aPdtIds);
             foreach ($aPkgList as $k => $row) {
                 $aPkgList[$k]['items'] = $oPackage->getPackageProducts($row['goods_id']);
             }
             $this->pagedata['package'] = $aPkgList;
         }
         if ($GLOBALS['runtime']['member_lv'] < 0) {
             $this->pagedata['login'] = '******';
         }
         $cur =& $this->system->loadModel('system/cur');
         $this->pagedata['readingGlass'] = $this->system->getConf('site.reading_glass');
         $this->pagedata['readingGlassWidth'] = $this->system->getConf('site.reading_glass_width');
         $this->pagedata['readingGlassHeight'] = $this->system->getConf('site.reading_glass_height');
         $sellLogList = $objProduct->getGoodsSellLogList($gid, 0, $this->system->getConf('selllog.display.listnum'));
         $sellLogSetting['display'] = array('switch' => $this->system->getConf('selllog.display.switch'), 'limit' => $this->system->getConf('selllog.display.limit'), 'listnum' => $this->system->getConf('selllog.display.listnum'));
         $this->pagedata['goods']['product_freez'] = $totalFreez;
         $this->pagedata['sellLog'] = $sellLogSetting;
         $this->pagedata['sellLogList'] = $sellLogList;
         $this->pagedata['money_format'] = json_encode($cur->getFormat($this->system->request['cur']));
         $this->pagedata['askshow'] = $this->system->getConf('comment.verifyCode.ask');
         $this->pagedata['goodsBnShow'] = $this->system->getConf('goodsbn.display.switch');
         $this->pagedata['discussshow'] = $this->system->getConf('comment.verifyCode.discuss');
         $this->pagedata['showStorage'] = intval($this->system->getConf('site.show_storage'));
         $this->pagedata['specimagewidth'] = $this->system->getConf('spec.image.width');
         $this->pagedata['specimageheight'] = $this->system->getConf('spec.image.height');
         $this->pagedata['goodsproplink'] = $this->system->getConf('goodsprop.display.switch');
         $this->pagedata['goodspropposition'] = $this->system->getConf('goodsprop.display.position');
         $this->getGlobal($this->seoTag, $this->pagedata);
         $GLOBALS['pageinfo']['goods'] =& $GLOBALS['runtime']['goods_name'];
         $GLOBALS['pageinfo']['brand'] =& $GLOBALS['runtime']['brand'];
         $GLOBALS['pageinfo']['gcat'] =& $GLOBALS['runtime']['goods_cat'];
         $this->output();
     }
 }