/**
  * Creates a new Contract model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Contract();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->contr_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
 /**
  * 上传或者提交合同
  * @author lvkui
  * @param $data
  * @param bool $method
  * @throws \Exception
  * @throws \yii\base\Exception
  */
 function sys_submitContract($data, $method = true)
 {
     $tran = null;
     try {
         $tran = Yii::$app->db->beginTransaction();
         if (!isset($data['contract']) || $this->isStrEmpty($data['contract'])) {
             throw new Exception('an empty string is not allowed for $contract');
         }
         $user = AccessTokenService::getCurrentUser();
         //电子合同
         $ec = $data['contract'];
         $model = new Contract();
         $model->vercode = $ec['vercode'];
         $model->type = $ec['type'];
         $model->is_lock = Contract::CONTRACT_NO;
         $model->status = $method ? Contract::CONTRACT_STATUS_COMMITIN : Contract::CONTRACT_STATUS_UNCOMMIT;
         $model->audit_status = $user->org->isaudit ? Contract::CONTRACT_YES : Contract::CONTRACT_NO;
         $model->is_submit = $model->status;
         $model->sub_time = $model->is_submit ? DataHelper::getCurrentTime() : '';
         $model->price = $ec['price'];
         $model->num = $ec['num'];
         $model->transactor = $ec['transactor'];
         $model->oldcontr = $ec['contr_no'];
         $model->save();
         //线路信息
         if (isset($data['group'])) {
             $g = $data['group'];
             $gModel = new Group();
             $gModel->contr_id = $model->contr_id;
             $gModel->teamcode = $g['teamcode'];
             $gModel->linename = $g['linename'];
             $gModel->personLimit = $g['personLimit'];
             $gModel->payGuide = $g['payGuide'];
             $gModel->days = $g['days'];
             $gModel->nights = $g['nights'];
             $gModel->bgndate = $g['bgndate'];
             $gModel->enddate = $g['enddate'];
             $gModel->from = $g['from'];
             $gModel->aim = $g['aim'];
             $gModel->save();
         }
         //游客信息
         if (isset($data['traveller'])) {
             $t = $data['traveller'];
             $tModel = new Traveller();
             $tModel->contr_id = $model->contr_id;
             $tModel->name = $t['name'];
             $tModel->sex = $t['sex'];
             $tModel->birthday = $t['birthday'];
             $tModel->nation = $t['nation'];
             $tModel->folk = $t['folk'];
             $tModel->mobile = $t['mobile'];
             $tModel->idtype = $t['idtype'];
             $tModel->idcode = $t['idcode'];
             $tModel->addr = $t['addr'];
             $tModel->no = $t['no'];
             $tModel->is_leader = $t['is_leader'];
             if ($tModel->is_leader) {
                 $tModel->extra_data = $t['extra_data'];
             }
             $tModel->save();
         }
         //行程信息
         if (isset($data['routes'])) {
             $r = $data['routes'];
             if (!empty($r['journeys'])) {
                 foreach ($r['journeys'] as $k => $j) {
                     $rModel = new Routes();
                     $rModel->contr_id = $model->contr_id;
                     $rModel->parentid = '0';
                     $rModel->title = $j['title'];
                     $rModel->ctype = Routes::ROUTE_TYPE_JOURNEY;
                     $rModel->index = $j['index'];
                     if ($rModel->save()) {
                         $parentid = $rModel->id;
                         if (!empty($j['citys'])) {
                             foreach ($j['citys'] as $i => $c) {
                                 $cModel = new Routes();
                                 $cModel->contr_id = $model->contr_id;
                                 $cModel->parentid = $parentid;
                                 $cModel->title = $c['title'];
                                 $cModel->ctype = Routes::ROUTE_TYPE_CITY;
                                 $cModel->transit = $c['transit'];
                                 $cModel->index = $c['index'];
                                 $cModel->from = $c['from'];
                                 $cModel->aim_city = $c['aim_city'];
                                 $cModel->aim_country = $c['aim_country'];
                                 $cModel->sign = DataHelper::getSign($c['content']);
                                 $text = Text::findOne($cModel->sign);
                                 if (empty($text)) {
                                     $text->sign = $cModel->sign;
                                     $text->content = $c['content'];
                                     $text->save();
                                 }
                                 //$cModel->extra_data=$c['extra_data'];
                                 $cModel->save();
                             }
                         }
                     }
                 }
             }
         }
         //购物协议
         if (isset($data['shops'])) {
             foreach ($data['shops'] as $shop) {
                 $sModel = new ShopAgreement();
                 $sModel->contr_id = $model->contr_id;
                 $sModel->name = $shop['name'];
                 $sModel->addr = $shop['addr'];
                 $sModel->time = $shop['time'];
                 $sModel->goods = $shop['goods'];
                 $sModel->duration = $shop['duration'];
                 $sModel->memo = $shop['memo'];
                 $sModel->agree = $shop['agree'];
                 $sModel->index = $shop['index'];
                 $sModel->save();
             }
         }
         //自费协议
         if (isset($data['chargeables'])) {
             foreach ($data['chargeables'] as $charge) {
                 $chModel = new Chargeable();
                 $chModel->contr_id = $model->contr_id;
                 $chModel->name = $charge['name'];
                 $chModel->addr = $charge['addr'];
                 $chModel->time = $charge['time'];
                 $chModel->price = $charge['price'];
                 $chModel->duration = $charge['duration'];
                 $chModel->memo = $charge['memo'];
                 $chModel->agree = $charge['agree'];
                 $chModel->index = $charge['index'];
                 $chModel->save();
             }
         }
         //合同其它信息
         if (isset($data['other'])) {
             $other = $data['other'];
             $oModel = new Other();
             $oModel->contr_id = $model->contr_id;
             $oModel->groupcorp = $other['groupcorp'];
             $oModel->pay = $other['pay'];
             $oModel->insurance = $other['insurance'];
             $oModel->group = $other['group'];
             if (!empty($other['goldenweek'])) {
                 $oModel->goldenweek = $other['goldenweek'];
             }
             if (!empty($other['controversy'])) {
                 $oModel->controversy = $other['controversy'];
             }
             $oModel->other = $other['other'];
             $oModel->effect = $other['effect'];
             $oModel->save();
         }
         $tran->commit();
     } catch (Exception $e) {
         $tran->rollBack();
         throw $e;
     }
 }