diff --git a/constants/field_status.go b/constants/field_status.go new file mode 100644 index 00000000..fdf96379 --- /dev/null +++ b/constants/field_status.go @@ -0,0 +1,5 @@ +package constants + +// 普通表中status状态 +const STATUS_ON = 1 +const STATUS_OFF = 0 diff --git a/constants/material.go b/constants/material.go new file mode 100644 index 00000000..04226716 --- /dev/null +++ b/constants/material.go @@ -0,0 +1,16 @@ +package constants + +// 材料类型 +var MAP_MATERIAL = map[int64]string{ + 1: "paper", + 2: "glass", + 3: "塑料", + 4: "牛皮纸", + 5: "单层牛皮纸", + 6: "双层牛皮纸", + 7: "PET", + 8: "瓦楞纸", + 9: "厚牛皮纸", + 10: "卡纸", + 11: "PP", +} diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 92ada4c3..14b1bf3e 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -3,7 +3,11 @@ package gmodel import "context" func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) { - err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? and `is_del` =? and `is_shelf` = ? and `status` =?", id, 0, 1, 1).First(&resp).Error + err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error + return resp, err +} +func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string) (resp *FsProduct, err error) { + err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`sn` = ? ", sn).Take(&resp).Error return resp, err } func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) { diff --git a/model/gmodel/fs_product_model3d_light_logic.go b/model/gmodel/fs_product_model3d_light_logic.go index db570d1e..445c26c0 100755 --- a/model/gmodel/fs_product_model3d_light_logic.go +++ b/model/gmodel/fs_product_model3d_light_logic.go @@ -3,6 +3,9 @@ package gmodel import "context" func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) { + if len(ids) == 0 { + return + } err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error return resp, err } @@ -17,3 +20,14 @@ func (l *FsProductModel3dLightModel) Create(ctx context.Context, data *FsProduct func (l *FsProductModel3dLightModel) Update(ctx context.Context, id int64, data *FsProductModel3dLight) error { return l.db.WithContext(ctx).Where("`id` = ?", id).Updates(data).Error } +func (l *FsProductModel3dLightModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3dLight, err error) { + if len(ids) == 0 { + return + } + db := l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?)", ids) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index c1af4b26..2ff1639a 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -60,3 +60,14 @@ func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3 func (d *FsProductModel3dModel) Update(ctx context.Context, id int64, data *FsProductModel3d) error { return d.db.WithContext(ctx).Where("`id` = ? ", id).Updates(&data).Error } +func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64) (resp []FsProductModel3d, err error) { + if len(sizeIds) == 0 { + return + } + err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, 1, tag).Find(&resp).Error + return resp, err +} +func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductModel3d, err error) { + err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_size_logic.go b/model/gmodel/fs_product_size_logic.go index 146554fc..b1ce6705 100755 --- a/model/gmodel/fs_product_size_logic.go +++ b/model/gmodel/fs_product_size_logic.go @@ -75,3 +75,17 @@ func (c *FsProductSizeModel) GetAllSelectIdAndCapacityByIds(ctx context.Context, err = c.db.WithContext(ctx).Where("id IN ?", sizeIds).Select("id", "capacity").Find(&sizes).Error return sizes, err } +func (s *FsProductSizeModel) GetAllByStatus(ctx context.Context, status int64, sortType int, fields ...string) (resp []FsProductSize, err error) { + db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where(" `status` = ?", status) + if len(fields) > 0 { + db = db.Select(fields[0]) + } + switch sortType { + case 1: + db = db.Order("`sort` ASC") + case 2: + db = db.Order("`sort` DESC") + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index dbff11a0..e47b166b 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -24,15 +24,16 @@ func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64 } return } -func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsProductTemplateV2, err error) { +func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductTemplateV2, err error) { if len(ids) == 0 { return } - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) ", ids).Find(&resp).Error - if err != nil { - return nil, err + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) ", ids) + if len(fields) != 0 { + db = db.Select(fields[0]) } - return + err = db.Find(&resp).Error + return resp, err } func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp *FsProductTemplateV2, err error) { @@ -60,3 +61,10 @@ func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelI } return } +func (t *FsProductTemplateV2Model) FindAllByProductIdModelIds(ctx context.Context, ids []int64, productId int64) (resp []FsProductTemplateV2, err error) { + if len(ids) == 0 { + return + } + err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `product_id` ", ids, productId).Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_tags_logic.go b/model/gmodel/fs_tags_logic.go index a822aa58..1a77ccd5 100755 --- a/model/gmodel/fs_tags_logic.go +++ b/model/gmodel/fs_tags_logic.go @@ -13,10 +13,14 @@ func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTa return } err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error - if err != nil { - return nil, err + return resp, err +} +func (t *FsTagsModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsTags, err error) { + if len(ids) == 0 { + return } - return + err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?)", ids).Find(&resp).Error + return resp, err } func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) { err = t.db.Model(&FsTags{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error diff --git a/server/product/internal/handler/getproductinfohandler.go b/server/product/internal/handler/getproductinfohandler.go new file mode 100644 index 00000000..d8c83be3 --- /dev/null +++ b/server/product/internal/handler/getproductinfohandler.go @@ -0,0 +1,78 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" +) + +func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var ( + // 定义错误变量 + err error + // 定义用户信息变量 + userinfo *auth.UserInfo + ) + // 解析JWT token,并对空用户进行判断 + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, // 返回401状态码,表示未授权 + Message: "unauthorized", // 返回未授权信息 + }) + logx.Info("unauthorized:", err.Error()) // 记录错误日志 + return + } + + if claims != nil { + // 从token中获取对应的用户信息 + userinfo, err = auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + } else { + // 如果claims为nil,则认为用户身份为白板用户 + userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} + } + + var req types.GetProductInfoReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetProductInfoLogic(r.Context(), svcCtx) + resp := l.GetProductInfo(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go index 48ef724f..023a5800 100644 --- a/server/product/internal/handler/routes.go +++ b/server/product/internal/handler/routes.go @@ -37,6 +37,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/product/design-gather", Handler: DesignGatherHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/product/info", + Handler: GetProductInfoHandler(serverCtx), + }, }, ) } diff --git a/server/product/internal/logic/getproductinfologic.go b/server/product/internal/logic/getproductinfologic.go new file mode 100644 index 00000000..b7844986 --- /dev/null +++ b/server/product/internal/logic/getproductinfologic.go @@ -0,0 +1,333 @@ +package logic + +import ( + "encoding/json" + "errors" + "fmt" + "fusenapi/constants" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/format" + "fusenapi/utils/image" + "gorm.io/gorm" + "strconv" + "strings" + + "context" + + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetProductInfoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic { + return &GetProductInfoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, userinfo *auth.UserInfo) (resp *basic.Response) { + //获取产品信息 + productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") + } + if req.Size > 0 { + req.Size = image.GetCurrentSize(req.Size) + } + materialIdSlice, err := format.StrSlicToInt64Slice(strings.Split(*productInfo.MaterialIds, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product material Id list") + } + type Material struct { + Id int64 `json:"id"` + Title string `json:"title"` + } + //材料列表 + materials := make([]Material, 0, len(materialIdSlice)) + for _, v := range materialIdSlice { + if title, ok := constants.MAP_MATERIAL[v]; ok { + materials = append(materials, Material{ + Id: v, + Title: title, + }) + } + } + //尺寸列表[这里要处理数据中的title] + sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByStatus(l.ctx, int64(constants.STATUS_ON), 1, "id,title,capacity,cover,sort,parts_can_deleted") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list") + } + sizeIds := make([]int64, 0, len(sizeList)) + for _, v := range sizeList { + sizeIds = append(sizeIds, v.Id) + } + //获取产品标签 + tagInfo, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, *productInfo.Type) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "tag info is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info") + } + typeName := *tagInfo.Title + //获取该尺寸下的模型数据 + model3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list") + } + model3dIds := make([]int64, 0, len(model3dList)) + mapModel3dWithSizeIdIndex := make(map[int64]int) //sizeid为key + for k, v := range model3dList { + model3dIds = append(model3dIds, v.Id) + mapModel3dWithSizeIdIndex[*v.SizeId] = k + } + //通过产品id和模型id获取模板信息 + productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdModelIds(l.ctx, model3dIds, productInfo.Id) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list") + } + //获取模板包含的model_id + mapTemplateModelId := make(map[int64]struct{}) + tagIds := make([]int64, 0, len(productTemplateList)) + for _, v := range productTemplateList { + mapTemplateModelId[v.Id] = struct{}{} + if v.Tag != nil && *v.Tag != "" { + tagId, err := strconv.ParseInt(*v.Tag, 10, 64) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not a number") + } + tagIds = append(tagIds, tagId) + } + } + //过滤没有模板的尺寸数据 + sizeListRsp := make([]types.SizeItem, 0, len(sizeList)) + for _, v := range sizeList { + model3dIndex, ok := mapModel3dWithSizeIdIndex[v.Id] + if !ok { + continue + } + if _, ok = mapTemplateModelId[model3dList[model3dIndex].Id]; !ok { + continue + } + var title types.SizeTitle + if err = json.Unmarshal([]byte(*v.Title), &title); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to decode size info`s title") + } + var modelInfo map[string]interface{} + if err = json.Unmarshal([]byte(*model3dList[model3dIndex].ModelInfo), &modelInfo); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info") + } + cover := "" + if modelInfo["cover"] != nil { + coverArr := strings.Split(modelInfo["cover"].(string), ".") + cover = modelInfo["cover"].(string) + if req.Size >= 200 { + cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1]) + } + } + sizeListRsp = append(sizeListRsp, types.SizeItem{ + Id: v.Id, + Title: title, + Capacity: *v.Capacity, + Cover: cover, + Sort: *v.Sort, + PartsCanDeleted: *v.PartsCanDeleted > 0, + }) + } + //获取标签列表 + tagList, err := l.svcCtx.AllModels.FsTags.GetAllByIdsWithoutStatus(l.ctx, tagIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag list") + } + //获取全部模型信息 + allModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAll(l.ctx) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get all 3d model list") + } + mapAllmodel3d := make(map[int64]int) + optionTemplateIds := make([]int64, 0, len(allModel3dList)) + lightIds := make([]int64, 0, len(allModel3dList)) + for k, v := range allModel3dList { + mapAllmodel3d[v.Id] = k + optionTemplateIds = append(optionTemplateIds, *v.OptionTemplate) + lightIds = append(lightIds, *v.Light) + } + //获取公共模板信息 + optionTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, optionTemplateIds, "id,material_img") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get option template list") + } + mapOptionTemplate := make(map[int64]int) + for k, v := range optionTemplateList { + mapOptionTemplate[v.Id] = k + } + //获取灯光信息 + lightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAllByIdsWithoutStatus(l.ctx, lightIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light list") + } + mapLight := make(map[int64]int) + for k, v := range lightList { + mapLight[v.Id] = k + } + //循环处理组装模板信息 + template484List := make([]interface{}, 0, len(productTemplateList)) + for _, v := range productTemplateList { + allModel3dIndex, ok := mapAllmodel3d[*v.ModelId] + if !ok { + continue + } + //如果是配件信息就跳过,不返回 + if *allModel3dList[allModel3dIndex].Tag == constants.TAG_PARTS { + continue + } + //未编辑模板信息的数据跳过 + if v.TemplateInfo == nil || *v.TemplateInfo == "" { + continue + } + model3dInfo := allModel3dList[allModel3dIndex] + //解码template info + var templateInfo map[string]interface{} + if err = json.Unmarshal([]byte(*v.TemplateInfo), &templateInfo); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template info") + } + if templateInfo["cover"] != nil && templateInfo["cover"].(string) != "" { + cover := templateInfo["cover"].(string) + if req.Size >= 200 { + coverArr := strings.Split(templateInfo["cover"].(string), ".") + cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1]) + } + templateInfo["cover"] = cover + delete(templateInfo, "isPublic") + delete(templateInfo, "name") + } + //解码模型数据 + var modelInfo map[string]interface{} + if err = json.Unmarshal([]byte(*model3dInfo.ModelInfo), &modelInfo); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template info") + } + modelInfo["id"] = allModel3dList[allModel3dIndex].Id + //解码灯光数据 + var lightInfo interface{} + lightIndex, ok := mapLight[*model3dInfo.Light] + if ok && lightList[lightIndex].Info != nil && *lightList[lightIndex].Info != "" { + if err = json.Unmarshal([]byte(*lightList[lightIndex].Info), &lightInfo); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse light info") + } + } + //配件备选项 + modelPartIds, err := format.StrSlicToInt64Slice(strings.Split(*model3dInfo.PartList, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse 3d model`s part_list") + } + partList := make([]interface{}, 0, len(modelPartIds)) + for _, partId := range modelPartIds { + //判断配件信息是否正常 + key, ok := mapAllmodel3d[partId] + if !ok || *allModel3dList[key].Status != 1 { + continue + } + thisInfo := allModel3dList[key] + } + } + /* + //循环处理组装模板信息 + foreach ($templates as $temp) { + foreach ($modelPart as $row) { + //判断配件信息是否正常 + if (isset($models[$row]) && !empty($models[$row]) && $models[$row]['status'] == 1) { + $thisInfo = $models[$row]; + $thisInfo['id'] = $models[$row]['id']; + if (!empty($models[$row]['option_template']) && !is_null($models[$row]['option_template'])) { + $thisInfo['material_img'] = $optionTemlateData[$models[$row]['option_template']]['material_img']; + } else { + $thisInfo['material_img'] = ProductTemplateV2::find()->where(['model_id' => $row])->select(['material_img'])->scalar(); + } + $thisInfo['model_info'] = json_decode($thisInfo['model_info'], true); + $partArr[] = $thisInfo; + } + } + + //按照材质和尺寸来存放模板信息 + $product['templates']["{$materialId}_{$models[$temp['model_id']]['size_id']}"][] = [ + 'id' => $temp['id'], + 'title' => $temp['title'], + 'templateData' => $info, + 'modelData' => $modelData, + 'lightData' => $lightData, + 'partList' => $partArr, + 'tag_name' => isset($tags[$temp['tag']]) ? $tags[$temp['tag']]['title'] : '', + ]; + } + + //产品价格查询 + $prices = ProductPrice::find() + ->andFilterWhere(['product_id' => $product['id']]) + ->statusOn(ProductPrice::STATUS_ON) + ->asArray() + ->all(); + + //循环阶梯价计算 + foreach ($prices as $price) { + $price['step_num'] = explode(',', $price['step_num']); + $price['step_price'] = explode(',', $price['step_price']); + + while ($price['min_buy_num'] < end($price['step_num']) + 5) { + $product['prices']["{$price['material_id']}_{$price['size_id']}"]['items'][] = [ + 'num' => intval($price['min_buy_num']), + 'total_num' => $price['min_buy_num'] * $price['each_box_num'], + 'price' => ProductPriceService::getPrice($price['min_buy_num'], $price['step_num'], $price['step_price']) + ]; + $price['min_buy_num'] += 1; + } + + $product['prices']["{$price['material_id']}_{$price['size_id']}"]['min_price'] = floatval(end($price['step_price']) / 100); + $product['prices']["{$price['material_id']}_{$price['size_id']}"]['max_price'] = floatval(reset($price['step_price']) / 100); + + } + + //这里加一个字段返回数据格式为最新的设计(只有当又用户信息是才会又这个) + $uid = intval(\Yii::$app->getUser()->id); + + $product['last_design'] = (new ProductService())->getLastDesign($uid); + $product['render_design'] = $haveCloudRendering == 'true' ? (new ProductService())->getRenderDesign($clientNo) : null; + + //获取色系数据 + $product['colors'] = ProductService::getColor(); + + //获取用户信息 + $userInfo = User::find()->where(['id' => $uid])->asArray()->one(); + $product['is_low_rendering'] = $userInfo && $userInfo['is_low_rendering'] ? true : false; + $product['is_remove_bg'] = $userInfo && $userInfo['is_remove_bg'] ? true : false;*/ + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 8662df52..4d0e53ee 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -103,6 +103,54 @@ type DesignGatherRsp struct { Sn string `json:"sn"` } +type GetProductInfoReq struct { + Pid string `form:"pid"` + Size uint32 `form:"size"` + ClientNo string `form:"client_no"` + HaveCloudRendering bool `form:"haveCloudRendering"` +} + +type GetProductInfoRsp struct { + Id int64 `json:"id"` + Type int64 `json:"type"` + Title string `json:"title"` + IsEnv int64 `json:"isEnv"` + IsMicro int64 `json:"isMicro"` + TypeName string `json:"typeName"` + IsLowRendering bool `json:"is_low_rendering"` + IsRemoveBg bool `json:"is_remove_bg"` + Materials []MaterialItem `json:"materials"` + Sizes []SizeItem `json:"sizes"` + Templates Templates `json:"templates"` + Price interface{} `json:"price"` + LastDesign interface{} `json:"last_design"` + RenderDesign interface{} `json:"render_design"` + Colors []interface{} `json:"colors"` +} + +type Templates struct { + Template484List []interface{} `json:"4_84"` +} + +type SizeItem struct { + Id int64 `json:"id"` + Title SizeTitle `json:"title"` + Capacity string `json:"capacity"` + Cover string `json:"cover"` + Sort int64 `json:"sort"` + PartsCanDeleted bool `json:"parts_can_deleted"` +} + +type SizeTitle struct { + Cm string `json:"cm"` + Inch string `json:"inch"` +} + +type MaterialItem struct { + Id int64 `json:"id"` + Title string `json:"title"` +} + type Request struct { } diff --git a/server_api/product.api b/server_api/product.api index b31e45e6..324a8cb8 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -121,9 +121,45 @@ type DesignGatherRsp { Sn string `json:"sn"` } //获取产品信息 -type GetProductInfoReq{ - Pid string `form:"pid"` - Size int64 `form:"size"` - ClientNo string `form:"client_no"` - HaveCloudRendering bool `form:"haveCloudRendering"` +type GetProductInfoReq { + Pid string `form:"pid"` + Size uint32 `form:"size"` + ClientNo string `form:"client_no"` + HaveCloudRendering bool `form:"haveCloudRendering"` +} +type GetProductInfoRsp { + Id int64 `json:"id"` + Type int64 `json:"type"` + Title string `json:"title"` + IsEnv int64 `json:"isEnv"` + IsMicro int64 `json:"isMicro"` + TypeName string `json:"typeName"` + IsLowRendering bool `json:"is_low_rendering"` + IsRemoveBg bool `json:"is_remove_bg"` + Materials []MaterialItem `json:"materials"` + Sizes []SizeItem `json:"sizes"` + Templates Templates `json:"templates"` + Price interface{} `json:"price"` + LastDesign interface{} `json:"last_design"` + RenderDesign interface{} `json:"render_design"` + Colors []interface{} `json:"colors"` +} +type Templates { + Template484List []interface{} `json:"4_84"` +} +type SizeItem { + Id int64 `json:"id"` + Title SizeTitle `json:"title"` + Capacity string `json:"capacity"` + Cover string `json:"cover"` + Sort int64 `json:"sort"` + PartsCanDeleted bool `json:"parts_can_deleted"` +} +type SizeTitle { + Cm string `json:"cm"` + Inch string `json:"inch"` +} +type MaterialItem { + Id int64 `json:"id"` + Title string `json:"title"` } \ No newline at end of file