BusinessBonusLevelInfo.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_info}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property string|null $upgrade_bgi 升级申请背景图
  11. * @property string|null $level_desc 等级说明
  12. * @property string|null $benefit_intro 福利介绍
  13. * @property int|null $status 状态:-1删除,0禁用,1启用
  14. * @property int|null $created_at 创建时间
  15. * @property int|null $updated_at 更新时间
  16. */
  17. class BusinessBonusLevelInfo extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_business_bonus_level_info}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'business_bonus_level', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['benefit_intro'], 'string'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城ID',
  44. 'business_bonus_level' => '招商员等级',
  45. 'benefit_intro' => '福利介绍',
  46. 'status' => '状态:-1删除,0禁用,1启用',
  47. 'created_at' => '创建时间',
  48. 'updated_at' => '更新时间',
  49. ];
  50. }
  51. /**
  52. * 数据设置
  53. */
  54. public static function setData(array $params)
  55. {
  56. try{
  57. if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
  58. if (isset($params['business_bonus_level']) && !empty($params['business_bonus_level'])) {
  59. $model = self::findOne(['mall_id' => $params['mall_id'], 'business_bonus_level' => $params['business_bonus_level'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
  60. }
  61. if (!isset($model) || empty($model)) {
  62. $model = new self();
  63. $model->loadDefaultValues();
  64. $model->mall_id = $params['mall_id'];
  65. }
  66. if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  67. return $model;
  68. }catch(Exception $e){
  69. self::setStaticError($e->getMessage());
  70. return false;
  71. }
  72. }
  73. /**
  74. * 获取福利介绍
  75. */
  76. public static function getBenefitIntro($mall_id, $business_bonus_level)
  77. {
  78. $info = self::getOne([
  79. ['=', 'mall_id', $mall_id],
  80. ['=', 'business_bonus_level', $business_bonus_level],
  81. ['=', 'status', StatusEnum::ENABLED],
  82. ], true);
  83. return $info['benefit_intro'] ?? '';
  84. }
  85. }