| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_goods_model".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id
- * @property int $goods_id 商品id
- * @property string|null $content 内容
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreGoodsModel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_goods_model}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id','goods_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['content'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => 'Store ID',
- 'goods_id' => '商品id',
- 'content' => '内容',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['mall_id'])&&!empty($params['store_id'])&&!empty($params['goods_id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'goods_id' => $params['goods_id'], 'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
- return false;
- }
- }
- //获取门店商品独立设置模式
- public static function getGoodsModel(int $goods_id, string $addons_name, string $type){
- if($goods_id && $type){
- $goods_model = self::find()->where(['goods_id' => $goods_id])->select('content')->one();
- $setting = [];
- if (!empty($goods_model['content'])) {
- $content = json_decode($goods_model['content'], true);
- foreach ($content as $key => $item) {
- $setting[$key] = json_decode($item, true);
- }
- }
- return $setting[$addons_name][$type];
- }
- }
- }
|