pmtpenza

Untitled

Jul 16th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <?php
  2.  
  3. namespace backend\models;
  4.  
  5. use Yii;
  6. use backend\models\Staussdelki;
  7. use backend\models\TypeZakaz;
  8. use yii\helpers\FileHelper;
  9. use yii\web\UploadedFile;
  10. use yii\helpers\Url;
  11.  
  12. /**
  13. * This is the model class for table "deals".
  14. *
  15. * @property int $id
  16. * @property string $budget
  17. * @property string $budg
  18. * @property string $tz_doc
  19. * @property string $tz_text
  20. * @property int $user_id
  21. * @property string $date
  22. * @property string $notes
  23. * @property string $doc
  24. * @property string $payment
  25. * @property string $paymentdate
  26. * @property int $staussdelki_id
  27. * @property string $finch_date
  28. */
  29. class Deals extends \yii\db\ActiveRecord
  30. {
  31. public $file;
  32. public $file2;
  33.  
  34. public function getStatussdel(){
  35. return $this->hasOne(Staussdelki::className(), ['id' => 'staussdelki_id']);
  36. }
  37. public function getType(){
  38. return $this->hasOne(TypeZakaz::className(), ['id' => 'type_zakaz_id']);
  39. }
  40. public function getManadger(){
  41. return $this->hasOne(Users::className(), ['id' => 'user_id']);
  42. }
  43. public function getClient(){
  44. return $this->hasOne(Client::className(), ['id' => 'client_id']);
  45. }
  46. public function getOrders(){
  47. return $this->hasMany(Order::className(), ['deals_id' => 'id']);
  48. }
  49.  
  50. public function getOrder(){
  51. return $this->hasOne(Order::className(), ['deals_id' => 'id']);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public static function tableName()
  57. {
  58. return 'deals';
  59. }
  60.  
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function rules()
  65. {
  66. return [
  67. [['user_id','staussdelki_id'], 'required'],
  68. [['user_id', 'payment', 'staussdelki_id', 'client_id'], 'integer'],
  69. [['date', 'notes', 'paymentdate', 'finch_date'], 'string', 'max' => 50],
  70. [['tz_doc', 'doc'],'string','max'=>100],
  71.  
  72. ];
  73. }
  74.  
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function attributeLabels()
  79. {
  80. return [
  81. 'id' => '№',
  82. 'client_id' => 'Клиент(Компания, ФИО)',
  83. 'budget' => 'Бюджет',
  84. 'tz_text' => 'ТЗ описание',
  85. 'tz_doc' => 'ТЗ документ',
  86. 'file' => 'ТЗ документ',
  87. 'file2' => 'Документы',
  88. 'user_id' => 'Менеджер',
  89. 'date' => 'Начало сделки',
  90. 'notes' => 'Заметки',
  91. 'doc' => 'Документы',
  92. 'payment' => 'Оплата сумма',
  93. 'paymentdate' => 'Дата оплаты',
  94. 'staussdelki_id' => 'Статус сделки',
  95. 'sum' => 'Гонорар менеджера',
  96. 'finch_date' => 'Конец сделки',
  97. ];
  98. }
  99. public function beforeSave ($insert){
  100. if ($file = UploadedFile::getInstance($this, 'file')){
  101. $dir = Yii::getAlias('@images').'/dop/';
  102. if(!file_exists($dir)){
  103. FileHelper::createDirectory($dir);
  104. }
  105. if (file_exists($dir.$this->tz_doc)){
  106.  
  107. }
  108. /* if(file_exists($dir.'50x50/'.$this->image)){
  109.  
  110. }
  111. if(file_exists($dir.'800x/'.$this->image)){
  112.  
  113. }*/
  114. $this->tz_doc = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) .'.'.$file->extension;
  115. $file->saveAs($dir.$this->tz_doc);
  116. /* $imag = Yii::$app->image->load($dir.$this->image);
  117. $imag->background('#fff',0);
  118. $imag->resize('50','50');
  119. $imag->crop('50',50);
  120. $imag->save($dir.'/50x50'.$this->image,90);
  121. $imag = Yii::$app->image->load($dir.$this->image);
  122. $imag->background('#fff',0);
  123. $imag->resize('800',null, Yii\image\drivers\Image::INVERSE);
  124. $imag->save($dir.'/800x'.$this->image,90);*/
  125. if ($file2 = UploadedFile::getInstance($this, 'file2')){
  126. $dir = Yii::getAlias('@images').'/dop/';
  127. if(!file_exists($dir)){
  128. FileHelper::createDirectory($dir);
  129. }
  130. if (file_exists($dir.$this->doc)){
  131.  
  132. }
  133. /* if(file_exists($dir.'50x50/'.$this->image)){
  134.  
  135. }
  136. if(file_exists($dir.'800x/'.$this->image)){
  137.  
  138. }*/
  139. $this->doc = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) .'.'.$file2->extension;
  140. $file->saveAs($dir.$this->doc);
  141. /* $imag = Yii::$app->image->load($dir.$this->image);
  142. $imag->background('#fff',0);
  143. $imag->resize('50','50');
  144. $imag->crop('50',50);
  145. $imag->save($dir.'/50x50'.$this->image,90);
  146. $imag = Yii::$app->image->load($dir.$this->image);
  147. $imag->background('#fff',0);
  148. $imag->resize('800',null, Yii\image\drivers\Image::INVERSE);
  149. $imag->save($dir.'/800x'.$this->image,90);*/
  150. }
  151. return parent::beforeSave($insert);
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment