Esempio n. 1
0
 public function actionAdddrop()
 {
     $this->pageTitle = Yii::app()->name . '-' . "发布商品";
     //        Yii::app()->request->getParam('id');
     $organID = Yii::app()->user->getOrganID();
     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']);
         if ($_POST['OENOS'][0]) {
             $data['OENO'] = $_POST['OENOS'][0];
         } else {
             $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 = new PapGoods();
         $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->OrganID = $organID;
         $model->OrganID = $organID;
         $UpdateTime = $model->CreateTime = time();
         //            if ($this->Isexist($data['GoodsNO'])) {  // 添加
         if ($model->save()) {
             //得到刚插入数据库的商品Id
             $pid = $model->attributes['ID'];
             // 把主营车系添加到商品车系关系表
             if ($_POST["make"]) {
                 DealergoodsService::addvehiclegoods($pid, $organID, $UpdateTime);
             }
             // 把OENO号添加到关系表里
             if ($_POST['OENOS']) {
                 DealergoodsService::addoegoods($pid, $organID);
             }
             // 添加商品图片
             if ($_POST['urlimg']) {
                 DealergoodsService::addimggoods($pid, $organID);
             }
             // 添加商品属性
             DealergoodsService::addspecgoods($pid);
             // 添加商品包装
             DealergoodsService::addpackgoods($pid);
             $goodsnew = DealergoodsService::newgoodsxinfo($pid);
             DealergoodsService::addgoodslog($goodsnew);
             $rs = array('success' => 1, 'errorMsg' => '保存数据成功');
         } else {
             $rs = array('success' => 0, 'errorMsg' => '保存数据失败');
         }
         //            } else {
         //                $rs = array('success' => 0, 'errorMsg' => '商品编号已存在,请修改!');
         //            }
     }
     $this->render('addresult', array('result' => $rs));
 }