| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\CloudStock\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_upgrade_bag".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property string $name 升级礼包名称
- * @property int $level 升级等级权重
- * @property int $goods_id 升级商品id
- * @property string $give_goods_num 赠送商品数量
- * @property string $give_goods_id 赠送商品id
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property string $level_reward
- * @property int $is_percent
- */
- class CloudStockUpgradeBag extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_upgrade_bag}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name', 'level', 'goods_id'], 'required'],
- [['mall_id', 'level', 'status', 'created_at', 'updated_at','is_percent'], 'integer'],
- [['name'], 'string', 'max' => 255],
- [['level_reward'], 'string'],
- [['goods_id', 'give_goods_id','give_goods_num'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'name' => '升级礼包名称',
- 'level' => '升级等级权重',
- 'goods_id' => '升级商品id',
- 'is_percent' => 'is_percent',
- 'give_goods_num' => '赠送商品数量',
- 'give_goods_id' => '赠送商品id',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'level_reward' => '直推、间推奖励',
- ];
- }
- public static function setData(array $params)
- {
- try {
- $query = self::find()->where(['mall_id'=>$params['mall_id'],'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if(!empty($params['id'])){
- $query->andWhere(['<>','id',$params['id']]);
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- // $res = self::findOne(['mall_id'=>$params['mall_id'],'level'=>$params['level'],'status'=>StatusEnum::ENABLED]);
- // if($res) throw new \Exception('该等级已经存在有升级礼包');
- $model = new self();
- $model->loadDefaultValues();
- }
- // $res = $query->one();
- // if ($res) throw new \Exception('该商品已经被添加过');
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function getGoodsIds($mall_id)
- {
- $goods_ids = CloudStockUpgradeBag::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'is_enable' => StatusEnum::ENABLED])->select('goods_id')->column();
- $goods_id_arr = [];
- foreach ($goods_ids as $item) {
- $temp_goods_id_arr = json_decode($item, true);
- if (!empty($temp_goods_id_arr)) {
- $goods_id_arr = array_merge($goods_id_arr, $temp_goods_id_arr);
- } else {
- $goods_id_arr[] = $item;
- }
- }
- return $goods_id_arr;
- }
- }
|