ServeBonusLevelSetting.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace addons\ServeBonus\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_addons_servebonus_level_setting".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property int $level
  11. * @property string $commission_type 分佣类型:积分score;佣金:commission
  12. * @property string $from_type 分佣类型:服务商;
  13. * @property float $prize 永久分红,单位:百分比
  14. * @property float $extra_prize 额外分红,单位:百分比
  15. * @property int $is_extra 是否开启额外分红【0否,1是】
  16. * @property int $extra_type 获取额外分红的类型:1购物,2条件,3任意
  17. * @property int $extra_is_limit 额外分红是否存在上限【0否,1是】
  18. * @property float $extra_limit_price 额外分红上限金额,单位:元
  19. * @property int $is_accumulation 是否开启叠加加权平分:0否,1是
  20. * @property int $status 状态[-1:删除;0:禁用;1启用]
  21. * @property int $created_at
  22. * @property int $updated_at
  23. * @property int $accumulation_condition 加权平均分限制条件,1开启,0关闭
  24. * @property float $accumulation_condition_money 上月团队总业绩需达n元
  25. */
  26. class ServeBonusLevelSetting extends \common\models\base\BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_servebonus_level_setting}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id'], 'required'],
  42. [['mall_id', 'level', 'is_percent_prize', 'is_percent_extra', 'is_extra', 'extra_type', 'extra_is_limit', 'is_accumulation', 'status', 'created_at', 'updated_at','is_cloud_stock_open','cloud_stock_achievement_percent', 'accumulation_condition'], 'integer'],
  43. [['prize', 'extra_prize', 'extra_limit_price','cloud_stock_achievement_prize', 'accumulation_condition_money'], 'number'],
  44. [['commission_type', 'from_type'], 'string', 'max' => 255],
  45. ];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => 'ID',
  54. 'mall_id' => '商城ID',
  55. 'level' => 'Level',
  56. 'commission_type' => '分佣类型:积分score;佣金:commission',
  57. 'from_type' => '分佣类型:股东;',
  58. 'is_percent_prize' => '出单奖励类型 0百分比 1 固定金额',
  59. 'prize' => '出单奖励',
  60. 'is_percent_extra' => '加权平分类型 0百分比 1 固定金额',
  61. 'extra_prize' => '加权平分',
  62. 'is_extra' => '是否开启额外分红【0否,1是】',
  63. 'extra_type' => '获取额外分红的类型:1购物,2条件,3任意',
  64. 'extra_is_limit' => '额外分红是否存在上限【0否,1是】',
  65. 'extra_limit_price' => '额外分红上限金额,单位:元',
  66. 'is_accumulation' => '是否开启叠加加权平分:0否,1是',
  67. 'status' => '状态[-1:删除;0:禁用;1启用]',
  68. 'created_at' => 'Created At',
  69. 'updated_at' => 'Updated At',
  70. 'accumulation_condition' => '加权平均分限制条件,1开启,0关闭',
  71. 'accumulation_condition_money' => '上月团队总业绩需达n元',
  72. ];
  73. }
  74. /**
  75. * 保存数据
  76. * @Author: ltm
  77. * @DateTime: 2021/11/4 0004 14:23
  78. * @Copyright: copyright (c) 2021 广东七件事集团
  79. * @param $params
  80. * @return bool
  81. */
  82. public static function setData($params)
  83. {
  84. try{
  85. // 删除数据特殊处理
  86. if ($params['status'] == StatusEnum::DELETE) {
  87. self::updateAll(['status'=>StatusEnum::DELETE],['level'=>$params['level'],'mall_id'=>$params['mall_id']]);
  88. return true;
  89. }
  90. $model = self::find()->where(['mall_id' => $params['mall_id'],'level' => $params['level']])->andWhere(['<>', 'status', StatusEnum::DELETE])->one();
  91. if (empty($model)) {
  92. $model = new self();
  93. $model->mall_id = $params['mall_id'];
  94. $model->level = $params['level'];
  95. $model->loadDefaultValues();
  96. }
  97. if(!$model->load($params,'') || !$model->save()){
  98. throw new \Exception($model->getErrorMessage());
  99. }
  100. return true;
  101. }catch(\Exception $e){
  102. self::$static_error = $e->getMessage();
  103. return false;
  104. }
  105. }
  106. /**
  107. * 获取等级分佣配置
  108. * @Author: ltm
  109. * @DateTime: 2021/11/4 0004 14:23
  110. * @Copyright: copyright (c) 2021 广东七件事集团
  111. * @param array $cond
  112. * @param array $with
  113. * @param bool $is_array
  114. * @param string $select
  115. * @return array|\yii\db\ActiveRecord[]
  116. */
  117. public static function getServeBonusLevelSetting(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
  118. $default_cond = [['<>','status',StatusEnum::DELETE]];
  119. $cond = array_merge($default_cond,$cond);
  120. $query = self::find()->select($select);
  121. self::paramPack(['where'=>$cond, 'with'=>$with],$query);
  122. $data = $query->asArray($is_array)->all();
  123. return $data;
  124. }
  125. }