BossThree.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace addons\BossThree\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Exception;
  6. use Yii;
  7. /**
  8. * This is the model class for table "{{%addons_boss_three}}".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $user_id 用户ID
  13. * @property int $level 股东等级
  14. * @property float $commission 累计永久佣金,单位:元
  15. * @property float $extra_commission 累计额外佣金,单位:元
  16. * @property float $temp_extra_commission 额外分红金额,主要用于判断是否会导致超额
  17. * @property float $total_commission 累计总佣金,单位:元
  18. * @property int $upgrade_status 1条件升级,2购买指定商品升级,3手动升级
  19. * @property int $upgrade_level_at 股东等级升级时间
  20. * @property string|null $remark
  21. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int $created_at 创建时间
  23. * @property int $updated_at 修改时间
  24. * @property string $goods_ids 商品ID
  25. * @property int $is_percent 类型 0百分比 1 固定金额
  26. * @property float $price 分佣比例配置
  27. */
  28. class BossThree extends \common\models\base\BaseActiveRecord
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%addons_boss_three}}';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['mall_id', 'user_id', 'level', 'upgrade_status', 'upgrade_level_at', 'status', 'created_at', 'updated_at','is_percent'], 'integer'],
  44. [['commission', 'extra_commission', 'temp_extra_commission', 'total_commission','price'], 'number'],
  45. [['remark'], 'string', 'max' => 255],
  46. [['goods_ids'], 'string'],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'mall_id' => 'Mall ID',
  57. 'user_id' => 'User ID',
  58. 'level' => 'Level',
  59. 'commission' => 'Commission',
  60. 'extra_commission' => 'Extra Commission',
  61. 'temp_extra_commission' => 'Temp Extra Commission',
  62. 'total_commission' => 'Total Commission',
  63. 'upgrade_status' => 'Upgrade Status',
  64. 'upgrade_level_at' => 'Upgrade Level At',
  65. 'remark' => 'Remark',
  66. 'status' => 'Status',
  67. 'created_at' => 'Created At',
  68. 'updated_at' => 'Updated At',
  69. ];
  70. }
  71. public function getUser()
  72. {
  73. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
  74. }
  75. /**
  76. * 保存数据
  77. * @Author: lun
  78. * @DateTime: 2021/10/22 0022 17:13
  79. * @Copyright: copyright (c) 2021 广东七件事集团
  80. * @param array $params
  81. * @return AddonsBoss|bool
  82. */
  83. public static function setData(array $params){
  84. try{
  85. if(!empty($params['user_id'])){
  86. $model = self::findOne(['user_id' => $params['user_id'],'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
  87. if(empty($model)) {
  88. $model = new self();
  89. $model->loadDefaultValues();
  90. $model->mall_id = $params['mall_id'];
  91. //$model->upgrade_status = LevelEnum::UPGRADE_MANUAL;
  92. //$model->upgrade_level_at = time();
  93. }
  94. } else {
  95. throw new \Exception('股东数据不存在或已删除');
  96. }
  97. if(!$model->load($params,'') || !$model->save()){
  98. throw new Exception($model->getErrorMessage());
  99. }
  100. return $model;
  101. }catch(\Exception $e){
  102. self::setStaticError($e->getMessage());
  103. return false;
  104. }
  105. }
  106. }