/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = InvitationCode::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['id' => $this->id, 'code' => $this->code, 'use_id' => $this->use_id, 'status' => $this->status, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); return $dataProvider; }
/** * Finds the InvitationCode model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return InvitationCode the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = InvitationCode::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 使用邀请码 * @param $id * @param $uid * @return bool|string */ public static function use_code($id, $uid) { $log = InvitationCode::findOne($id); if ($log) { $log->use_id = $uid; $log->status = InvitationCode::STATUS_USED; if ($log->save()) { return true; } else { return 'save error'; } } else { return 'find error'; } }