Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace backend\models;
- use Yii;
- use backend\models\Staussdelki;
- use backend\models\TypeZakaz;
- use yii\helpers\FileHelper;
- use yii\web\UploadedFile;
- use yii\helpers\Url;
- /**
- * This is the model class for table "deals".
- *
- * @property int $id
- * @property string $budget
- * @property string $budg
- * @property string $tz_doc
- * @property string $tz_text
- * @property int $user_id
- * @property string $date
- * @property string $notes
- * @property string $doc
- * @property string $payment
- * @property string $paymentdate
- * @property int $staussdelki_id
- * @property string $finch_date
- */
- class Deals extends \yii\db\ActiveRecord
- {
- public $file;
- public $file2;
- public function getStatussdel(){
- return $this->hasOne(Staussdelki::className(), ['id' => 'staussdelki_id']);
- }
- public function getType(){
- return $this->hasOne(TypeZakaz::className(), ['id' => 'type_zakaz_id']);
- }
- public function getManadger(){
- return $this->hasOne(Users::className(), ['id' => 'user_id']);
- }
- public function getClient(){
- return $this->hasOne(Client::className(), ['id' => 'client_id']);
- }
- public function getOrders(){
- return $this->hasMany(Order::className(), ['deals_id' => 'id']);
- }
- public function getOrder(){
- return $this->hasOne(Order::className(), ['deals_id' => 'id']);
- }
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'deals';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id','staussdelki_id'], 'required'],
- [['user_id', 'payment', 'staussdelki_id', 'client_id'], 'integer'],
- [['date', 'notes', 'paymentdate', 'finch_date'], 'string', 'max' => 50],
- [['tz_doc', 'doc'],'string','max'=>100],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '№',
- 'client_id' => 'Клиент(Компания, ФИО)',
- 'budget' => 'Бюджет',
- 'tz_text' => 'ТЗ описание',
- 'tz_doc' => 'ТЗ документ',
- 'file' => 'ТЗ документ',
- 'file2' => 'Документы',
- 'user_id' => 'Менеджер',
- 'date' => 'Начало сделки',
- 'notes' => 'Заметки',
- 'doc' => 'Документы',
- 'payment' => 'Оплата сумма',
- 'paymentdate' => 'Дата оплаты',
- 'staussdelki_id' => 'Статус сделки',
- 'sum' => 'Гонорар менеджера',
- 'finch_date' => 'Конец сделки',
- ];
- }
- public function beforeSave ($insert){
- if ($file = UploadedFile::getInstance($this, 'file')){
- $dir = Yii::getAlias('@images').'/dop/';
- if(!file_exists($dir)){
- FileHelper::createDirectory($dir);
- }
- if (file_exists($dir.$this->tz_doc)){
- }
- /* if(file_exists($dir.'50x50/'.$this->image)){
- }
- if(file_exists($dir.'800x/'.$this->image)){
- }*/
- $this->tz_doc = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) .'.'.$file->extension;
- $file->saveAs($dir.$this->tz_doc);
- /* $imag = Yii::$app->image->load($dir.$this->image);
- $imag->background('#fff',0);
- $imag->resize('50','50');
- $imag->crop('50',50);
- $imag->save($dir.'/50x50'.$this->image,90);
- $imag = Yii::$app->image->load($dir.$this->image);
- $imag->background('#fff',0);
- $imag->resize('800',null, Yii\image\drivers\Image::INVERSE);
- $imag->save($dir.'/800x'.$this->image,90);*/
- if ($file2 = UploadedFile::getInstance($this, 'file2')){
- $dir = Yii::getAlias('@images').'/dop/';
- if(!file_exists($dir)){
- FileHelper::createDirectory($dir);
- }
- if (file_exists($dir.$this->doc)){
- }
- /* if(file_exists($dir.'50x50/'.$this->image)){
- }
- if(file_exists($dir.'800x/'.$this->image)){
- }*/
- $this->doc = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) .'.'.$file2->extension;
- $file->saveAs($dir.$this->doc);
- /* $imag = Yii::$app->image->load($dir.$this->image);
- $imag->background('#fff',0);
- $imag->resize('50','50');
- $imag->crop('50',50);
- $imag->save($dir.'/50x50'.$this->image,90);
- $imag = Yii::$app->image->load($dir.$this->image);
- $imag->background('#fff',0);
- $imag->resize('800',null, Yii\image\drivers\Image::INVERSE);
- $imag->save($dir.'/800x'.$this->image,90);*/
- }
- return parent::beforeSave($insert);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment