コード例 #1
0
ファイル: LogisticsController.php プロジェクト: zwq/unpei
 public function actionAddlogistics()
 {
     $organID = Commonmodel::getOrganID();
     if (isset($_POST)) {
         $model = Logistics::model()->find(array("condition" => "OrganID = {$organID} and LogisticsCompany = '{$_POST['LogisticsCompany']}'"));
         if (!empty($model)) {
             $rs = array('success' => 0, 'errorMsg' => '物流公司不能重复添加');
         } else {
             unset($model);
             $model = new Logistics();
             $model->OrganID = $organID;
             $model->LogisticsCompany = $_POST['LogisticsCompany'];
             $model->LogisticsDescription = $_POST['LogisticsDescription'];
             $model->CreateTime = time();
             $model->UpdateTime = time();
             $model->Status = 2;
             $bool = $model->save();
             if ($bool == 1) {
                 $ID = Yii::app()->db->getLastInsertID();
                 // 把地址添加到关系表里,可添加多个
                 $sprovince = $_POST['province'];
                 $scity = $_POST['city'];
                 $sarea = $_POST['area'];
                 $addlegth = count($sprovince);
                 for ($i = 0; $i < $addlegth; $i++) {
                     $model1 = new LogisticsAddress();
                     $model1->LogisticsID = $ID;
                     $model1->Province = $sprovince[$i];
                     $model1->City = $scity[$i];
                     $model1->Area = $sarea[$i];
                     $res = $model1->save();
                 }
             }
             if ($res == 1) {
                 $rs = array('success' => 1, 'errorMsg' => '物流公司添加成功');
             } else {
                 $rs = array('success' => 0, 'errorMsg' => '物流公司添加失败');
             }
         }
     }
     echo json_encode($rs);
 }