255], [['give_goods_num', 'give_goods_id'], 'string', 'max' => 1000], [['give_goods_info'],'string'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'name' => '升级礼包名称', 'level' => '升级等级权重', 'goods_id' => '升级商品id', 'give_goods_num' => '赠送商品数量', 'give_goods_id' => '赠送商品id', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'give_goods_info' => 'Give Goods Info' ]; } public static function setData(array $params) { try { $query = self::find()->where(['mall_id'=>$params['mall_id'],'goods_id'=>$params['goods_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; } } }