Bills.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * This is the model class for table "bills".
  7. *
  8. * @property int $id
  9. * @property int $user_id
  10. * @property string $type
  11. * @property int $lot_id
  12. * @property User $user
  13. */
  14. class Bills extends \yii\db\ActiveRecord {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public static function tableName() {
  19. return 'bills';
  20. }
  21. /*
  22. * without migrations
  23. * */
  24. public static function create(Bidding $bid) {
  25. $data = [
  26. 'user_id' => Yii::$app->user->id,
  27. 'type' => 'guarantee',
  28. 'bid_id' => $bid->id,
  29. 'payed' => 0,
  30. 'auction_id' => $bid->auction_id,
  31. ];
  32. (new Bills($data))->save(false);
  33. $data['type'] = 'registration';
  34. (new Bills($data))->save(false);
  35. return true;
  36. }
  37. public static function types() {
  38. return
  39. [
  40. 'guarantee' => Yii::t('app', 'Guaranteed payment'),
  41. 'registration' => Yii::t('app', 'Registration fee'),
  42. ];
  43. }
  44. public static function payStatuses() {
  45. return
  46. [
  47. '0' => Yii::t('app','Нові'),
  48. '1' => Yii::t('app','Сплачено'),
  49. '2' => Yii::t('app','Не сплачено'),
  50. ];
  51. }
  52. public function rules() {
  53. return [
  54. [['user_id', 'type', 'bid_id'], 'required'],
  55. [['user_id','auction_id' ,'bid_id'], 'integer'],
  56. [['type'], 'in', 'range' => array_keys(static::types())],
  57. [['payed'], 'in', 'range' => array_keys(static::payStatuses())],
  58. ];
  59. }
  60. // public function getLotName() {
  61. // return $this->hasOne(Lots::className(), );
  62. // }
  63. public function getBid() {
  64. return $this->hasOne(Bidding::className(), ['id' => 'bid_id']);
  65. }
  66. public function getAuction() {
  67. return $this->hasOne(Auctions::className(), ['id' => 'auction_id'])->via('bid');
  68. }
  69. public function getUser() {
  70. return $this->hasOne(User::className(), ['id' =>'user_id']);
  71. }
  72. public function getProfile() {
  73. return $this->hasOne(Profile::className(), ['user_id' => 'user_id']);
  74. }
  75. public function getRequisite() {
  76. return $this->hasOne(Requisites::className(), ['user_id' => 'user_id']);
  77. }
  78. public function attributeLabels() {
  79. return [
  80. 'id' => Yii::t('app', 'ID'),
  81. 'user_id' => Yii::t('app', 'User ID'),
  82. 'type' => Yii::t('app', 'Bill type'),
  83. 'bid_id' => Yii::t('app', 'Ставка №'),
  84. 'payed' => Yii::t('app', 'Payed'),
  85. 'auction_id' => Yii::t('app', 'ID Аукціонa'),
  86. 'user_at_org' => Yii::t('app', 'Company full name'),
  87. ];
  88. }
  89. }