Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace backend\models;
- use Yii;
- use backend\models\Uslugi;
- /**
- * This is the model class for table "zayvki".
- *
- * @property int $id
- * @property int $user_id
- * @property int $status
- * @property int $master
- * @property int $uk
- * @property string $create_at
- * @property int $oplata_id
- * @property string $data_vyp
- *
- */
- class Zayvki extends \yii\db\ActiveRecord
- {
- public $uslugi_id;
- public $zayvki_id;
- public $typeuslug;
- public $category_id;
- const STATUS_NEW = 1;
- const STATUS_WORK = 2;
- const STATUS_NONWORK = 3;
- const STATUS_FINISH = 4;
- const SERVICE_TYPES = [
- 1 => 'Услуга',
- 2 => 'Эконом',
- 3 => 'Доп. услуга',
- 4 => 'ОДН',
- ];
- public function getOrder(){
- return $this->hasOne(Order::className(), ['zayvki_id' => 'id']);
- }
- public function getUseruk(){
- return $this->hasOne(Users::className(), ['id' => 'uk']);
- }
- public function getUslugi(){
- return $this->hasOne(Uslugi::className(), ['id' => 'uslugi_id']);
- }
- public function getOplata(){
- return $this->hasOne(Oplata::className(), ['id' => 'oplata_id']);
- }
- public function getCategory(){
- return $this->hasOne(Category::className(), ['id' => 'category_id']);
- }
- public function getUser(){
- return $this->hasOne(Users::className(), ['id' => 'user_id']);
- }
- public static function statuses()
- {
- return [
- self::STATUS_NEW => 'Новая',
- self::STATUS_WORK => 'В работе',
- self::STATUS_NONWORK => 'Отклонена',
- self::STATUS_FINISH => 'Выполненая',
- ];
- }
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'zayvki';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id'], 'required'],
- [['user_id', 'status', 'master', 'uk', 'oplata_id'], 'integer'],
- [['create_at'], 'safe'],
- [['status'], 'default', 'value' => 1],
- [['oplata_id'], 'default', 'value' => 1],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '№ заявки',
- 'user_id' => 'Житель',
- 'status' => 'Статус',
- 'master' => 'Мастер',
- 'uk' => 'УК',
- 'create_at' => 'Дата заявки',
- 'oplata_id' => 'Способ оплаты',
- 'data_vyp' => 'Желаемое время',
- 'uslugi_id' => 'Услуга',
- 'typeName' => 'Тип услуги',
- 'koluslug' => 'Количество услуг',
- 'summa' => 'Сумма заявки',
- 'category_id' => 'Категория',
- ];
- }
- public function getTypeName()
- {
- $typeId = $this->order->uslugi->typeuslug;
- return self::SERVICE_TYPES[$typeId];
- }
- public function afterSave() {
- parent::afterSave();
- if($this->isNewRecord){
- $order = new Order;
- $order->zayvki_id = $this->id;
- $order->uslugi_id = $this->uslugi_id;
- $order->category_id = $this->category_id;
- $order->save();
- } else {
- Order::model()->updateAll(array( 'zayvki_id' =>$this->id,
- 'uslugi_id' => $this->uslugi_id,
- 'category_id'=>$this->catregory_id,
- ), 'zayvki_id=:zayvki_id', array(':zayvki_id'=> $this->id));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment