| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\models;
- use yii\behaviors\TimestampBehavior;/**
- * This is the model class for table "{{%store_dividends}}".
- *
- * @property integer $id
- * @property integer $role
- * @property integer $role_id
- * @property integer $join_cycle_key
- * @property float $dividends_integral
- * @property float $league_price
- * @property string $created_at
- * @property string $updated_at
- */
- class StoreDividendsUser extends \yii\db\ActiveRecord
- {
- /**
- * 身份类型:用户;
- */
- const ROLE_USER = 0;
- /**
- * 身份类型:商城;
- */
- const ROLE_STORE = 1;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%store_dividends_user}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class
- ]
- ];
- }
- public function rules()
- {
- return [
- [['id', 'role', 'role_id', 'join_cycle_key'], 'integer'],
- [['dividends_integral', 'league_price', 'created_at', 'updated_at'], 'number']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'role' => '身份类型(0=用户;1=商城;)',
- 'role_id' => '身份ID',
- 'join_cycle_key' => '加入时候的周期数',
- 'dividends_integral' => '积分数量',
- 'league_price' => '已分红数量(联盟券数量)',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间'
- ];
- }
- public static function addUser($role = self::ROLE_USER, $role_id = 0, $cycle_sort_key = 1) {
- $storeDividendsUser = self::findOne(['role' => $role, 'role_id' => $role_id]);
- if (!$storeDividendsUser) {
- $storeDividendsUser = new self();
- $storeDividendsUser->role = $role;
- $storeDividendsUser->role_id = $role_id;
- $storeDividendsUser->dividends_integral = 0;
- $storeDividendsUser->league_price = 0;
- $storeDividendsUser->join_cycle_key = $cycle_sort_key;
- if (!$storeDividendsUser->save()) {
- return null;
- }
- }
- return $storeDividendsUser;
- }
- }
|