[ 'label' => 'Отправитель', ], 2 => [ 'label' => 'Получатель', ], ]; public static function tableName() { return 'order'; } public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), ], ]; } public function rules() { return [ [ [ 'pay' ], 'boolean', ], [ [ 'created_at', 'updated_at', 'deleted_at', 'payment', 'reason', 'label', ], 'integer', ], [ [ 'phone', ], 'required', ], [ [ 'comment' ], 'string', ], [ [ 'email' ], 'email', ], [ [ 'phone', 'phone2', ], 'match', 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', ], [ [ 'deadline', 'name', 'numbercard', 'body', 'declaration', 'stock', 'consignment', 'insurance', 'amount_imposed', 'shipping_by', 'city', 'adress', 'total', 'status', 'check', 'sms', ], 'string', 'max' => 255, ], ]; } public function afterFind() { parent::afterFind(); $this->deadline = !empty( $this->deadline ) ? date('d.m.Y', $this->deadline) : ''; } public function beforeSave($insert) { if (parent::beforeSave($insert)) { $this->convertDate(); return true; } return false; } protected function convertDate() { if (!empty( $this->deadline )) { $date = new \DateTime($this->deadline); $date->format("d.m.Y"); $this->deadline = $date->getTimestamp(); } } public function attributeLabels() { return [ 'name' => Yii::t('app', 'order_name'), 'phone' => Yii::t('app', 'order_phone'), 'email' => Yii::t('app', 'order_email'), 'comment' => Yii::t('app', 'order_comment'), 'created_at' => Yii::t('app', 'Дата добавления'), 'updated_at' => Yii::t('app', 'Дата обновления'), 'deleted_at' => Yii::t('app', 'Дата удаления'), 'deadline' => Yii::t('app', 'Дедлайн'), 'reason' => Yii::t('app', 'Причина'), 'check' => Yii::t('app', 'Чек'), 'sms' => Yii::t('app', 'СМС'), ]; } public function getUser() { return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]); } /** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]); } /** * @return \yii\db\ActiveQuery */ public function getOrderDelivery() { return $this->hasOne(Delivery::className(), [ 'id' => 'delivery' ]); } /** * @return \yii\db\ActiveQuery */ public function getOrderLabel() { return $this->hasOne(Label::className(), [ 'id' => 'status' ]); } /** * @return \yii\db\ActiveQuery */ public function getOrderPayment() { return $this->hasOne(OrderPayment::className(), [ 'id' => 'payment' ]); } /** * @return string */ public function getDeliveryString() { if (!empty( $this->orderDelivery )) { if (!empty( $this->orderDelivery->parent )) { return $this->orderDelivery->parent->lang->title . ': ' . $this->orderDelivery->lang->title; } else { return $this->orderDelivery->lang->title; } } else { return ''; } } }