DistributionCommissionLevelSetting.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace addons\Distribution\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_distribution_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 佣金类型 0百分比 1 固定金额
  15. * @property float $first_prize 一级
  16. * @property float $second_prize 二级
  17. * @property float $third_prize 三级
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at
  20. * @property int $updated_at
  21. */
  22. class DistributionCommissionLevelSetting extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_distribution_commission_level_setting}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id'], 'required'],
  38. [['mall_id', 'level', 'is_percent', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['first_prize', 'second_prize', 'third_prize'], 'number'],
  40. [['commission_type', 'from_type'], 'string', 'max' => 255],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => '商城ID',
  51. 'level' => 'Level',
  52. 'commission_type' => '分佣类型:积分score;佣金:commission',
  53. 'from_type' => '分佣类型:经销Agent;幸运平团:Lucky_group',
  54. 'is_percent' => '佣金类型 0百分比 1 固定金额',
  55. 'first_prize' => '一级',
  56. 'second_prize' => '二级',
  57. 'third_prize' => '三级',
  58. 'status' => '状态[-1:删除;0:禁用;1启用]',
  59. 'created_at' => 'Created At',
  60. 'updated_at' => 'Updated At',
  61. ];
  62. }
  63. public static function setData($params)
  64. {
  65. try{
  66. if (!empty($params['level'])&&!empty($params['from_type'])&&!empty($params['commission_type'])) {
  67. $where = [
  68. 'level' => $params['level'],
  69. 'mall_id' => $params['mall_id'],
  70. 'from_type'=>$params['from_type'],
  71. 'commission_type'=>$params['commission_type'],
  72. 'status' => [StatusEnum::ENABLED]];
  73. $model = self::findOne($where);
  74. if (empty($model)) {
  75. $model = new self();
  76. $model->loadDefaultValues();
  77. }
  78. } else {
  79. $model = new self();
  80. $model->loadDefaultValues();
  81. }
  82. if(!$model->load($params,'') || !$model->save()){
  83. throw new \Exception($model->getErrorMessage());
  84. }
  85. return true;
  86. }catch(\Exception $e){
  87. self::$static_error = $e->getMessage();
  88. return false;
  89. }
  90. }
  91. public static function del($params){
  92. try{
  93. $model = self::updateAll(['status'=>StatusEnum::DELETE],['level'=>$params['level'],'mall_id'=>$params['mall_id']]);
  94. if(empty($model)) throw new \Exception("删除失败");
  95. return true;
  96. }catch (\Exception $e){
  97. self::$static_error = $e->getMessage();
  98. return false;
  99. }
  100. }
  101. }