ServeBonusCommissionItemSetting.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "{{%addons_servebonus_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 $is_percent_prize 出单奖励类型 0百分比 1 固定金额
  17. * @property int $is_percent_extra 加权平分类型 0百分比 1 固定金额
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at
  20. * @property int $updated_at
  21. */
  22. class ServeBonusCommissionItemSetting extends \common\models\base\BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_servebonus_commission_item_setting}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id'], 'required'],
  38. [['mall_id', 'is_enable', 'is_alone', 'is_extra', 'item_id', 'is_percent_prize', 'is_percent_extra', 'status', 'created_at', 'updated_at','cloud_stock_achievement_percent'], 'integer'],
  39. [['item_type', 'commission_type'], 'string', 'max' => 255],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => '商城ID',
  50. 'is_enable' => '是否启用服务商分红:0:否;1是',
  51. 'is_alone' => '是否独立设置:0:否;1是',
  52. 'is_extra' => '是否开启额外分红:0:否;1是',
  53. 'item_id' => '项目id',
  54. 'item_type' => '项目类型:商品goods',
  55. 'commission_type' => '分佣类型:佣金:commission',
  56. 'is_percent_prize' => '出单奖励类型 0百分比 1 固定金额',
  57. 'is_percent_extra' => '加权平分类型 0百分比 1 固定金额',
  58. 'status' => '状态[-1:删除;0:禁用;1启用]',
  59. 'created_at' => 'Created At',
  60. 'updated_at' => 'Updated At',
  61. ];
  62. }
  63. public function getDetail()
  64. {
  65. return $this->hasMany(ServeBonusCommissionItemSettingDetail::class, ['sid' => 'id'])->orderBy("level asc")->indexBy('level');
  66. }
  67. /**
  68. * 保存数据
  69. * @Author: ltm
  70. * @DateTime: 2021/11/2 0002 11:45
  71. * @Copyright: copyright (c) 2021 广东七件事集团
  72. * @param $params
  73. * @param $data
  74. * @return bool
  75. */
  76. public static function setData($params, $data)
  77. {
  78. try{
  79. foreach ($data as $item) {
  80. $model = self::findOne([
  81. 'mall_id' => $params['mall_id'],
  82. 'item_type' => $item['item_type'],
  83. 'commission_type' => $item['commission_type'],
  84. 'item_id' => $params['item_id'],
  85. 'status' => [StatusEnum::ENABLED]
  86. ]);
  87. if (empty($model)) {
  88. $model = new self();
  89. $model->mall_id = $params['mall_id'];
  90. $model->item_id = $params['item_id'];
  91. $model->loadDefaultValues();
  92. }
  93. if(!$model->load($item,'') || !$model->save()){
  94. throw new \Exception($model->getErrorMessage());
  95. }
  96. // 插入配置详情
  97. $detail = ['mall_id' => $params['mall_id'], 'sid' => $model->id];
  98. $res = ServeBonusCommissionItemSettingDetail::setData($detail, $item['detail']);
  99. if ($res == false) throw new \Exception(ServeBonusCommissionItemSettingDetail::getStaticError());
  100. }
  101. return true;
  102. }catch(\Exception $e){
  103. self::$static_error = $e->getMessage();
  104. return false;
  105. }
  106. }
  107. }