예제 #1
0
 public function actionUpdate()
 {
     $organID = Commonmodel::getOrganID();
     $userID = Yii::app()->user->id;
     $goodsID = $_GET['id'];
     if ($_POST) {
         $data['Name'] = trim($_POST['Name']);
         if (trim($_POST['Pinyin']) == "") {
             $pinyin = F::Pinyin1($_POST['Name']);
             // 如果未输入拼音则自动添加拼音
         } else {
             $pinyin = trim($_POST['Pinyin']);
         }
         $data['Pinyin'] = $pinyin;
         $data['GoodsNO'] = trim($_POST['GoodsNO']);
         if (!empty($_POST['OENOS'][0])) {
             $data['OENO'] = $_POST['OENOS'][0];
         }
         $data['PartsLevel'] = trim($_POST['PartsLevel']);
         $data['Memo'] = trim($_POST['Memo']);
         $data['Price'] = trim($_POST['Price']);
         $data['Unit'] = trim($_POST['Unit']);
         $LogisticsPrice = trim($_POST['LogisticsPrice']);
         if (empty($LogisticsPrice)) {
             $data['LogisticsPrice'] = 0;
         } else {
             $data['LogisticsPrice'] = $LogisticsPrice;
         }
         if (empty($_POST['goodsBrand'])) {
             $data['BrandID'] = trim($_POST['goodsBrand']);
             // id
             $data['Brand'] = '';
             // 名称
         } else {
             if (!empty($_POST['goodsBrand'])) {
                 $data['BrandID'] = trim($_POST['goodsBrand']);
                 // id
                 $data['Brand'] = trim($_POST['brandID']);
                 // 名称
             }
         }
         //            if (!empty($_POST['leafCategory'])) {
         //                $data['BigParts'] = $_POST['mainCategory'];         // 配件大类
         //                $data['SubParts'] = $_POST['subCategory'];          // 配件子类
         //                $data['CpName'] = $_POST['leafCategory'];           // 标准名称
         $data['CpNameTxt'] = $_POST['CpNameTxt'];
         // 标准名称
         $goodsspec['JiapartsNO'] = $data['BrandID'];
         // 加配号
         //            }
         //            if (!empty($_POST['IsUpSale'])) {
         $data['IsSale'] = $_POST['IsUpSale'];
         //            }
         // $model = new DealerGoods();
         $model = DealerGoods::model()->findByPk($goodsID);
         // var_dump($data);exit;
         $model->attributes = $data;
         $oenos = $_POST['OENOS'] ? $_POST['OENOS'] : $_POST['OENO'];
         if ($oenos) {
             foreach ($oenos as $value) {
                 $oe .= $value;
             }
         } else {
             $oe = '';
         }
         $make_hidden = explode(',', $_POST["make_hidden"]);
         $make_hidden = array_unique($make_hidden);
         $make_hidden = array_filter($make_hidden);
         $make_hidden = implode(',', $make_hidden);
         $model->Title = $data['Name'] . ' ' . $pinyin . ' ' . $data['Brand'] . ' ' . $oe . ' ' . $make_hidden;
         // $model->CreateTime = time();
         $model->UpdateTime = time();
         if ($this->Isexist($data['GoodsNO'], $goodsID)) {
             // 修改
             if ($model->save()) {
                 $make = explode(',', $_POST["make"]);
                 $car = explode(',', $_POST["car"]);
                 $year = explode(',', $_POST["year"]);
                 $model2 = explode(',', $_POST["model"]);
                 $maketext = explode(',', $_POST["maketxt"]);
                 $cartext = explode(',', $_POST["cartxt"]);
                 $modeltext = explode(',', $_POST["modeltxt"]);
                 // 把主营车系添加到商品车系关系表
                 $vehlegth = count($make);
                 for ($i = 0; $i < $vehlegth; $i++) {
                     if ($make[$i] != 0) {
                         $goodsv = new DealerGoodsVehicleRelation();
                         // 车型车系
                         $goodsv->OrganID = $organID;
                         $goodsv->GoodsID = $goodsID;
                         $goodsv->Make = $make[$i];
                         $goodsv->Car = $car[$i];
                         $goodsv->Year = $year[$i];
                         $goodsv->Model = $model2[$i];
                         $goodsv->Marktxt = $maketext[$i];
                         $goodsv->Cartxt = $cartext[$i];
                         $goodsv->Modeltxt = $modeltext[$i];
                         $goodsv->save();
                     }
                 }
                 $sql = "update tbl_dealer_goods_vehicle_relation set GoodsID = {$goodsID} where OrganID = {$organID} and GoodsID = 0";
                 $b = DBUtil::execute($sql);
                 // 把OENO号添加到关系表里
                 $oenos = $_POST['OENOS'];
                 $oelegth = count($oenos);
                 DealerGoodsOenoRelation::model()->deleteAll("OrganID= '{$organID}' and GoodsID='{$goodsID}'");
                 for ($i = 0; $i < $oelegth; $i++) {
                     $goodsoeno = new DealerGoodsOenoRelation();
                     // OE号关系表
                     $goodsoeno->OrganID = $organID;
                     $goodsoeno->GoodsID = $goodsID;
                     $goodsoeno->OENO = $oenos[$i];
                     $goodsoeno->save();
                 }
                 // 添加商品图片
                 //                    $goodsImages = $_POST['goodsImages'];
                 //                    $imglegth = count($goodsImages);
                 //                    for ($i = 0; $i < $imglegth; $i++) {
                 //                        $goodsImg = new DealerGoodsImageRelation();
                 //                        $goodsImg->GoodsID = $goodsID;
                 //                        $goodsImg->OrganID = $organID;
                 //                        $goodsImg->ImageUrl = $goodsImages[$i];
                 //                        $goodsImg->save();
                 //                    }
                 $urlimg = explode(',', $_POST['urlimg']);
                 //根据逗号拆分,得到图片信息的字符串
                 $sqlimg = "insert into tbl_dealer_goods_image_relation (OrganID,GoodsID,ImageUrl,CreateTime,ImageName) values";
                 foreach ($urlimg as $k => $value) {
                     if ($value) {
                         //去掉初始值0
                         $addimg = explode(';', $value);
                         //根据分号拆分,得到图片的相关信息
                         if ($k != 1) {
                             $sqlimg .= ",";
                         }
                         $sqlimg .= "(";
                         $sqlimg .= $organID;
                         $sqlimg .= ",";
                         $sqlimg .= $goodsID;
                         //商品ID
                         $sqlimg .= ",'";
                         $sqlimg .= $addimg[0];
                         //图片url
                         $sqlimg .= "',";
                         $sqlimg .= time();
                         $sqlimg .= ",'";
                         $sqlimg .= $addimg[1];
                         //图片原名
                         $sqlimg .= "')";
                     }
                 }
                 DBUtil::execute($sqlimg);
                 // 添加商品属性
                 if ($goodsImages) {
                     $goodsspec['ImageUrl'] = $goodsImages[0];
                 }
                 if ($_POST['detcImages']) {
                     $goodsspec['DetectionImg'] = $_POST['detcImages'];
                 }
                 // 添加商品属性
                 $goodsspec['Weight'] = $_POST['Weight'];
                 // 重量
                 $goodsspec['Length'] = $_POST['Length'];
                 // 长
                 $goodsspec['Wide'] = $_POST['Wide'];
                 // 宽
                 $goodsspec['Height'] = $_POST['Height'];
                 // 高
                 $goodsspec['Volume'] = $_POST['Volume'];
                 //体积
                 $goodsspec['ValidityType'] = $_POST['ValidityType'];
                 // 保质期类型
                 $goodsspec['ValidityDate'] = $_POST['ValidityDate'];
                 // 保质期
                 $goodsspec['BganCompany'] = $_POST['BganCompany'];
                 // 标杆公司
                 $goodsspec['BganGoodsNO'] = $_POST['BganGoodsNO'];
                 // 标杆商品号
                 $goodsspec['Specifica'] = $_POST['Specifica'];
                 // 规格
                 $goodsspec['PartsNO'] = $_POST['PartsNO'];
                 // 配件类别
                 $goodsspec['Unit'] = trim($_POST['Unit']);
                 $psid = DealerGoodsSpec::model()->find("GoodsID={$goodsID}")->attributes['ID'];
                 $goodssp = DealerGoodsSpec::model()->findByPk($psid);
                 if (empty($psid)) {
                     $goodssp = new DealerGoodsSpec();
                 }
                 $goodssp->attributes = $goodsspec;
                 $goodssp->GoodsID = $goodsID;
                 $goodssp->save();
                 // 添加商品包装
                 $goodspack['MinQuantity'] = $_POST['MinQuantity'];
                 //
                 $goodspack['Weight'] = $_POST['pWeight'];
                 //
                 $goodspack['Volume'] = $_POST['pVolume'];
                 //
                 $pcid = DealerGoodsPack::model()->find("GoodsID={$goodsID}")->attributes['ID'];
                 $goodspc = DealerGoodsPack::model()->findByPk($pcid);
                 if (empty($pcid)) {
                     $goodspc = new DealerGoodsPack();
                 }
                 $goodspc->attributes = $goodspack;
                 $goodspc->GoodsID = $goodsID;
                 $goodspc->save();
                 //                $bool2 = DealerGoodsPack::model()->updateAll(array(
                 //                    'MinQuantity' => $goodspack['MinQuantity'],
                 //                    'Weight' => $goodspack['Weight'],
                 //                    'Volume' => $goodspack['Volume'],
                 //                        ), "GoodsID=" . $goodsID);
                 $rs = array('success' => 1, 'errorMsg' => '修改数据成功');
             } else {
                 $rs = array('success' => 0, 'errorMsg' => '修改数据失败');
             }
         } else {
             $rs = array('success' => 0, 'errorMsg' => '商品编号已存在,请修改!');
         }
     }
     echo json_encode($rs);
 }
예제 #2
0
파일: DealerGoods.php 프로젝트: zwq/unpei
 /**
  * 
  * 获取商品信息
  * @param type array() $prams
  * Description 根据传入的阐述
  * 参数传入方法: array('OrganID'=>'机构ID','goodsName'=>'商品名称',...);
  *                如果需要分页,array('rows'=>'每页显示条数',...); 返回结果 获取总条数: $data[0]['count'];
  * @return array 
  * 使用方法 : 1、DealerGoods::getGoodsInfo(); 
  *             3、DealerGoods::getGoodsInfo(array('goodsName'=>'商品001')); 等
  */
 public static function getGoodsInfo($params = '')
 {
     $criteria = new CDbCriteria();
     $criteria->select = "*";
     $criteria->order = "t.ID DESC";
     //排序条件:update_time,id倒叙
     //        $criteria->with = array('goodsspec', 'goodspack');
     $criteria->condition = 't.ISdelete =1';
     // 查询条件
     if (is_array($params)) {
         $organID = $params['OrganID'];
         // 机构ID
         $rows = $params['rows'];
         $curpage = $params['page'];
         // 每页显示条数
         $goodsNO = $params['goodsNO'];
         // 商品编号
         $goodsName = $params['goodsName'];
         // 商品名称
         $brandID = $params['BrandID'];
         // 商品品牌ID
         $brand = $params['BrandName'];
         // 商品品牌名
         $OENO = $params['OENO'];
         // 商品OE号
         $IsSale = $params['IsSale'];
         // 是否上架
         $IsPro = $params['IsPro'];
         // 是否促销
         //   $gbigparts = $params['gbigparts'];          // 大类
         //   $gsubparts = $params['gsubparts'];          // 子类
         //   $gcpname = $params['gcpname'];              // 标准名称
         $gcpnametxt = $params['gcpnametxt'];
         // 标准名称
         $gmake = $params['gmake'];
         // 厂家
         $gcar = $params['gcar'];
         // 车系
         $gyear = $params['gyear'];
         // 年款
         $gmodel = $params['gmodel'];
         // 车型
         if (empty($IsSale)) {
             // 是否上架
             $criteria->addCondition("t.IsSale = 1", "AND");
         } elseif ($IsSale == 'all') {
             $criteria->addBetweenCondition('IsSale', 0, 1, "AND");
         } else {
             if ($IsSale == 2) {
                 $criteria->addCondition("IsSale = 0", "AND");
             } else {
                 $criteria->addCondition("t.IsSale = 1", "AND");
             }
         }
         if (empty($IsPro) || $IsPro == 'all') {
             // 是否促销
             $criteria->addBetweenCondition('t.IsPro', 0, 1, "AND");
         } else {
             if ($IsPro == 2) {
                 // 不是促销的
                 $criteria->addCondition("t.IsPro = 0", "AND");
             } else {
                 // 是促销的
                 //   $Times = time() - 24 * 60 * 60 * 7 * 2 ;
                 $criteria->addCondition("t.IsPro = 1", "AND");
                 //  $criteria->addCondition("ProTime < $Times", "AND");
             }
         }
         if (!empty($goodsNO)) {
             // 商品编号
             $criteria->addSearchCondition("t.GoodsNO", "{$goodsNO}", "AND");
         }
         if (!empty($goodsName)) {
             // 商品名称
             $criteria->addSearchCondition("t.Name", "{$goodsName}", "AND");
         }
         if (!empty($brandID)) {
             // 品牌ID
             $criteria->addCondition("t.BrandID = {$brandID} ", "AND");
         }
         if (!empty($brand)) {
             // 品牌名称
             $criteria->addCondition("t.Brand = '{$brand}' ", "AND");
         }
         if (!empty($organID)) {
             // 机构名称
             $criteria->addCondition("t.OrganID = {$organID} ", "AND");
         }
         //            if (!empty($gbigparts)) {
         //                if (!empty($gcpname)) {
         //                    $criteria->addCondition("t.BigParts = $gbigparts ", "AND");
         //                    $criteria->addCondition("t.CpName = $gcpname ", "AND");
         //                } else {
         //                    $criteria->addCondition("t.BigParts = $gcpname ", "AND");
         //                }
         //            }
         if (!empty($gcpnametxt) && $gcpnametxt != "请选择标准名称") {
             $criteria->addCondition("t.CpNameTxt = '{$gcpnametxt}'", "AND");
             // $criteria->addCondition("t.CpNameTxt = '空气滤清器'", "AND");
         }
         if ($OENO) {
             $OENOs = self::getOENOcondition($OENO);
             if ($OENOs) {
                 $criteria->addInCondition('t.ID', $OENOs, "AND");
             } else {
                 $criteria->addInCondition('t.ID', array(0), "AND");
             }
         }
         if (!empty($gmake)) {
             // 车型车系
             $arr = array();
             $arr['gmake'] = $gmake ? $gmake : 0;
             $arr['gcar'] = $gcar ? $gcar : 0;
             $arr['gyear'] = $gyear ? $gyear : 0;
             $arr['gmodel'] = $gmodel ? $gmodel : 0;
             $goodsIDS = self::getVehcondition($arr);
             //var_dump($goodsIDS);     exit;
             if ($goodsIDS) {
                 $criteria->addInCondition('t.ID', $goodsIDS, "AND");
             } else {
                 $criteria->addInCondition('t.ID', array(0), "AND");
             }
             //                $MakeInfo = D::queryFrontMakeInfo($gmake);
             //                $SeriesInfo = D::queryFrontSeriesInfo($gcar);
         }
         // var_dump($params);
     } else {
         if (!empty($params) && !is_array($params)) {
             return '参数传入错误';
         }
     }
     $count = DealerGoods::model()->count($criteria);
     //        $rows = $rows ? $rows : 10;
     //        $offset = $curpage * $rows + 1;
     //        $criteria->limit = $rows;   //取1条数据,如果小于0,则不作处理
     //        $criteria->offset = $offset;
     $pages = new CPagination($count);
     $pages->pageSize = $rows ? $rows : 10;
     $pages->applyLimit($criteria);
     $goodses = DealerGoods::model()->findAll($criteria);
     // var_dump($goodses);
     $data = array();
     $data[0]['count'] = $count;
     foreach ($goodses as $key => $goods) {
         $data[$key]['ID'] = $goods['ID'];
         $data[$key]['OrganID'] = $goods['OrganID'];
         $organInfo = self::getOrganName($goods['OrganID']);
         $data[$key]['OrganName'] = $organInfo['organName'];
         $data[$key]['Name'] = $goods['Name'];
         $data[$key]['goodsName'] = F::msubstr($goods['Name'], 0, 20);
         $data[$key]['gName'] = mb_substr($goods['Name'], 0, 20, 'utf-8');
         $data[$key]['Pinyin'] = $goods['Pinyin'];
         $data[$key]['Pinyin2'] = F::msubstr($goods['Pinyin'], 0, 10);
         $data[$key]['Brand'] = self::getBrandByID($goods['BrandID']);
         $data[$key]['Brand'] = $data[$key]['Brand'] ? $data[$key]['Brand'] : $goods['Brand'];
         $data[$key]['goodsBrand'] = $goods['BrandID'];
         $data[$key]['GoodsNO'] = $goods['GoodsNO'];
         $data[$key]['OENO'] = $goods['OENO'];
         $data[$key]['OENOS'] = self::getOENOSByGoodsID($goods['ID']) ?: $goods['OENO'];
         // 车型车系
         $vehs = explode('、', self::getVehicleByGoodsID($goods['ID']));
         //  'seriesName'=>'','makeId'=>'','makeName'=>'');
         //检索商品本身的适用车型,如果有子集的车型则显示有子集的车型
         $data[$key]['Vehicle'] = self::getCurrentVehicle($arr);
         $data[$key]['Vehicle'] = $data[$key]['Vehicle'] ? $data[$key]['Vehicle'] : $vehs[0];
         $data[$key]['Vehicles'] = self::getVehicleByGoodsID($goods['ID']);
         $data[$key]['PartsLevel'] = $goods['PartsLevel'];
         $data[$key]['Memo'] = $goods['Memo'];
         $data[$key]['Price'] = $goods['Price'];
         // 参考价
         if ($goods['IsPro'] == 1) {
             if (empty($goods['ProPrice']) || $goods['ProPrice'] == 0) {
                 $data[$key]['ProPrice'] = $goods['Price'];
                 // 促销价
             } else {
                 $data[$key]['ProPrice'] = $goods['ProPrice'];
                 // 促销价
             }
         }
         $data[$key]['LogisticsPrice'] = $goods['LogisticsPrice'];
         // 物流价
         //$data[$key]['BigParts'] = Commonmodel::getCategory($goods['BigParts']);
         //$data[$key]['SubParts'] = Commonmodel::getCategory($goods['SubParts']);
         //$data[$key]['CpName'] = Commonmodel::getCategory($goods['CpName']);
         $data[$key]['CpNameTxt'] = $goods['CpNameTxt'];
         $data[$key]['mainCategory'] = $goods['BigParts'];
         $data[$key]['subCategory'] = $goods['SubParts'];
         $data[$key]['leafCategory'] = $goods['CpName'];
         // $data[$key]['sutecar'] = F::msubstr($this->getcar($goods['ID']));
         $data[$key]['IsSale'] = $goods['IsSale'] == 1 ? '已上架' : '已下架';
         $data[$key]['IsUpSale'] = $goods['IsSale'];
         $data[$key]['proTime'] = date("Y-m-d", $goods['ProTime']) . '--' . date("Y-m-d", $goods['ProTime'] + 60 * 60 * 24 * 14);
         // 促销时间
         // 商品属性
         $data[$key]['Weight'] = "";
         $data[$key]['Length'] = "";
         $data[$key]['Wide'] = "";
         $data[$key]['Height'] = "";
         $data[$key]['Volume'] = "";
         $data[$key]['ValidityDate'] = "";
         $data[$key]['ValidityType'] = "";
         $data[$key]['Specifica'] = "";
         $data[$key]['Unit'] = "";
         $data[$key]['BganCompany'] = "";
         $data[$key]['BganGoodsNO'] = "";
         $data[$key]['PartsNO'] = "";
         $data[$key]['JiapartsNO'] = "";
         // 嘉配号
         $data[$key]['ImageUrl'] = "";
         // 图像名称
         $data[$key]['DetectionImg'] = "";
         // 检测图像
         $cmodel = DealerGoodsSpec::model()->findByAttributes(array('GoodsID' => $goods['ID']));
         if ($cmodel) {
             $data[$key]['Weight'] = $cmodel->Weight;
             $data[$key]['Length'] = $cmodel->Length;
             $data[$key]['Wide'] = $cmodel->Wide;
             $data[$key]['Height'] = $cmodel->Height;
             $data[$key]['Volume'] = $cmodel->Volume;
             $data[$key]['ValidityType'] = $cmodel->ValidityType;
             $data[$key]['ValidityDate'] = $cmodel->ValidityDate;
             if ($cmodel->ValidityType == 1) {
                 $data[$key]['Validity'] = '不保修';
             }
             if ($cmodel->ValidityType == 2) {
                 $data[$key]['Validity'] = '保装车';
             }
             if ($cmodel->ValidityType == 3) {
                 $data[$key]['Validity'] = $cmodel->ValidityDate;
             }
             $data[$key]['Specifica'] = $cmodel->Specifica;
             $data[$key]['Unit'] = $cmodel->Unit;
             $data[$key]['BganCompany'] = $cmodel->BganCompany;
             $data[$key]['BganGoodsNO'] = $cmodel->BganGoodsNO;
             $data[$key]['PartsNO'] = $cmodel->PartsNO;
             $data[$key]['JiapartsNO'] = $cmodel->JiapartsNO;
             // 嘉配号
             $data[$key]['ImageUrl'] = $cmodel->ImageUrl;
             // 图像名称
             $data[$key]['DetectionImg'] = $cmodel->DetectionImg;
             // 检测图像
         }
         // 商品包装
         $data[$key]['pWeight'] = "";
         $data[$key]['pVolume'] = "";
         $data[$key]['MinQuantity'] = "";
         $cmodel = DealerGoodsPack::model()->findByAttributes(array('GoodsID' => $goods['ID']));
         if ($cmodel) {
             $data[$key]['pWeight'] = $cmodel->Weight;
             $data[$key]['pVolume'] = $cmodel->Volume;
             $data[$key]['MinQuantity'] = $cmodel->MinQuantity;
         }
     }
     return $data;
 }