| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\ScoreExpansion\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- use yii\grid\Column;
- /**
- * This is the model class for table "{{%addons_score_expansion_goods_setting}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $goods_id 商品id
- * @property int|null $integral_wallet_type 红包类型[frozen_integral:冻结红包,integral:激活红包]
- * @property int $is_enable 是否开启:0:否,1是
- * @property int $is_percent 是否百分比:0:否(固定金额),1是
- * @property float $give 赠送红包金额
- * @property int $deduct_type 商品抵扣类型[1:单件抵扣,2:多件抵扣]
- * @property float $deduct_money 商品抵扣金额
- * @property float $is_deduct_percent 抵扣是否百分比[0=否,1=是]
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $parent 上级赠送
- * @property int $created_at
- * @property int $updated_at
- */
- class ScoreExpansionGoodsSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_score_expansion_goods_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'goods_id', 'is_enable', 'is_percent', 'deduct_type', 'is_deduct_percent', 'status', 'created_at', 'updated_at'], 'integer'],
- [['give', 'deduct_money','parent'], 'number'],
- [['integral_wallet_type'], 'string', 'max' => 20],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'goods_id' => '商品id',
- 'integral_wallet_type' => '红包类型[frozen_integral:冻结红包,integral:激活红包]',
- 'is_enable' => '是否开启:0:否,1是',
- 'is_percent' => '是否百分比:0:否(固定金额),1是',
- 'give' => '赠送红包金额',
- 'deduct_type' => '商品抵扣类型[1:单件抵扣,2:多件抵扣]',
- 'deduct_money' => '商品抵扣金额',
- 'is_deduct_percent' => '抵扣是否百分比[0=否,1=是]',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存设置
- * @Author: lun
- * @DateTime: 2022/3/23 0023 14:26
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param $goods_id
- * @param $list
- * @return bool
- */
- public static function setGoodsSetting($mall_id, $goods_id, $list)
- {
- try {
- $marketing_model = $list['marketing_model'];
- unset($list['marketing_model']);
- foreach ($list as $item) {
- $model = self::findOne(['mall_id' => $mall_id, 'goods_id' => $goods_id, 'integral_wallet_type' => $item['integral_wallet_type'], 'status' => StatusEnum::ENABLED,'parent'=>$item['parent']]);
- if(empty($model)){
- $model = new self();
- $model->mall_id = $mall_id;
- $model->goods_id = $goods_id;
- }
- $item['is_enable'] = (int) $marketing_model;
- empty($item['give']) && $item['give'] = 0;
-
- $model->loadDefaultValues();
- if (!$model->load($item, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- }
- return true;
- } catch (\Exception $e) {
- self::setStaticError('商品红包设置失败:' . $e->getMessage());
- return false;
- }
- }
- }
|