StoreDividendsUser.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;/**
  4. * This is the model class for table "{{%store_dividends}}".
  5. *
  6. * @property integer $id
  7. * @property integer $role
  8. * @property integer $role_id
  9. * @property integer $join_cycle_key
  10. * @property float $dividends_integral
  11. * @property float $league_price
  12. * @property string $created_at
  13. * @property string $updated_at
  14. */
  15. class StoreDividendsUser extends \yii\db\ActiveRecord
  16. {
  17. /**
  18. * 身份类型:用户;
  19. */
  20. const ROLE_USER = 0;
  21. /**
  22. * 身份类型:商城;
  23. */
  24. const ROLE_STORE = 1;
  25. /**
  26. * @inheritdoc
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%store_dividends_user}}';
  31. }
  32. public function behaviors()
  33. {
  34. return [
  35. [
  36. 'class' => TimestampBehavior::class
  37. ]
  38. ];
  39. }
  40. public function rules()
  41. {
  42. return [
  43. [['id', 'role', 'role_id', 'join_cycle_key'], 'integer'],
  44. [['dividends_integral', 'league_price', 'created_at', 'updated_at'], 'number']
  45. ];
  46. }
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'role' => '身份类型(0=用户;1=商城;)',
  52. 'role_id' => '身份ID',
  53. 'join_cycle_key' => '加入时候的周期数',
  54. 'dividends_integral' => '积分数量',
  55. 'league_price' => '已分红数量(联盟券数量)',
  56. 'created_at' => '创建时间',
  57. 'updated_at' => '修改时间'
  58. ];
  59. }
  60. public static function addUser($role = self::ROLE_USER, $role_id = 0, $cycle_sort_key = 1) {
  61. $storeDividendsUser = self::findOne(['role' => $role, 'role_id' => $role_id]);
  62. if (!$storeDividendsUser) {
  63. $storeDividendsUser = new self();
  64. $storeDividendsUser->role = $role;
  65. $storeDividendsUser->role_id = $role_id;
  66. $storeDividendsUser->dividends_integral = 0;
  67. $storeDividendsUser->league_price = 0;
  68. $storeDividendsUser->join_cycle_key = $cycle_sort_key;
  69. if (!$storeDividendsUser->save()) {
  70. return null;
  71. }
  72. }
  73. return $storeDividendsUser;
  74. }
  75. }