Beispiel #1
0
 public function actionSave()
 {
     $this->pageTitle = Yii::app()->name . '-' . "修改商品";
     $organID = Yii::app()->user->getOrganID();
     $goodsID = $_POST['GoodsID'];
     if ($_POST) {
         $data['Name'] = trim($_POST['Name']);
         if (trim($_POST['Pinyin']) == "") {
             $pinyin = F::Pinyin1($_POST['Name']);
             // 如果未输入拼音则自动添加拼音
         } else {
             $pinyin = trim($_POST['Pinyin']);
         }
         $data['IsSale'] = 0;
         //商品默认不上架
         $data['Pinyin'] = $pinyin;
         $data['GoodsNO'] = trim($_POST['GoodsNO']);
         // 商品编号
         //$data['OENO'] = trim($_POST['OENO']);
         $data['PartsLevel'] = trim($_POST['PartsLevel']);
         $data['Memo'] = trim($_POST['Memo']);
         $data['Price'] = trim($_POST['Price']);
         if (!empty($_POST['goodsBrand'])) {
             $data['BrandID'] = trim($_POST['goodsBrand']);
             // id
             //                $data['Brand'] = trim($_POST['BrandName']);    // 名称
         }
         $data['StandCode'] = $_POST['StandCode'];
         // 标准名称txt
         //            $goodsspec['JiapartsNO'] = $data['BrandID']; // 加配号
         $data['Info'] = $_POST['Info'];
         $data['Provenance'] = $_POST['Provenance'];
         $model = PapGoods::model()->findByPk($goodsID);
         $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'] .' '.$data['GoodsNO']. ' ' . $pinyin . ' ' . $data['Brand'] . ' ' . $oe . ' ' . $make_hidden;
         $model->Title = $data['Name'] . ' ' . $data['GoodsNO'] . ' ' . $pinyin . ' ' . $data['Brand'] . ' ' . $oe . ' ' . $_POST['cpname'];
         //            $model->Title = $data['Name'] . ' ' . $pinyin . ' ' . $data['Brand'];
         // $model->CreateTime = time();
         $edtitime = $model->UpdateTime = time();
         //            if ($this->Isexist(trim($_POST['GoodsNO']), $goodsID)) {  // 修改
         //            $model->save();
         //
         //            var_dump($model->errors);
         //            exit;
         $goodsold = DealergoodsService::newgoodsxinfo($goodsID);
         if ($model->save()) {
             // 把主营车系添加到商品车系关系表
             if ($_POST["make"]) {
                 DealergoodsService::addvehiclegoods($goodsID, $organID, $edtitime);
             }
             // 把OENO号添加到关系表里
             if ($_POST['OENOS']) {
                 DealergoodsService::addoegoods($goodsID, $organID);
             }
             // 添加商品图片
             if ($_POST['urlimg'] || $_POST['delimg']) {
                 DealergoodsService::addimggoods($goodsID, $organID);
             }
             // 添加商品属性
             DealergoodsService::addspecgoods($goodsID);
             // 添加商品包装
             DealergoodsService::addpackgoods($goodsID);
             $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');
         }
         //            } else {
         //                $rs = array('success' => 0, 'errorMsg' => '商品编号已存在,请修改!', 'status' => 'save');
         //            }
     }
     $this->render('saveresult', array('result' => $rs));
 }