/** * 生成合同号 * @param bool $isAutomatic 是否自动生成 * @return string */ static function generateNumber($isAutomatic = true, $type, $oldcontr = '') { $arr_number = []; //生成号 if ($isAutomatic) { $arr_number[] = Contract::CONTRNO_SYSTEM; } else { $arr_number[] = Contract::CONTRNO_APP; } //经营许可证号简写 $user = AccessTokenService::getCurrentUser(); $license = str_replace('-', '', $user->org->license); $arr_number[] = $license; if ($isAutomatic) { $arr_number[] = strtoupper($type); //类型 $arr_number[] = DataHelper::getCurrentDate('Ymd'); //年月日 $arr_number[] = substr(microtime(), 2, 5); //5位流水号 } else { $arr_number[] = $oldcontr; } return implode('', $arr_number); }
?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Razz', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'title', ['attribute' => 'uid', 'value' => function ($model) { return isset($model->user->username) ? $model->user->username . '[' . $model->uid . ']' : 'none[0]'; }], ['attribute' => 'responder_uid', 'value' => function ($model) { return isset($model->responder->username) ? $model->responder->username . '[' . $model->responder_uid . ']' : 'none[0]'; }], ['attribute' => 'type', 'value' => function ($model) { return $model->type == 1 ? 'some[1]' : 'any[2]'; }], ['label' => 'Time left', 'value' => function ($model) { if ($model->responder_uid) { $time = DataHelper::downcounter(date("Y-m-d H:i:s", $model->created_at + Razz::DAYS)); } else { $time = 'Waiting'; } return $time ? $time : 'Ended'; }], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * @return mixed */ public function getSignTimeF() { if (empty($this->sign_time)) { return ''; } return DataHelper::getSignTime($this->sign_time); }
public function tree($vid, $parent = 0, $max_depth = NULL) { static $trees = []; if (empty($trees[$vid])) { $tree = array(); $cleanParent = array(); $elems = \Yii::$app->db->createCommand('SELECT * FROM {{%taxonomy_items}} taxonomy_items WHERE vid = :vid ORDER BY weight')->bindValue(':vid', $vid)->queryAll(); foreach ($elems as $itm) { $tree[$itm['id']] = $itm; } $tree = DataHelper::treeMap($tree); $trees[$vid] = $tree; } else { $tree = $trees[$vid]; } if ($parent) { $tree = DataHelper::treeParent($tree, $parent); } if ($max_depth !== NULL) { $tree = DataHelper::treeDepth($tree, $max_depth); } return $tree; }
/** * 上传电子合同[未提交] * @author lvkui * @date 2016011 */ public function actionUploadEc() { $map = self::getRestMap(); try { //验证 AccessTokenService::validateToken(Yii::$app->request); $ec = new EcService(); if (!isset($_POST['data'])) { throw new Exception('an empty string is not allowed for $data'); } $data = $_POST['data']; $ec->sys_submitContract($data, false); $map[AjaxStatus::PROPERTY_MESSAGES] = "业务处理成功"; $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_SUCCESSFUL; $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_OK; $map[AjaxStatus::PROPERTY_DATA] = array('oid' => '1122121', 'name' => DataHelper::getRequestParam('name')); } catch (IllegalArgumentException $e) { $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_FAILED; $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_503; $map[AjaxStatus::PROPERTY_MESSAGES] = $e->getMessage(); } catch (Exception $e) { $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_FAILED; $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_503; $map[AjaxStatus::PROPERTY_MESSAGES] = $e->getMessage(); } echo json_encode($map); }
<div class="jumbotron"> <?php if (isset($object)) { $razzdViews = $razzModel->getViewsTotalByRid($object['id']); ?> <section class="main-video border-bottom"> <h2 class="title-visual-time"> <?php echo Html::encode($object['title']); ?> <span class="time highlight">TIME REMAINING: <?php $razzModel->addView($object['id'], Yii::$app->user->id); if ($object['created_at'] + Razz::DAYS > time()) { echo DataHelper::downcounter(date("Y-m-d H:i:s", $object['created_at'] + Razz::DAYS)); } else { echo 'ENDED'; } ?> </span> </h2> <div class="visual"> <div class="visual-sections"> <div class="visual-section"> <div class="visual-person"> <?php echo ZiggeoHelper::getImage($object['id'], $object['stream'], $object['stream_preview'], false, "video-preview", true); ?> </div> <div class="info-person" id="r1">
public static function validateAPIAuth($appkey, $clientid, $clientsecurity) { /** * @var AccessToken $accessToken * @var AccessApp $accessApp */ //app $accessApp = AccessApp::find()->andWhere('appkey=:appkey', array(':appkey' => $appkey))->one(); if (empty($accessApp)) { throw new Exception('传入appkey 错误'); } if ($accessApp->client_id != $clientid) { throw new Exception('client_id 错误'); } if ($accessApp->client_secret != $clientsecurity) { throw new Exception('client_secret 错误'); } $accessToken = AccessToken::findOne(array('clientid' => $clientid, 'appkey' => $appkey)); $usable = true; if (!empty($accessToken)) { $date1 = date_create(BaseDataHelper::getCurrentTime()); $date2 = date_create($accessToken->createtime); $diff = date_diff($date1, $date2); if ($diff->format('%y') > 0 || $diff->format('%m') > 0 || $diff->format('%d') > 0 || $diff->format('%h') > 0 || $diff->format('%i') > $accessToken->validity / 60) { $accessToken->delete(); $usable = false; } } else { $usable = false; } //token if (!$usable) { $accessToken = new AccessToken(); $accessToken->tokenid = DataHelper::random(10); $accessToken->appkey = $appkey; $accessToken->clientid = $clientid; $accessToken->validity = 600; //60秒 $accessToken->uid = $accessApp->uid; $accessToken->orgid = $accessApp->user->orgid; if (!$accessToken->save()) { var_dump($accessToken->errors); die; } //当前登录人信息 $session = Yii::$app->session; $model = AccessToken::findOne(array('tokenid' => $accessToken->tokenid)); $session->set('user', $model->user); } return $accessToken; }
/** * This method is called at the beginning of inserting or updating a record. * The default implementation will trigger an [[EVENT_BEFORE_INSERT]] event when `$insert` is true, * or an [[EVENT_BEFORE_UPDATE]] event if `$insert` is false. * When overriding this method, make sure you call the parent implementation like the following: * * @param boolean $insert whether this method called while inserting a record. * If false, it means the method is called while updating a record. * @return boolean whether the insertion or updating should continue. * If false, the insertion or updating will be cancelled. */ public function beforeSave($insert) { if ($this->isNewRecord) { //$this->tokenid = 'ssda'; $this->createtime = DataHelper::getCurrentTime(); } return parent::beforeSave($insert); }
/** * 上传或者提交合同 * @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; } }