Lots.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\db\ActiveRecord;
  5. use yii\helpers\FileHelper;
  6. use yii\web\UploadedFile;
  7. use app\models\Bidding;
  8. use app\models\Bills;
  9. use app\models\Auctions;
  10. /**
  11. * This is the model class for table "lots".
  12. *
  13. * @property integer $id
  14. * @property integer $user_id
  15. * @property string $name
  16. * @property string $description
  17. * @property double $start_price
  18. * @property string $step
  19. * @property integer $docs_id
  20. * @property Files|null $doc
  21. * @property string $address
  22. * @property integer $delivery_time
  23. * @property string $delivery_term
  24. * @property string $requires
  25. * @property string $payment_term
  26. * @property string $payment_order
  27. * @property integer $category_id
  28. * @property string $member_require
  29. * @property string $member_docs
  30. * @property integer $requisites_id
  31. * @property string $notes
  32. * @property integer $dogovor_id
  33. * @property string $date
  34. * @property integer $auction_date
  35. * @property integer $status
  36. * @property string $term_procedure
  37. * @property string $bidding_date
  38. * @property string $time_step_down
  39. * @property Units $unit
  40. * @property Images[] $images
  41. * @property Images[] $thumbnails
  42. */
  43. class Lots extends ActiveRecord
  44. {
  45. public $price_per_one;
  46. public $files;
  47. /**
  48. * @inheritdoc
  49. */
  50. public static function tableName()
  51. {
  52. return 'lots';
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function rules()
  58. {
  59. return [
  60. [['aukname', 'user_id', 'name', 'description', 'start_price', 'step', 'category_id', 'member_docs', 'date'], 'required'],
  61. [['user_id', 'category_id', 'status', 'lot_lock', 'docs_id', 'nds', 'num', 'unitId', 'count'], 'integer'],
  62. [['start_price', 'step'], 'number'],
  63. [['date', 'auction_date', 'bidding_date', 'address', 'step_down', 'time_step_down', 'notes', 'description'], 'safe'],
  64. [['aukname', 'name', 'delivery_term', 'delivery_time', 'requires', 'member_docs', 'delivery_time', 'delivery_term', 'requires'], 'string', 'max' => 800],
  65. [['price_per_one'], 'number', 'integerOnly' => false],
  66. [['files'], 'image'],
  67. [['file'],'file'],
  68. [['file'],'safe'],
  69. //[['notes', 'description', 'safe'], 'string', 'max' => 15000]
  70. ];
  71. }
  72. /** ,'dogovor_id', 'payment_term', 'payment_order', 'member_require', 'term_procedure','requisites_id'
  73. * @inheritdoc
  74. */
  75. public function attributeLabels()
  76. {
  77. return [
  78. 'id' => Yii::t('app', 'id'),
  79. 'count' => Yii::t('app', 'Кількість'),
  80. 'UnitId' => Yii::t('app', 'Одиниця виміру'),
  81. 'user_id' => Yii::t('app', 'User ID'),
  82. 'num' => Yii::t('app', 'LotNumber ID'),
  83. 'name' => Yii::t('app', 'Lot ID'),
  84. 'description' => Yii::t('app', 'LotsDescrioption ID'),
  85. 'start_price' => Yii::t('app', 'Price ID'),
  86. 'nds' => Yii::t('app', 'NDS ID'),
  87. 'step' => Yii::t('app', 'Step ID'),
  88. 'docs_id' => Yii::t('app', 'LotFiles ID'),
  89. 'address' => Yii::t('app', 'AddressTo ID'),
  90. 'delivery_time' => Yii::t('app', 'DeliveryTime ID'),
  91. 'delivery_term' => Yii::t('app', 'DeliveryTerm ID'),
  92. 'requires' => Yii::t('app', 'Требования к сроку и объему'),
  93. 'payment_term' => Yii::t('app', 'PaymentTerm ID'), // auclots
  94. 'payment_order' => Yii::t('app', 'Порядок формирования цен договора'), // auclots
  95. 'category_id' => Yii::t('app', 'Категория товара'),
  96. 'member_require' => Yii::t('app', 'MemberRequire ID'), // auclots
  97. 'member_docs' => Yii::t('app', 'Перечень документов'),
  98. 'term_procedure' => Yii::t('app', 'Term_procedure ID'), // auclots
  99. 'requisites_id' => Yii::t('app', 'Requisites ID'), // auclots
  100. 'notes' => Yii::t('app', 'LotsNotes ID'),
  101. 'dogovor_id' => Yii::t('app', 'Проект договора'), // auclots
  102. 'date' => Yii::t('app', 'Date ID'),
  103. 'auction_date' => Yii::t('app', 'AuctionDate ID'),
  104. 'status' => Yii::t('app', 'Status ID'),
  105. 'lot_lock' => Yii::t('app', 'Status ID'),
  106. 'aukname' => Yii::t('app', 'AukName ID'),
  107. 'categoryName' => Yii::t('app', 'Category ID'),
  108. 'bidding_date' => Yii::t('app', 'BiddingDate ID'),
  109. 'step_down' => Yii::t('app', 'Circle ID'),
  110. 'time_step_down' => Yii::t('app', 'Time Step'),
  111. 'unitName' => Yii::t('app', 'Одиниця виміру'),
  112. 'price_per_one' => Yii::t('app', 'Ціна за одиницю'),
  113. ];
  114. }
  115. public function save($validate = true, $attr = NULL)
  116. {
  117. if (empty($this->bidding_date)) {
  118. $lot = Auclots::findOne(['name' => $this->aukname]);
  119. //var_dump($lot); exit;
  120. //$this->address = $lot->address;
  121. $this->bidding_date = $lot->bidding_date;
  122. $this->auction_date = $lot->auction_date;
  123. $this->payment_term = $lot->payment_term;
  124. $this->payment_order = $lot->payment_order;
  125. $this->member_require = $lot->member_require;
  126. $this->term_procedure = $lot->term_procedure;
  127. $this->requisites_id = $lot->requisites_id;
  128. $this->dogovor_id = $lot->dogovor_id;
  129. $this->member_docs = "NULL";
  130. //$this->docs_id =
  131. //$this->time_step_down = $lot->time_step_down;
  132. }
  133. return parent::save($validate, $attr);
  134. }
  135. public function getRequisite()
  136. {
  137. return $this->hasOne(Requisites::className(), ['id' => 'requisites_id']);
  138. }
  139. public function getBillPayRegistration() {
  140. $sql = Yii::$app->db->createCommand("
  141. SELECT bills.id FROM bills
  142. LEFT JOIN bidding ON bills.bid_id = bidding.id
  143. LEFT JOIN auctions ON bidding.auction_id = auctions.id
  144. LEFT JOIN lots ON auctions.lot_id = lots.id
  145. WHERE bills.type = 'registration'
  146. ");
  147. $result = $sql->queryScalar();
  148. return $result;
  149. }
  150. public function getBillPayGuarantee() {
  151. $sql = Yii::$app->db->createCommand("
  152. SELECT bills.id FROM bills
  153. LEFT JOIN bidding ON bills.bid_id = bidding.id
  154. LEFT JOIN auctions ON bidding.auction_id = auctions.id
  155. LEFT JOIN lots ON auctions.lot_id = lots.id
  156. WHERE bills.type = 'guarantee'
  157. ");
  158. $result = $sql->queryScalar();
  159. return $result;
  160. }
  161. public function getAuction() {
  162. return $this->hasOne(Auctions::className(), ['lot_id' => 'id']);
  163. }
  164. public function getCategory()
  165. {
  166. return $this->hasOne(Category::className(), ['id' => 'category_id']);
  167. }
  168. public function getCategoryName()
  169. {
  170. return $this->category->name;
  171. }
  172. public function getFile()
  173. {
  174. return $this->hasOne(Files::className(), ['lot_id' => 'id']);
  175. }
  176. public function getImages()
  177. {
  178. return $this->hasMany(Images::className(), ['related_id' => 'id'])->andOnCondition(['type' => 'image']);
  179. }
  180. public function getThumbnails()
  181. {
  182. return $this->hasMany(Images::className(), ['related_id' => 'id'])->andOnCondition(['type' => 'thumbnail']);
  183. }
  184. public function getThumbnail()
  185. {
  186. return $this->hasOne(Images::className(), ['related_id' => 'id'])->andOnCondition(['type' => 'thumbnail']);
  187. }
  188. public function getRarFile()
  189. {
  190. return Yii::$app->response->sendFile($this->file->path . $this->file->name);
  191. }
  192. public function getUnit()
  193. {
  194. return $this->hasOne(Units::className(), ['id' => 'unitId']);
  195. }
  196. public function upload()
  197. {
  198. $files = UploadedFile::getInstances($this, 'files');
  199. foreach ($files as $file) {
  200. (new Images([
  201. 'type' => 'image',
  202. 'related_id' => $this->id,
  203. '_file' => $file,
  204. ]))->upload();
  205. }
  206. }
  207. }