AddonsBossCommissionItemSetting.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\BossWeight\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_boss_weight_commission_item_setting}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property int $is_enable 是否启用股东分红:0:否;1是
  11. * @property int $is_alone 是否独立设置:0:否;1是
  12. * @property int $is_extra 是否开启额外分红:0:否;1是
  13. * @property int $item_id 项目id
  14. * @property string $item_type 项目类型:商品goods
  15. * @property string $commission_type 分佣类型:佣金:commission
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int $created_at
  18. * @property int $updated_at
  19. */
  20. class AddonsBossCommissionItemSetting extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_boss_weight_commission_item_setting}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id'], 'required'],
  36. [['mall_id', 'is_enable', 'is_alone', 'is_extra', 'item_id', 'status', 'created_at', 'updated_at'], 'integer'],
  37. [['item_type', 'commission_type'], 'string', 'max' => 255],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => '商城ID',
  48. 'is_enable' => '是否启用股东分红:0:否;1是',
  49. 'is_alone' => '是否独立设置:0:否;1是',
  50. 'is_extra' => '是否开启额外分红:0:否;1是',
  51. 'item_id' => '项目id',
  52. 'item_type' => '项目类型:商品goods',
  53. 'commission_type' => '分佣类型:佣金:commission',
  54. 'status' => '状态[-1:删除;0:禁用;1启用]',
  55. 'created_at' => 'Created At',
  56. 'updated_at' => 'Updated At',
  57. ];
  58. }
  59. public function getDetail()
  60. {
  61. return $this->hasMany(AddonsBossCommissionItemSettingDetail::class, ['boss_commission_item_setting_id' => 'id'])->indexBy('level');
  62. }
  63. /**
  64. * 保存数据
  65. * @Author: lun
  66. * @DateTime: 2021/11/2 0002 11:45
  67. * @Copyright: copyright (c) 2021 广东七件事集团
  68. * @param $params
  69. * @param $data
  70. * @return bool
  71. */
  72. public static function setData($params, $data)
  73. {
  74. try{
  75. foreach ($data as $item) {
  76. $model = self::findOne([
  77. 'mall_id' => $params['mall_id'],
  78. 'item_type' => $item['item_type'],
  79. 'commission_type' => $item['commission_type'],
  80. 'item_id' => $params['item_id'],
  81. 'status' => [StatusEnum::ENABLED]
  82. ]);
  83. if (empty($model)) {
  84. $model = new self();
  85. $model->mall_id = $params['mall_id'];
  86. $model->item_id = $params['item_id'];
  87. $model->loadDefaultValues();
  88. }
  89. if(!$model->load($item,'') || !$model->save()){
  90. throw new \Exception($model->getErrorMessage());
  91. }
  92. // 插入配置详情
  93. $detail = ['mall_id' => $params['mall_id'], 'boss_commission_item_setting_id' => $model->id];
  94. $res = AddonsBossCommissionItemSettingDetail::setData($detail, $item['detail']);
  95. if ($res == false) throw new \Exception(AddonsBossCommissionItemSettingDetail::getStaticError());
  96. }
  97. return true;
  98. }catch(\Exception $e){
  99. self::$static_error = $e->getMessage();
  100. return false;
  101. }
  102. }
  103. }