AgentCommissionLevelSetting.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace addons\Agent\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_agent_commission_level_setting".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $level
  12. * @property string $commission_type 分佣类型:积分score;佣金:commission
  13. * @property string $from_type 分佣类型:经销Agent;幸运平团:Lucky_group
  14. * @property int $is_percent_team 渠道奖类型 0百分比 1 固定金额
  15. * @property int $is_percent_equal 平级奖类型 0百分比 1 固定金额
  16. * @property int $is_percent_over 越级奖类型 0百分比 1 固定金额
  17. * @property int $is_percent_extra 额外奖类型 0百分比 1 固定金额
  18. * @property float $agent_team_prize 渠道奖
  19. * @property float $agent_equal_prize 平级奖
  20. * @property float $agent_over_prize 越级奖
  21. * @property float $agent_extra_prize 额外奖
  22. * @property int $status 状态[-1:删除;0:禁用;1启用]
  23. * @property int $created_at
  24. * @property int $updated_at
  25. * @property int $is_repurchase_subsidy 是否开启每月复购补贴奖[0否 1是]
  26. * @property string|null $repurchase_subsidy_condition 每月复购补贴奖奖励条件
  27. */
  28. class AgentCommissionLevelSetting extends BaseActiveRecord
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%addons_agent_commission_level_setting}}';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['mall_id'], 'required'],
  44. [['mall_id', 'level', 'is_percent_team', 'is_percent_equal', 'is_percent_over', 'is_percent_extra', 'status', 'created_at', 'updated_at','is_alone_agent_equal_prize', 'is_repurchase_subsidy'], 'integer'],
  45. [['agent_team_prize', 'agent_equal_prize', 'agent_over_prize', 'agent_extra_prize','team_achievement'], 'number'],
  46. [['commission_type', 'from_type'], 'string', 'max' => 255],
  47. [['alone_agent_equal_prize_info'], 'string', 'max' => 1000],
  48. [['repurchase_subsidy_condition'], 'string']
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => 'ID',
  58. 'mall_id' => '商城ID',
  59. 'level' => 'Level',
  60. 'commission_type' => '分佣类型:积分score;佣金:commission',
  61. 'from_type' => '分佣类型:经销Agent;幸运平团:Lucky_group',
  62. 'is_percent_team' => '渠道奖类型 0百分比 1 固定金额',
  63. 'is_percent_equal' => '平级奖类型 0百分比 1 固定金额',
  64. 'is_percent_over' => '越级奖类型 0百分比 1 固定金额',
  65. 'is_percent_extra' => '额外奖类型 0百分比 1 固定金额',
  66. 'agent_team_prize' => '渠道奖',
  67. 'agent_equal_prize' => '平级奖',
  68. 'agent_over_prize' => '越级奖',
  69. 'agent_extra_prize' => '额外奖',
  70. 'status' => '状态[-1:删除;0:禁用;1启用]',
  71. 'created_at' => 'Created At',
  72. 'updated_at' => 'Updated At',
  73. 'is_repurchase_subsidy' => '是否开启每月复购补贴奖[0否 1是]',
  74. 'repurchase_subsidy_condition' => '每月复购补贴奖奖励条件',
  75. ];
  76. }
  77. public static function setData($params)
  78. {
  79. try{
  80. if (!empty($params['level'])&&!empty($params['from_type'])&&!empty($params['commission_type'])) {
  81. $where = [
  82. 'level' => $params['level'],
  83. 'mall_id' => $params['mall_id'],
  84. 'from_type'=>$params['from_type'],
  85. 'commission_type'=>$params['commission_type'],
  86. 'status' => [StatusEnum::ENABLED]];
  87. $model = self::findOne($where);
  88. if (empty($model)) {
  89. $model = new self();
  90. $model->loadDefaultValues();
  91. }
  92. } else {
  93. $model = new self();
  94. $model->loadDefaultValues();
  95. }
  96. if(!$model->load($params,'') || !$model->save()){
  97. throw new \Exception($model->getErrorMessage());
  98. }
  99. return true;
  100. }catch(\Exception $e){
  101. self::$static_error = $e->getMessage();
  102. return false;
  103. }
  104. }
  105. public static function del($params){
  106. try{
  107. $model = self::updateAll(['status'=>StatusEnum::DELETE],['level'=>$params['level'],'mall_id'=>$params['mall_id']]);
  108. if(empty($model)) throw new \Exception("删除失败");
  109. return true;
  110. }catch (\Exception $e){
  111. self::$static_error = $e->getMessage();
  112. return false;
  113. }
  114. }
  115. }