Publishing.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "auctions".
  6. *
  7. * @property integer $id
  8. * @property string $name
  9. * @property integer $user_id
  10. * @property integer $lot_id
  11. * @property string $date_start
  12. * @property string $date_stop
  13. * @property double $last_price
  14. * @property integer $last_user
  15. * @property string $last_date
  16. * @property integer $type
  17. * @property integer $status
  18. * @property Lots $lot
  19. */
  20. class Publishing extends \yii\db\ActiveRecord
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return 'auctions';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['name', 'user_id', 'lot_id', 'last_price', 'last_user','status'], 'required'],
  36. [['user_id', 'lot_id', 'last_user', 'type'], 'integer'],
  37. [['date_start', 'date_stop', 'last_date','userName', 'lotNum','lotName','statusName','endBidding','lotDesc','lotPrice','lotStep'], 'safe'],
  38. [['last_price'], 'number'],
  39. [['name'], 'string', 'max' => 30],
  40. [['lot_id'], 'unique']
  41. ];
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => Yii::t('app', 'Number ID'),
  50. 'name' => Yii::t('app', 'AukName ID'),
  51. 'user_id' => Yii::t('app', 'организатор'),
  52. 'lot_id' => Yii::t('app', 'лот'),
  53. 'date_start' => Yii::t('app', 'PublishDateStart ID'),
  54. 'date_stop' => Yii::t('app', 'дата завершения'),
  55. 'last_price' => Yii::t('app', 'текущая цена'),
  56. 'last_user' => Yii::t('app', 'ставка последнего юзера'),
  57. 'last_date' => Yii::t('app', 'время последней ставки'),
  58. 'type' => Yii::t('app', 'type'),
  59. 'status' => Yii::t('app', 'statusName ID'),
  60. 'lotName' => Yii::t('app', 'Predmet ID'),
  61. 'userName' => Yii::t('app', 'OrgName ID'),
  62. 'statusName' => Yii::t('app', 'statusName ID'),
  63. 'endBidding' => Yii::t('app', 'endBidding ID'),
  64. 'created_at' => Yii::t('app','BiddingStartDate ID'),
  65. 'lotDesc' => Yii::t('app', 'PublishLotDesc ID'),
  66. 'lotPrice' => Yii::t('app', 'StartPrice ID'),
  67. 'lotStep' => Yii::t('app', 'Step ID'),
  68. 'NDS' => Yii::t('app', 'NDS ID'),
  69. //'Pterm' => Yii::t('app', 'PaymentTerm ID'),
  70. ];
  71. }
  72. public function getLot()
  73. {
  74. return $this->hasOne(Lots::className(), ['id' => 'lot_id']);
  75. }
  76. public function getUser()
  77. {
  78. return $this->hasOne(User::className(), ['id' => 'user_id']);
  79. }
  80. public function getProfile(){
  81. return $this->hasOne(Profile::className(), ['user_id' => 'id'])->via('user');
  82. }
  83. public function getLotName()
  84. {
  85. if($this->lot)
  86. {
  87. return $this->lot->name;
  88. }
  89. else
  90. {
  91. return false;
  92. }
  93. }
  94. public function getUserName()
  95. {
  96. if($this->user)
  97. {
  98. return $this->user->at_org;
  99. }
  100. else
  101. {
  102. return false;
  103. }
  104. }
  105. public function getLotNum()
  106. {
  107. return $this->lot->num;
  108. }
  109. public function getLotDesc()
  110. {
  111. return $this->lot->description;
  112. }
  113. public function getLotPrice()
  114. {
  115. return $this->lot->start_price;
  116. }
  117. public function getNDS()
  118. {
  119. $nds = $this->lot->nds;
  120. if($nds==1)
  121. {
  122. return 'з ПДВ';///Yii::t('app', 'withNDS ID');
  123. }
  124. else
  125. {
  126. return Yii::t('app', 'withoutNDS ID');
  127. }
  128. }
  129. public function getLotStep()
  130. {
  131. return $this->lot->step;
  132. }
  133. public function getEndBidding()
  134. {
  135. if($this->lot)
  136. {
  137. return $this->lot->bidding_date;
  138. }
  139. else
  140. {
  141. return false;
  142. }
  143. }
  144. function getStatusName()
  145. {
  146. if($this->status==0)
  147. {
  148. return Yii::t('app','pMakeBidding ID');
  149. }
  150. if($this->status==1)
  151. {
  152. return Yii::t('app','pWaitAuction ID');
  153. }
  154. elseif($this->status==2)
  155. {
  156. return Yii::t('app','pMakeAuction ID');
  157. }
  158. elseif($this->status==3)
  159. {
  160. return Yii::t('app','pMakeFinal ID');
  161. }
  162. elseif($this->status==4)
  163. {
  164. return Yii::t('app','pEndTorg ID');
  165. }
  166. else
  167. {
  168. return false;
  169. }
  170. }
  171. public function setLotName()
  172. {
  173. // add
  174. }
  175. public function setUserName()
  176. {
  177. // add
  178. }
  179. public function setEndBidding()
  180. {
  181. // add
  182. }
  183. public function getProtocol()
  184. {
  185. $protocol = Files::find()->where(['user_id'=>'23','auction_id'=>$this->id])->one();
  186. if($protocol)
  187. {
  188. return $protocol;
  189. }
  190. else
  191. {
  192. return false;
  193. }
  194. }
  195. public function fields()
  196. {
  197. return [
  198. 'id',
  199. 'userName',
  200. 'lotNum',
  201. 'lotName',
  202. 'user_id',
  203. 'endBidding',
  204. 'statusName',
  205. ];
  206. }
  207. }