ScoreExpansionGoodsSetting.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace addons\ScoreExpansion\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. use yii\grid\Column;
  7. /**
  8. * This is the model class for table "{{%addons_score_expansion_goods_setting}}".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $goods_id 商品id
  13. * @property int|null $integral_wallet_type 红包类型[frozen_integral:冻结红包,integral:激活红包]
  14. * @property int $is_enable 是否开启:0:否,1是
  15. * @property int $is_percent 是否百分比:0:否(固定金额),1是
  16. * @property float $give 赠送红包金额
  17. * @property int $deduct_type 商品抵扣类型[1:单件抵扣,2:多件抵扣]
  18. * @property float $deduct_money 商品抵扣金额
  19. * @property float $is_deduct_percent 抵扣是否百分比[0=否,1=是]
  20. * @property int $status 状态[-1:删除;0:禁用;1启用]
  21. * @property int $parent 上级赠送
  22. * @property int $created_at
  23. * @property int $updated_at
  24. */
  25. class ScoreExpansionGoodsSetting extends \common\models\base\BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_score_expansion_goods_setting}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['mall_id'], 'required'],
  41. [['mall_id', 'goods_id', 'is_enable', 'is_percent', 'deduct_type', 'is_deduct_percent', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['give', 'deduct_money','parent'], 'number'],
  43. [['integral_wallet_type'], 'string', 'max' => 20],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => 'ID',
  53. 'mall_id' => '商城ID',
  54. 'goods_id' => '商品id',
  55. 'integral_wallet_type' => '红包类型[frozen_integral:冻结红包,integral:激活红包]',
  56. 'is_enable' => '是否开启:0:否,1是',
  57. 'is_percent' => '是否百分比:0:否(固定金额),1是',
  58. 'give' => '赠送红包金额',
  59. 'deduct_type' => '商品抵扣类型[1:单件抵扣,2:多件抵扣]',
  60. 'deduct_money' => '商品抵扣金额',
  61. 'is_deduct_percent' => '抵扣是否百分比[0=否,1=是]',
  62. 'status' => '状态[-1:删除;0:禁用;1启用]',
  63. 'created_at' => 'Created At',
  64. 'updated_at' => 'Updated At',
  65. ];
  66. }
  67. /**
  68. * 保存设置
  69. * @Author: lun
  70. * @DateTime: 2022/3/23 0023 14:26
  71. * @Copyright: copyright (c) 2021 广东七件事集团
  72. * @param $mall_id
  73. * @param $goods_id
  74. * @param $list
  75. * @return bool
  76. */
  77. public static function setGoodsSetting($mall_id, $goods_id, $list)
  78. {
  79. try {
  80. $marketing_model = $list['marketing_model'];
  81. unset($list['marketing_model']);
  82. foreach ($list as $item) {
  83. $model = self::findOne(['mall_id' => $mall_id, 'goods_id' => $goods_id, 'integral_wallet_type' => $item['integral_wallet_type'], 'status' => StatusEnum::ENABLED,'parent'=>$item['parent']]);
  84. if(empty($model)){
  85. $model = new self();
  86. $model->mall_id = $mall_id;
  87. $model->goods_id = $goods_id;
  88. }
  89. $item['is_enable'] = (int) $marketing_model;
  90. empty($item['give']) && $item['give'] = 0;
  91. $model->loadDefaultValues();
  92. if (!$model->load($item, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  93. }
  94. return true;
  95. } catch (\Exception $e) {
  96. self::setStaticError('商品红包设置失败:' . $e->getMessage());
  97. return false;
  98. }
  99. }
  100. }