/** * 生产商最新版本的所有产品 * @param unknown $manufacturer_ID * @return unknown * @params goodsprice 商品价格 * @params marketprice 市场指导价 */ public static function getGoodsByMDID($manufacturer_ID, $userID, $params, $page, $limit) { //授权品牌 $organID = Commonmodel::getOrganID(); $identity = Commonmodel::getIdentity(Yii::app()->user->id); $brands = MakePromitBrand::model()->find('DealerID=' . $organID . ' and OrganID=' . $manufacturer_ID); //查询销售价格 $criteria = new CDbCriteria(); //找到授权经销商的客户类别 //折扣率 // $priceratio= MakePromitPrice::model()->find('OrganID='.$manufacturer_ID); // $ratio=isset($priceratio['Level'.$brands['Level']])?$priceratio['Level'.$brands['Level']].'%':'100%'; // $sql2='select distinct a.id as goodsID,b.goods_oe as OE,b.goods_brand as brandid,b.version_name as verion_name,b.goods_no as goodsno,b.goods_name as goodsname,' // .' b.goods_category as categoryid,b.standard_id' // . " from tbl_make_goods a ,tbl_make_goods_version b,tbl_make_goods_vehicle c" // . ' where a.id=b.goods_id and a.NewVersion=b.version_name' // . " and a.ISdelete='0' and b.ISdelete=0" // . " and a.organID='$manufacturer_ID' "; $sql2 = "select distinct a.id as goodsID ,b.goods_category as category_id,b.goods_oe as OE,b.goods_brand as brand,b.organID,\n a.NewVersion as version_name,b.goods_no as goodsno,b.goods_name as goodsname,\n b.benchmarking_brand,b.benchmarking_sn,a.create_time,"; if ($identity['identity'] == 2) { $sql2 .= 'd.Price,'; } $sql2 .= " b.inventory as inventory,b.senddays,b.description,a.IsSale,b.standard_id" . " from tbl_make_goods a ,tbl_make_goods_version b "; if (!empty($params['goodsvehicle'])) { $sql2 .= ",tbl_make_goods_vehicle c"; } if ($identity['identity'] == 2) { $sql2 .= ',tbl_make_price_relation d'; } $sql2 .= ' where a.id=b.goods_id and a.NewVersion=b.version_name' . " and a.ISdelete='0' and b.ISdelete=0" . " and a.organID='{$manufacturer_ID}' "; if ($identity['identity'] == 2 && $brands['CustomerType']) { $sql2 .= "and d.TypeID= {$brands['CustomerType']} and d.GoodsID=a.id and d.Price is not null"; $sql2 .= " and a.IsSale=0"; } if ($params && is_array($params)) { if ($brands['BrandName']) { $sql2 .= " and b.goods_brand in (0" . $brands['BrandName'] . "0)"; } //商品类别搜索 if (!empty($params['goodscategory'])) { $sql2 .= ' and b.goods_category=' . $params['goodscategory']; } //商品名称搜索 if (!empty($params['goodsname'])) { $sql2 .= " and b.goods_name like '%{$params['goodsname']}%'"; } //商品编号搜索 if (!empty($params['goodsno'])) { $sql2 .= " and b.goods_no like '%{$params['goodsno']}%'"; } //商品OE号搜索 if (!empty($params['oe'])) { $sql2 .= " and b.goods_oe like '%{$params['oe']}%'"; } //商品品牌搜索 if (!empty($params['goodsbrand'])) { $sql2 .= " and b.goods_brand ='{$params['goodsbrand']}'"; } //适用车型搜索 if (!empty($params['goodsvehicle'])) { $sql2 .= " and c.Name like '%{$params['goodsvehicle']}%' and a.id=c.GoodsID and a.NewVersion=c.VersionName"; } // //是否上架查询 if (is_numeric($params['issale'])) { $sql2 .= " && a.IsSale='{$params['issale']}'"; } //配件品类 if (!empty($params['standardid'])) { $sql2 .= ' and b.standard_id=' . $params['standardid']; } else { //经营品类 $standmodel = DealerCpname::model()->findAll("OrganID=:organID", array(':organID' => $manufacturer_ID)); $standids = ''; $standarr = array(); foreach ($standmodel as $m) { $standarr[] = $m['CpNameID']; } $standids = implode(',', $standarr); if (!$standids) { $standids = '0'; } $sql2 .= ' and b.standard_id in (' . $standids . ')'; } //高级筛选 //此处 key : 查询属性 between,normall; $val['name']: 模板名称;$val["value"]:值 eg:value / value,value2 if (is_array($params["more"])) { foreach ($params["more"] as $key => $val) { $sql2 .= " and exists(\n\t \t\t \t\tSELECT DISTINCT(f.goods_id) FROM `tbl_make_goods_values` f,`tbl_make_goods_template` g where\n\t \t\t \t\tg.id=f.template_id and a.id=f.goods_id\n\t \t\t \t\tand g.organID='{$manufacturer_ID}' and g.standard_id='{$params['standardid']}'"; //判断查询属性 if ($val["type"] == "between") { //区间查询方式: $val["value"] = value,value2; $valArr = explode(',', $val["value"]); $sql2 .= "and (g.name='" . $val["name"] . "' and f.value between {$valArr['0']} and {$valArr['1']})) "; } else { if ($val["type"] == "normall") { $sql2 .= "and (g.name='" . $val["name"] . "' and f.value= '" . $val["value"] . "')) "; } } } } } //把make_goods里面上架的查询出来(0/1/上架/下架) 不写则全部查询 $sql2 .= " group by a.id order by a.id desc"; $result = Yii::app()->db->createCommand($sql2)->queryAll(); if ($page && $limit) { $count = count($result); $pages = new CPagination($count); //设置分页页数 $pages->setPageSize($limit); $pages->applyLimit($criteria); $result = Yii::app()->db->createCommand($sql2 . " LIMIT :offset,:limit"); //绑定分页参数 $offset = $pages->currentPage * $pages->pageSize; $size = $pages->pageSize; $result->bindValue(':offset', $pages->currentPage * $pages->pageSize); $result->bindValue(':limit', (int) $limit); $result = $result->queryAll(); } $res = array(); foreach ($result as $key => $val) { $res[$key] = $val; $OEArr = explode(',', $val['OE']); $res[$key]["car"] = self::getVehicleByOEArr($OEArr); //查询品牌名称 $brandmodel = MakeGoodsBrand::model()->findByPK($val['brand']); // $res[$key]['brand']=$brandmodel['BrandName']; $res[$key]['brandname'] = $brandmodel['BrandName']; //查询类别名称 $categorymodel = MakeGoodsCategory::model()->findByPk($val['category_id']); $res[$key]['category'] = $categorymodel['name']; //查询标准名称 $standardmodel = Gcategory::model()->findByPk($val['standard_id']); $res[$key]['cp_name'] = $standardmodel['name']; //查询车型 $cmodel = MakeGoodsVehicle::model()->find('GoodsID=' . $val['goodsID'] . ' and VersionName="' . $val['version_name'] . '"'); if ($cmodel) { $res[$key]['carmodel'] = $cmodel->Name; } if ($val['Price']) { $res[$key]['marketprice'] = $val['Price']; } //根据客户类别获取商品价格 // if($brands['CustomerType']) // { // $sql_price="select * from tbl_make_price_relation where TypeID= {$brands['CustomerType']} and GoodsID= $val[goodsID]"; // $price=DBUtil::query($sql_price); // $res[$key]['marketprice']=$price['Price']; // } //查询标准名称对应的参数名称 // $temname= MakeGoodsTemplate::model()->findAll("organID=:organID and standard_id=:stand and ISdelete='N'",array( // ':organID'=>$manufacturer_ID,':stand'=>$val['standard_id'])); //查询商品品与标准名称参数名称对应的参数值 $paramssql = 'SELECT a.id,a.name,b.value FROM `tbl_make_goods_template` a,`tbl_make_goods_values` b where a.id=b.template_id and b.goods_id=' . $val['goodsID'] . ' and b.version_name="' . $val['version_name'] . '"'; $paramsvalue = Yii::app()->db->createCommand($paramssql)->queryAll(); $res[$key]['params'] = ''; foreach ($paramsvalue as $p) { $res[$key]['params'] .= $p['name'] . ':' . $p['value'] . ';'; } $res[$key]['OE'] = $val['OE']; $res[$key]['Brand'] = $val['brand']; $res[$key]['version_name'] = $val['version_name']; $res[$key]['GoodsNo'] = $val['goodsno']; $res[$key]['GoodsName'] = $val['goodsname']; $res[$key]['BenchBrand'] = $val['benchmarking_brand']; $res[$key]['BenchNo'] = $val['benchmarking_sn']; $res[$key]['benchmarking_brand'] = $val['benchmarking_brand']; $res[$key]['benchmarking_sn'] = $val['benchmarking_sn']; $res[$key]['GoodsBrand'] = $val['brand']; $res[$key]['BrandName'] = $val['brandname']; $res[$key]['GoodsCategory'] = $val['category_id']; // $datas[$key]['CategoryName']=$val['category']; $res[$key]['inventory'] = $val['inventory']; $res[$key]['Days'] = $val['senddays']; $res[$key]['Desc'] = $val['description']; //b.maincategory,b.subcategory,b.standard_id $res[$key]['standard_id'] = $val['standard_id']; $res[$key]['create_time'] = date('Y-m-d H:i:s', $val['create_time']); //获取标准名称参数值 if (!empty($val['standard_id'])) { $params = MakeGoodsValues::model()->findAll('standard_id=' . $val['standard_id'] . ' and goods_id=' . $val['goodsID'] . ' and version_name="' . $val['version_name'] . '"'); $value = array(); foreach ($params as $param) { $k = $param['template_id']; $value[$k] = $param['value']; $res[$key][$k] = $param['value']; } $res[$key]['paramsvalue'] = $value; } if ($val['IsSale'] == 0) { $res[$key]['IsSale'] = '已上架'; } else { $res[$key]['IsSale'] = '已下架'; } } if ($page && $count) { return array('rows' => $res, 'total' => $count); } return $res; }
public function checkrepeat($goodsid, $version) { $res = array(); $verinfo = MakeGoodsVersion::model()->find('goods_id=' . $goodsid . ' and version_name="' . $version . '"'); $column = array(); if ($verinfo) { $res['BenchBrand'] = $verinfo['benchmarking_brand']; $res['BenchNo'] = $verinfo['benchmarking_sn']; $res['Days'] = $verinfo['senddays']; $res['Desc'] = $verinfo['description']; //$res['DiscountPrice']=$verinfo['discountprice']; $res['GoodsBrand'] = $verinfo['goods_brand']; $res['GoodsCategory'] = $verinfo['goods_category']; $res['GoodsName'] = $verinfo['goods_name']; $res['GoodsNo'] = $verinfo['goods_no']; //查询车型 $cmodel = MakeGoodsVehicle::model()->find('GoodsID=' . $goodsid . ' and VersionName="' . $version . '"'); $res['carmodel'] = ''; if ($cmodel) { $res['carmodel'] = $cmodel->Name; } //$res['MarkPrice']=$verinfo['marketprice']; $res['OE'] = $verinfo['goods_oe']; //$res['SalePrice']=$verinfo['salesprice']; $res['inventory'] = $verinfo['inventory']; $res['leafCategory'] = $verinfo['standard_id']; //$res['mainCategory']=$verinfo['maincategory']; //$res['subCategory']=$verinfo['subcategory']; $res['version_name'] = $verinfo['version_name']; //标准名称参数 $params = MakeGoodsValues::model()->findAll('standard_id=' . $res['leafCategory'] . ' and goods_id=' . $goodsid . ' and version_name="' . $res['version_name'] . '"'); foreach ($params as $param) { $k = $param['template_id']; $column[$k] = $param['value']; } } return array('baseinfo' => $res, 'column' => $column); }