pmtpenza

Untitled

Jun 21st, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace backend\models;
  4.  
  5. use Yii;
  6. use backend\models\Uslugi;
  7.  
  8.  
  9. /**
  10. * This is the model class for table "zayvki".
  11. *
  12. * @property int $id
  13. * @property int $user_id
  14. * @property int $status
  15. * @property int $master
  16. * @property int $uk
  17. * @property string $create_at
  18. * @property int $oplata_id
  19. * @property string $data_vyp
  20.  
  21. *
  22. */
  23. class Zayvki extends \yii\db\ActiveRecord
  24. {
  25. public $uslugi_id;
  26. public $zayvki_id;
  27. public $typeuslug;
  28. public $category_id;
  29. const STATUS_NEW = 1;
  30. const STATUS_WORK = 2;
  31. const STATUS_NONWORK = 3;
  32. const STATUS_FINISH = 4;
  33.  
  34. const SERVICE_TYPES = [
  35. 1 => 'Услуга',
  36. 2 => 'Эконом',
  37. 3 => 'Доп. услуга',
  38. 4 => 'ОДН',
  39. ];
  40.  
  41.  
  42. public function getOrder(){
  43. return $this->hasOne(Order::className(), ['zayvki_id' => 'id']);
  44. }
  45. public function getUseruk(){
  46. return $this->hasOne(Users::className(), ['id' => 'uk']);
  47. }
  48. public function getUslugi(){
  49. return $this->hasOne(Uslugi::className(), ['id' => 'uslugi_id']);
  50. }
  51. public function getOplata(){
  52. return $this->hasOne(Oplata::className(), ['id' => 'oplata_id']);
  53. }
  54. public function getCategory(){
  55. return $this->hasOne(Category::className(), ['id' => 'category_id']);
  56. }
  57.  
  58. public function getUser(){
  59. return $this->hasOne(Users::className(), ['id' => 'user_id']);
  60. }
  61. public static function statuses()
  62. {
  63. return [
  64. self::STATUS_NEW => 'Новая',
  65. self::STATUS_WORK => 'В работе',
  66. self::STATUS_NONWORK => 'Отклонена',
  67. self::STATUS_FINISH => 'Выполненая',
  68. ];
  69. }
  70.  
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public static function tableName()
  75. {
  76. return 'zayvki';
  77. }
  78.  
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public function rules()
  83. {
  84. return [
  85. [['user_id'], 'required'],
  86. [['user_id', 'status', 'master', 'uk', 'oplata_id'], 'integer'],
  87. [['create_at'], 'safe'],
  88. [['status'], 'default', 'value' => 1],
  89. [['oplata_id'], 'default', 'value' => 1],
  90. ];
  91. }
  92.  
  93. /**
  94. * {@inheritdoc}
  95. */
  96. public function attributeLabels()
  97. {
  98. return [
  99. 'id' => '№ заявки',
  100. 'user_id' => 'Житель',
  101. 'status' => 'Статус',
  102. 'master' => 'Мастер',
  103. 'uk' => 'УК',
  104. 'create_at' => 'Дата заявки',
  105. 'oplata_id' => 'Способ оплаты',
  106. 'data_vyp' => 'Желаемое время',
  107. 'uslugi_id' => 'Услуга',
  108. 'typeName' => 'Тип услуги',
  109. 'koluslug' => 'Количество услуг',
  110. 'summa' => 'Сумма заявки',
  111. 'category_id' => 'Категория',
  112. ];
  113. }
  114. public function getTypeName()
  115. {
  116. $typeId = $this->order->uslugi->typeuslug;
  117. return self::SERVICE_TYPES[$typeId];
  118. }
  119. public function afterSave() {
  120. parent::afterSave();
  121. if($this->isNewRecord){
  122. $order = new Order;
  123. $order->zayvki_id = $this->id;
  124. $order->uslugi_id = $this->uslugi_id;
  125. $order->category_id = $this->category_id;
  126. $order->save();
  127. } else {
  128. Order::model()->updateAll(array( 'zayvki_id' =>$this->id,
  129. 'uslugi_id' => $this->uslugi_id,
  130. 'category_id'=>$this->catregory_id,
  131. ), 'zayvki_id=:zayvki_id', array(':zayvki_id'=> $this->id));
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment