BusinessBonusLevel.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\BusinessBonus\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_business_bonus_level}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property string|null $level_name 等级名称
  11. * @property int|null $level_weight 等级权重,数字越大,等级越高
  12. * @property float|null $bonus_rate 分红比例,5%,填5
  13. * @property int|null $status 状态:-1删除,0禁用,1启用
  14. * @property int|null $created_at 创建时间
  15. * @property int|null $updated_at 更新时间
  16. */
  17. class BusinessBonusLevel extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_business_bonus_level}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['bonus_rate'], 'number'],
  34. [['level_name'], 'string', 'max' => 128],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => '商城ID',
  45. 'level_name' => '等级名称',
  46. 'level' => '等级(权重),数字越大,等级越高',
  47. 'bonus_rate' => '分红比例,5%,填5',
  48. 'status' => '状态:-1删除,0禁用,1启用',
  49. 'created_at' => '创建时间',
  50. 'updated_at' => '更新时间',
  51. ];
  52. }
  53. /**
  54. * 数据设置
  55. */
  56. public static function setData(array $params)
  57. {
  58. try{
  59. if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
  60. if (isset($params['id']) && !empty($params['id'])) {
  61. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
  62. if(empty($model)) throw new Exception('招商员等级不存在或已删除');
  63. } else {
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. $model->mall_id = $params['mall_id'];
  67. }
  68. if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  69. return $model;
  70. }catch(Exception $e){
  71. self::setStaticError($e->getMessage());
  72. return false;
  73. }
  74. }
  75. }