ShareGroupPurchaseUser.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;
  4. /**
  5. * This is the model class for table "{{%share_group_purchase_user}}".
  6. *
  7. * @property integer $id
  8. * @property integer $user_id
  9. * @property integer $parent_user_id
  10. * @property integer $store_id
  11. * @property float $direct_price
  12. * @property float $support_price
  13. * @property float $group_price
  14. * @property float $total_price
  15. * @property float $price
  16. * @property integer $created_at
  17. * @property integer $updated_at
  18. */
  19. class ShareGroupPurchaseUser extends \yii\db\ActiveRecord
  20. {
  21. /**
  22. * @inheritdoc
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%share_group_purchase_user}}';
  27. }
  28. public function behaviors()
  29. {
  30. return [
  31. [
  32. 'class' => TimestampBehavior::class
  33. ]
  34. ];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['id', 'user_id', 'store_id', 'created_at', 'updated_at', 'parent_user_id'], 'integer'],
  43. [['direct_price', 'support_price', 'group_price', 'total_price', 'price'], 'number']
  44. ];
  45. }
  46. /**
  47. * @inheritdoc
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => '',
  53. 'user_id' => '用户ID',
  54. 'parent_user_id' => '上级用户ID',
  55. 'store_id' => 'Store Id',
  56. 'direct_price' => '当前点位直推佣金',
  57. 'support_price' => '当前点位扶持佣金',
  58. 'group_price' => '成团佣金',
  59. 'total_price' => '累计佣金',
  60. 'price' => '可提现佣金',
  61. 'created_at' => '',
  62. 'updated_at' => '',
  63. ];
  64. }
  65. public function beforeSave($insert)
  66. {
  67. if (parent::beforeSave($insert)) {
  68. if ($insert) {
  69. $self = self::findOne(['user_id' => $this->user_id]);
  70. if ($self) {
  71. $this->addError('user', '用户已存在');
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77. return false;
  78. }
  79. }