SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace app\common\models;
  4.  
  5. use app\common\exceptions\InvalidValueException;
  6. use app\common\interfaces\ExternalEntityInterface;
  7. use app\modules\v1\interfaces\PaymentModelInterface;
  8. use yii\db\ActiveQuery;
  9. use yii\db\ActiveRecord;
  10.  
  11. /**
  12.  * 'guid' => $this->guid(),
  13. 'user_guid' => $this->string(70),
  14. 'plan_id'   => $this->string(70),
  15. 'club_guid' => $this->string(70),
  16. 'number'    => $this->string(255),
  17. 'remove_created_at' => $this->dateTime(),
  18. 'begin_date' => $this->dateTime()->null(),
  19. 'end_date' => $this->dateTime()->null(),
  20. 'graphyc_name' => $this->string(255),
  21. 'external_guid' => $this->string(70),
  22. 'external_user_guid' => $this->string(70),
  23. 'client_id' => $this->integer(),
  24.  *
  25.  *
  26.  *
  27.  * @property string $guid
  28.  * @property int    $client_id
  29.  * @property string $user_id
  30.  * @property string $plan_id
  31.  * @property string $club_guid
  32.  * @property string $number
  33.  * @property string $remove_created_at
  34.  * @property string $begin_date
  35.  * @property string $end_date
  36.  * @property string $graphyc_name
  37.  * @property boolean $active
  38.  *
  39.  * @property User $user
  40.  * @property FreezePlan $plan
  41.  * @property Club $club
  42.  */
  43. class FreezePlanUser extends ActiveRecord implements PaymentModelInterface, ExternalEntityInterface
  44. {
  45.     /**
  46.      * @inheritdoc
  47.      */
  48.     public static function tableName()
  49.     {
  50.         return 'freeze_plan_user';
  51.     }
  52.  
  53.     public function rules()
  54.     {
  55.         return [
  56.             [['user_id', 'plan_id', 'club_guid'], 'string', 'max' => 70],
  57.             [['number'], 'string', 'max' => 255],
  58.             [['remove_created_at', 'begin_date', 'end_date'], 'safe'],
  59.  
  60.             [['user_id'], 'exist', 'targetRelation' => 'user'],
  61.             [['plan_id'], 'exist', 'targetRelation' => 'plan'],
  62.             [['club_guid'], 'exist', 'targetRelation' => 'club'],
  63.         ];
  64.     }
  65.  
  66.     /**
  67.      * @return string
  68.      */
  69.     public function getGuid()
  70.     {
  71.         return $this->guid;
  72.     }
  73.  
  74.     /**
  75.      * @return int
  76.      */
  77.     public function getClientId()
  78.     {
  79.         return $this->client_id;
  80.     }
  81.  
  82.     /**
  83.      * @param int $id
  84.      * @return self
  85.      */
  86.     public function setClientId(int $id)
  87.     {
  88.         $this->client_id = $id;
  89.         return $this;
  90.     }
  91.  
  92.     /**
  93.      * @return ActiveQuery
  94.      */
  95.     public function getClient(): ActiveQuery
  96.     {
  97.         return $this->hasOne(Client::class, ['id' => 'client_id']);
  98.     }
  99.  
  100.     public function payment()
  101.     {
  102.         $this->active = true;
  103.         if (!$this->save()) {
  104.             throw new \RuntimeException('Not saved freeze plan');
  105.         }
  106.     }
  107.  
  108.     public function getServer(): string
  109.     {
  110.         if ($this->club === null) {
  111.             throw new InvalidValueException('Not found club.');
  112.         }
  113.  
  114.         return $this->club->code;
  115.     }
  116.  
  117.     /**
  118.      * @return \yii\db\ActiveQuery
  119.      */
  120.     public function getUser()
  121.     {
  122.         return $this->hasOne(User::class, ['guid' => 'user_id']);
  123.     }
  124.  
  125.     /**
  126.      * @return \yii\db\ActiveQuery
  127.      */
  128.     public function getPlan()
  129.     {
  130.         return $this->hasOne(FreezePlan::class, ['guid' => 'plan_id']);
  131.     }
  132.  
  133.     /**
  134.      * @return \yii\db\ActiveQuery
  135.      */
  136.     public function getClub()
  137.     {
  138.         return $this->hasOne(Club::class, ['guid' => 'club_guid']);
  139.     }
  140. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top