Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\common\models;
- use app\common\exceptions\InvalidValueException;
- use app\common\interfaces\ExternalEntityInterface;
- use app\modules\v1\interfaces\PaymentModelInterface;
- use yii\db\ActiveQuery;
- use yii\db\ActiveRecord;
- /**
- * 'guid' => $this->guid(),
- 'user_guid' => $this->string(70),
- 'plan_id' => $this->string(70),
- 'club_guid' => $this->string(70),
- 'number' => $this->string(255),
- 'remove_created_at' => $this->dateTime(),
- 'begin_date' => $this->dateTime()->null(),
- 'end_date' => $this->dateTime()->null(),
- 'graphyc_name' => $this->string(255),
- 'external_guid' => $this->string(70),
- 'external_user_guid' => $this->string(70),
- 'client_id' => $this->integer(),
- *
- *
- *
- * @property string $guid
- * @property int $client_id
- * @property string $user_id
- * @property string $plan_id
- * @property string $club_guid
- * @property string $number
- * @property string $remove_created_at
- * @property string $begin_date
- * @property string $end_date
- * @property string $graphyc_name
- * @property boolean $active
- *
- * @property User $user
- * @property FreezePlan $plan
- * @property Club $club
- */
- class FreezePlanUser extends ActiveRecord implements PaymentModelInterface, ExternalEntityInterface
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'freeze_plan_user';
- }
- public function rules()
- {
- return [
- [['user_id', 'plan_id', 'club_guid'], 'string', 'max' => 70],
- [['number'], 'string', 'max' => 255],
- [['remove_created_at', 'begin_date', 'end_date'], 'safe'],
- [['user_id'], 'exist', 'targetRelation' => 'user'],
- [['plan_id'], 'exist', 'targetRelation' => 'plan'],
- [['club_guid'], 'exist', 'targetRelation' => 'club'],
- ];
- }
- /**
- * @return string
- */
- public function getGuid()
- {
- return $this->guid;
- }
- /**
- * @return int
- */
- public function getClientId()
- {
- return $this->client_id;
- }
- /**
- * @param int $id
- * @return self
- */
- public function setClientId(int $id)
- {
- $this->client_id = $id;
- return $this;
- }
- /**
- * @return ActiveQuery
- */
- public function getClient(): ActiveQuery
- {
- return $this->hasOne(Client::class, ['id' => 'client_id']);
- }
- public function payment()
- {
- $this->active = true;
- if (!$this->save()) {
- throw new \RuntimeException('Not saved freeze plan');
- }
- }
- public function getServer(): string
- {
- if ($this->club === null) {
- throw new InvalidValueException('Not found club.');
- }
- return $this->club->code;
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['guid' => 'user_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getPlan()
- {
- return $this->hasOne(FreezePlan::class, ['guid' => 'plan_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getClub()
- {
- return $this->hasOne(Club::class, ['guid' => 'club_guid']);
- }
- }
Add Comment
Please, Sign In to add comment