| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace addons\HiGo\common\models;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use Yii;
- use Exception;
- /**
- * This is the model class for table "{{%addons_higo_store_goods_mode}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $source_id 来源id
- * @property string $source 来源,插件名称
- * @property int $goods_id 商品id
- * @property int $is_enable 是否开启嗨购模式:0:否,1是
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class HigoStoreGoodsMode extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_higo_store_goods_mode}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'source_id', 'goods_id', 'is_enable', 'status', 'created_at', 'updated_at'], 'integer'],
- [['source'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'source' => 'Source',
- 'source_id' => 'Source Id',
- 'goods_id' => 'Goods ID',
- 'is_enable' => 'Is Enable',
- 'status' => 'Status',
- '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 $item
- * @return bool
- */
- public static function setGoodsSetting($mall_id, $goods_id, $item)
- {
- try {
- $model = self::findOne(['mall_id' => $mall_id, 'goods_id' => $goods_id, 'source' => $item['source'], 'source_id' => $item['source_id'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $mall_id;
- $model->goods_id = $goods_id;
- $model->loadDefaultValues();
- }
- if (!$model->load($item, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::setStaticError('商品嗨购设置失败:' . $e->getMessage());
- return false;
- }
- }
- }
|