| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "{{%goods_full_minus}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $goods_id
- * @property string $colonel
- * @property string $group_num
- * @property integer $group_time
- * @property string $attr
- * @property string $is_delete
- * @property int $is_level
- */
- class GoodsFullMinus extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%goods_full_minus}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['store_id'], 'required'],
- [['store_id', 'goods_id', 'full_minus_num', 'is_delete'], 'integer'],
- [['attr'], 'string'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'goods_id' => 'Goods ID',
- 'full_minus_num' => '商品满减数',
- 'attr' => '规格的库存及价格',
- ];
- }
- public function getCheckedAttrData()
- {
- if ($this->isNewRecord) {
- return [];
- }
- if (!$this->use_attr) {
- return [];
- }
- if (!$this->attr) {
- return [];
- }
- $attr_data = json_decode($this->attr, true);
- foreach ($attr_data as $i => $attr_data_item) {
- if (!isset($attr_data[$i]['no'])) {
- $attr_data[$i]['no'] = '';
- }
- if (!isset($attr_data[$i]['pic'])) {
- $attr_data[$i]['pic'] = '';
- }
- foreach ($attr_data[$i]['attr_list'] as $j => $attr_list) {
- $attr_group = $this->getAttrGroupByAttId($attr_data[$i]['attr_list'][$j]['attr_id']);
- $attr_data[$i]['attr_list'][$j]['attr_group_name'] = $attr_group ? $attr_group->attr_group_name : null;
- }
- }
- return $attr_data;
- }
- private function getAttrGroupByAttId($att_id)
- {
- $cache_key = 'get_attr_group_by_attr_id_' . $att_id;
- $attr_group = Yii::$app->cache->get($cache_key);
- if ($attr_group) {
- return $attr_group;
- }
- $attr_group = AttrGroup::find()->alias('ag')
- ->where(['ag.id' => Attr::find()->select('attr_group_id')->distinct()->where(['id' => $att_id])])
- ->limit(1)->one();
- if (!$attr_group) {
- return $attr_group;
- }
- Yii::$app->cache->set($cache_key, $attr_group, 10);
- return $attr_group;
- }
- }
|