Exemple #1
0
 public static function editgoods($goods)
 {
     $organID = Yii::app()->user->getOrganID();
     $goodsID = $goods['GoodsID'];
     if ($goods) {
         $data['Name'] = trim($goods['Name']);
         if (trim($goods['Pinyin']) == "") {
             $pinyin = F::Pinyin1($goods['Name']);
             // 如果未输入拼音则自动添加拼音
         } else {
             $pinyin = trim($goods['Pinyin']);
         }
         $data['IsSale'] = 0;
         //商品默认不上架
         $data['Pinyin'] = $pinyin;
         $data['GoodsNO'] = trim($goods['GoodsNO']);
         // 商品编号
         $data['PartsLevel'] = trim($goods['PartsLevel']);
         $data['Memo'] = trim($goods['Memo']);
         $data['Price'] = trim($goods['Price']);
         if (!empty($goods['goodsBrand'])) {
             $data['BrandID'] = trim($goods['goodsBrand']);
             // id
         }
         $data['StandCode'] = $goods['StandCode'];
         // 标准名称txt
         $data['Info'] = $goods['Info'];
         $data['Provenance'] = $goods['Provenance'];
         $model = PapGoods::model()->findByPk($goodsID);
         $model->attributes = $data;
         $oenos = $goods['OENOS'] ? $goods['OENOS'] : $goods['OENO'];
         if ($oenos) {
             foreach ($oenos as $value) {
                 $oe .= $value . ' ';
             }
         } else {
             $oe = '';
         }
         $model->Title = $data['Name'] . ' ' . $data['GoodsNO'] . ' ' . $pinyin . ' ' . $data['Brand'] . ' ' . $oe . ' ' . $goods['cpname'];
         $edtitime = $model->UpdateTime = time();
         $goodsold = DealergoodsService::newgoodsxinfo($goodsID);
         if ($model->save()) {
             // 把主营车系添加到商品车系关系表
             if ($goods["make"]) {
                 DealergoodsService::editvehiclegoods($goodsID, $organID, $edtitime, $goods);
             }
             // 把OENO号添加到关系表里
             if ($goods['OENOS']) {
                 DealergoodsService::editoegoods($goodsID, $organID, $goods);
             }
             // 添加商品图片
             if ($goods['urlimg']) {
                 DealergoodsService::editimggoods($goodsID, $organID, $goods);
             }
             // 添加商品属性
             DealergoodsService::editspecgoods($goodsID, $goods);
             // 添加商品包装
             DealergoodsService::editpackgoods($goodsID, $goods);
             $goodsnew = DealergoodsService::newgoodsxinfo($goodsID);
             $edit = DealergoodsService::goodsversion($goodsnew, $goodsold);
             DealergoodsService::editgoodslog($edit);
             $rs = array('success' => 1, 'errorMsg' => '修改数据成功', 'status' => 'save');
         } else {
             foreach ($model->errors as $key => $value) {
                 if ($key == 0) {
                     $errorMsg = $value['0'];
                 }
             }
             $rs = array('success' => 0, 'errorMsg' => $errorMsg, 'status' => 'save');
         }
     }
 }