Exemple #1
0
 /**
  * 获取单个投资项目信息
  * @param $id
  * @return array|null|\yii\db\ActiveRecord
  * @throws ErrorException
  */
 public static function fundOne($id)
 {
     if (is_numeric($id)) {
         $fund_one = product::find()->where(['id' => $id])->asArray()->one();
         if ($fund_one) {
             return $fund_one;
         } else {
             throw new ErrorException("项目不存在", "100");
         }
     } else {
         throw new ErrorException('参数错误', '404');
     }
 }
Exemple #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = product::find()->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $ucmember = new UcenterMember();
     $user = new User();
     $ocreditor = $ucmember->find()->andWhere(['username' => $this->ocreditor])->one();
     $oid = $ocreditor ? $ocreditor->id : '';
     $maxcreditor = $ucmember->find()->andWhere(['username' => $this->maxcreditor])->one();
     $mid = $maxcreditor ? $maxcreditor->id : '';
     $user = $user->find()->andWhere(['username' => $this->create_user_id])->one();
     $uid = $user ? $user->id : '';
     $query->andFilterWhere(['id' => $this->id, 'amount' => $this->amount, 'start_at' => $this->start_at, 'end_at' => $this->end_at, 'rate' => $this->rate, 'invest_people' => $this->invest_people, 'invest_sum' => $this->invest_sum, 'create_at' => $this->create_at, 'update_at' => $this->update_at, 'status' => $this->status, 'type' => $this->type, 'create_user_id' => $uid, 'check_user_id' => $this->check_user_id, 'ocreditor' => $oid, 'maxcreditor' => $mid]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'each_max', $this->each_max])->andFilterWhere(['like', 'each_min', $this->each_min]);
     return $dataProvider;
 }
 /**
  * Finds the product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }