| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- /**
- * This is the model class for table "bills".
- *
- * @property int $id
- * @property int $user_id
- * @property string $type
- * @property int $lot_id
- * @property User $user
- */
- class Bills extends \yii\db\ActiveRecord {
- /**
- * {@inheritdoc}
- */
- public static function tableName() {
- return 'bills';
- }
- /*
- * without migrations
- * */
- public static function create(Bidding $bid) {
- $data = [
- 'user_id' => Yii::$app->user->id,
- 'type' => 'guarantee',
- 'bid_id' => $bid->id,
- 'payed' => 0,
- 'auction_id' => $bid->auction_id,
- ];
- (new Bills($data))->save(false);
- $data['type'] = 'registration';
- (new Bills($data))->save(false);
- return true;
- }
- public static function types() {
- return
- [
- 'guarantee' => Yii::t('app', 'Guaranteed payment'),
- 'registration' => Yii::t('app', 'Registration fee'),
- ];
- }
- public static function payStatuses() {
- return
- [
- '0' => Yii::t('app','Нові'),
- '1' => Yii::t('app','Сплачено'),
- '2' => Yii::t('app','Не сплачено'),
- ];
- }
- public function rules() {
- return [
- [['user_id', 'type', 'bid_id'], 'required'],
- [['user_id','auction_id' ,'bid_id'], 'integer'],
- [['type'], 'in', 'range' => array_keys(static::types())],
- [['payed'], 'in', 'range' => array_keys(static::payStatuses())],
- ];
- }
- // public function getLotName() {
- // return $this->hasOne(Lots::className(), );
- // }
- public function getBid() {
- return $this->hasOne(Bidding::className(), ['id' => 'bid_id']);
- }
- public function getAuction() {
- return $this->hasOne(Auctions::className(), ['id' => 'auction_id'])->via('bid');
- }
- public function getUser() {
- return $this->hasOne(User::className(), ['id' =>'user_id']);
- }
- public function getProfile() {
- return $this->hasOne(Profile::className(), ['user_id' => 'user_id']);
- }
- public function getRequisite() {
- return $this->hasOne(Requisites::className(), ['user_id' => 'user_id']);
- }
- public function attributeLabels() {
- return [
- 'id' => Yii::t('app', 'ID'),
- 'user_id' => Yii::t('app', 'User ID'),
- 'type' => Yii::t('app', 'Bill type'),
- 'bid_id' => Yii::t('app', 'Ставка №'),
- 'payed' => Yii::t('app', 'Payed'),
- 'auction_id' => Yii::t('app', 'ID Аукціонa'),
- 'user_at_org' => Yii::t('app', 'Company full name'),
- ];
- }
- }
|