Ejemplo n.º 1
0
 public static function editscheme($params)
 {
     $organID = Yii::app()->user->getOrganID();
     $time = $_SERVER['REQUEST_TIME'];
     //更新报价单
     $quoID = self::ifsendquo(array('inqid' => $params['inqid']));
     $quodatas['UpdateTime'] = $time;
     $quodatas['Title'] = $params['quoname'];
     $result = Yii::app()->papdb->createCommand()->update('pap_quotation', $quodatas, 'QuoID=' . $quoID);
     $SchID = $params['schid'];
     $datas['TotalFee'] = $params['quoprices'];
     $datas['GoodFee'] = $params['totalprices'];
     $datas['ShipFee'] = $params['shipprices'];
     $datas['ShipFee'] = $params['shipprices'];
     $datas['UpdateTime'] = $time;
     //保存附件
     if ($params['fileurl']) {
         $datas['FileName'] = $params['filename'];
         $datas['FileUrl'] = $params['fileurl'];
         //删除之前附件
         $quo_data = PapQuotationScheme::model()->findByPk($SchID);
         if (!empty($quo_data['FileName'])) {
             $ftp = new Ftp();
             $res = $ftp->delete_file($quo_data->FileUrl);
             $ftp->close();
         }
     }
     $result = Yii::app()->papdb->createCommand()->update('pap_quotation_scheme', $datas, 'SchID=:SchID', array(':SchID' => $SchID));
     //获取商品信息
     $goodsinfo = array();
     $goodsids = explode(',', $params['quoids']);
     $goodsnum = explode(',', $params['quonum']);
     $goodsprice = explode(',', $params['quoprice']);
     //获取以前的商品信息
     $oldgoodsinfo = PapQuotationGoods::model()->findAll('SchID=' . $SchID);
     $newgoodsinfo = array();
     foreach ($goodsids as $key => $v) {
         if ($v) {
             $newgoodsinfo[$key]['GoodsID'] = $goodsids[$key];
             $newgoodsinfo[$key]['Num'] = $goodsnum[$key];
             $newgoodsinfo[$key]['Price'] = $goodsprice[$key];
             $version = QuotationService::getgoodsversion($goodsids[$key]);
             $newgoodsinfo[$key]['Version'] = $version ? $version : 0;
         }
     }
     $insertid = array();
     //将报价单商品插入报价单商品表中
     if ($SchID) {
         foreach ($newgoodsinfo as $nkey => $new) {
             $newids[] = $new['GoodsID'];
         }
         if ($oldgoodsinfo) {
             foreach ($oldgoodsinfo as $okey => $old) {
                 $oldids[] = $old['GoodsID'];
             }
         } else {
             $oldids = array();
         }
         foreach ($oldids as $id) {
             if (!in_array($id, $newids)) {
                 //删除商品
                 $delcount = Yii::app()->papdb->createCommand()->delete('pap_quotation_goods', 'SchID=:SchID and GoodsID=:goodsid', array(':SchID' => $SchID, ':goodsid' => $id));
             }
         }
         foreach ($newids as $key => $id) {
             if (in_array($id, $oldids)) {
                 //更新商品
                 $update['Num'] = $newgoodsinfo[$key]['Num'];
                 $update['Price'] = $newgoodsinfo[$key]['Price'];
                 $update['Version'] = $newgoodsinfo[$key]['Version'];
                 $result = Yii::app()->papdb->createCommand()->update('pap_quotation_goods', $update, 'SchID=:SchID and GoodsID=:goodsid', array(':SchID' => $SchID, ':goodsid' => $id));
                 if ($result == 1) {
                     $res = 1;
                 }
             } else {
                 //插入商品
                 $goodsdatas['SchID'] = $SchID;
                 $goodsdatas['GoodsID'] = $newgoodsinfo[$key]['GoodsID'];
                 $goodsdatas['Num'] = $newgoodsinfo[$key]['Num'];
                 $goodsdatas['Price'] = $newgoodsinfo[$key]['Price'];
                 $goodsdatas['Version'] = $newgoodsinfo[$key]['Version'];
                 $result = Yii::app()->papdb->createCommand()->insert('pap_quotation_goods', $goodsdatas);
                 $insertid[] = Yii::app()->papdb->getLastInsertID();
             }
         }
     }
     if ($res = 1 || count($insertid) > 0 || $delcount > 0) {
         echo json_encode(array('count' => 1, 'schid' => $SchID, 'success' => true));
     } else {
         echo json_encode(array('count' => 0));
     }
 }