Lots.php 8.9 KB

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