fix
This commit is contained in:
parent
8d190f0097
commit
d455f3b256
29
ddl/fs_cart.sql
Normal file
29
ddl/fs_cart.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- fusentest.fs_cart definition
|
||||||
|
|
||||||
|
CREATE TABLE `fs_cart` (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||||
|
`user_id` int(10) unsigned DEFAULT NULL COMMENT '用户ID',
|
||||||
|
`product_id` int(10) unsigned NOT NULL COMMENT '产品ID',
|
||||||
|
`template_id` int(10) unsigned NOT NULL COMMENT '模板ID',
|
||||||
|
`price_id` int(10) unsigned NOT NULL COMMENT '价格ID',
|
||||||
|
`material_id` int(10) unsigned NOT NULL COMMENT '材质ID',
|
||||||
|
`size_id` int(10) unsigned NOT NULL COMMENT '尺寸ID',
|
||||||
|
`buy_num` int(10) unsigned NOT NULL COMMENT '购买数量',
|
||||||
|
`cover` varchar(128) NOT NULL COMMENT '截图',
|
||||||
|
`design_id` int(10) unsigned NOT NULL COMMENT '设计ID',
|
||||||
|
`ctime` int(10) unsigned DEFAULT NULL COMMENT '添加时间',
|
||||||
|
`status` tinyint(3) unsigned NOT NULL COMMENT '状态位',
|
||||||
|
`optional_id` int(11) NOT NULL DEFAULT '0' COMMENT '选项ID',
|
||||||
|
`is_check` int(11) NOT NULL COMMENT '是否选中状态(0:未选中,1:选中)',
|
||||||
|
`ts_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`is_email` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发送邮件',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
KEY `user_id` (`user_id`) USING BTREE,
|
||||||
|
KEY `product_id` (`product_id`) USING BTREE,
|
||||||
|
KEY `template_id` (`template_id`) USING BTREE,
|
||||||
|
KEY `price_id` (`price_id`) USING BTREE,
|
||||||
|
KEY `material_id` (`material_id`) USING BTREE,
|
||||||
|
KEY `size_id` (`size_id`) USING BTREE,
|
||||||
|
KEY `design_id` (`design_id`) USING BTREE,
|
||||||
|
KEY `optional_id` (`optional_id`) USING BTREE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=800 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='购物车';
|
28
ddl/fs_product_design.sql
Normal file
28
ddl/fs_product_design.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
-- fusentest.fs_product_design definition
|
||||||
|
|
||||||
|
CREATE TABLE `fs_product_design` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`sn` char(8) NOT NULL COMMENT '唯一标识',
|
||||||
|
`user_id` int(11) NOT NULL COMMENT '用户ID',
|
||||||
|
`product_id` int(11) NOT NULL COMMENT '产品ID',
|
||||||
|
`template_id` int(11) NOT NULL COMMENT '模型ID',
|
||||||
|
`material_id` int(11) NOT NULL COMMENT '材质ID',
|
||||||
|
`size_id` int(11) NOT NULL COMMENT '尺寸ID',
|
||||||
|
`optional_id` int(11) NOT NULL DEFAULT '0' COMMENT '选项ID',
|
||||||
|
`cover` varchar(128) NOT NULL COMMENT '封面图',
|
||||||
|
`info` text COMMENT '保留的设计信息',
|
||||||
|
`utime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态',
|
||||||
|
`is_del` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 0未删除 1删除',
|
||||||
|
`is_pay` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已有支付 0 未 1 有',
|
||||||
|
`logo_color` text COMMENT 'logo图片备选项',
|
||||||
|
`page_guid` varchar(50) NOT NULL DEFAULT '' COMMENT '页面识别id',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
KEY `sn` (`sn`) USING BTREE,
|
||||||
|
KEY `user_id` (`user_id`) USING BTREE,
|
||||||
|
KEY `product_id` (`product_id`) USING BTREE,
|
||||||
|
KEY `template_id` (`template_id`) USING BTREE,
|
||||||
|
KEY `material_id` (`material_id`) USING BTREE,
|
||||||
|
KEY `size_id` (`size_id`) USING BTREE,
|
||||||
|
KEY `optional_id` (`optional_id`) USING BTREE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=727 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='产品设计表';
|
@ -4,6 +4,9 @@ import (
|
|||||||
{{.configImport}}
|
{{.configImport}}
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"net/http"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
@ -16,7 +19,7 @@ func NewServiceContext(c {{.config}}) *ServiceContext {
|
|||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
MysqlConn: initalize.InitMysql(c.DataSource),
|
||||||
{{.middlewareAssignment}}
|
{{.middlewareAssignment}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
model/fscartmodel.go
Executable file
24
model/fscartmodel.go
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
|
||||||
|
var _ FsCartModel = (*customFsCartModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// FsCartModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customFsCartModel.
|
||||||
|
FsCartModel interface {
|
||||||
|
fsCartModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customFsCartModel struct {
|
||||||
|
*defaultFsCartModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewFsCartModel returns a model for the database table.
|
||||||
|
func NewFsCartModel(conn sqlx.SqlConn) FsCartModel {
|
||||||
|
return &customFsCartModel{
|
||||||
|
defaultFsCartModel: newFsCartModel(conn),
|
||||||
|
}
|
||||||
|
}
|
99
model/fscartmodel_gen.go
Executable file
99
model/fscartmodel_gen.go
Executable file
@ -0,0 +1,99 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fsCartFieldNames = builder.RawFieldNames(&FsCart{})
|
||||||
|
fsCartRows = strings.Join(fsCartFieldNames, ",")
|
||||||
|
fsCartRowsExpectAutoSet = strings.Join(stringx.Remove(fsCartFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||||
|
fsCartRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCartFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
fsCartModel interface {
|
||||||
|
Insert(ctx context.Context, data *FsCart) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*FsCart, error)
|
||||||
|
Update(ctx context.Context, data *FsCart) error
|
||||||
|
Delete(ctx context.Context, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultFsCartModel struct {
|
||||||
|
conn sqlx.SqlConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
FsCart struct {
|
||||||
|
Id int64 `db:"id"` // id
|
||||||
|
UserId sql.NullInt64 `db:"user_id"` // 用户ID
|
||||||
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
|
TemplateId int64 `db:"template_id"` // 模板ID
|
||||||
|
PriceId int64 `db:"price_id"` // 价格ID
|
||||||
|
MaterialId int64 `db:"material_id"` // 材质ID
|
||||||
|
SizeId int64 `db:"size_id"` // 尺寸ID
|
||||||
|
BuyNum int64 `db:"buy_num"` // 购买数量
|
||||||
|
Cover string `db:"cover"` // 截图
|
||||||
|
DesignId int64 `db:"design_id"` // 设计ID
|
||||||
|
Ctime sql.NullInt64 `db:"ctime"` // 添加时间
|
||||||
|
Status int64 `db:"status"` // 状态位
|
||||||
|
OptionalId int64 `db:"optional_id"` // 选项ID
|
||||||
|
IsCheck int64 `db:"is_check"` // 是否选中状态(0:未选中,1:选中)
|
||||||
|
TsTime time.Time `db:"ts_time"`
|
||||||
|
IsEmail int64 `db:"is_email"` // 是否发送邮件
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newFsCartModel(conn sqlx.SqlConn) *defaultFsCartModel {
|
||||||
|
return &defaultFsCartModel{
|
||||||
|
conn: conn,
|
||||||
|
table: "`fs_cart`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCartModel) Delete(ctx context.Context, id int64) error {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCartModel) FindOne(ctx context.Context, id int64) (*FsCart, error) {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCartRows, m.table)
|
||||||
|
var resp FsCart
|
||||||
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCartModel) Insert(ctx context.Context, data *FsCart) (sql.Result, error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsCartRowsExpectAutoSet)
|
||||||
|
ret, err := m.conn.ExecCtx(ctx, query, data.UserId, data.ProductId, data.TemplateId, data.PriceId, data.MaterialId, data.SizeId, data.BuyNum, data.Cover, data.DesignId, data.Ctime, data.Status, data.OptionalId, data.IsCheck, data.TsTime, data.IsEmail)
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCartModel) Update(ctx context.Context, data *FsCart) error {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCartRowsWithPlaceHolder)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, data.UserId, data.ProductId, data.TemplateId, data.PriceId, data.MaterialId, data.SizeId, data.BuyNum, data.Cover, data.DesignId, data.Ctime, data.Status, data.OptionalId, data.IsCheck, data.TsTime, data.IsEmail, data.Id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCartModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
24
model/fsproductdesignmodel.go
Executable file
24
model/fsproductdesignmodel.go
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
|
||||||
|
var _ FsProductDesignModel = (*customFsProductDesignModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// FsProductDesignModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customFsProductDesignModel.
|
||||||
|
FsProductDesignModel interface {
|
||||||
|
fsProductDesignModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customFsProductDesignModel struct {
|
||||||
|
*defaultFsProductDesignModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewFsProductDesignModel returns a model for the database table.
|
||||||
|
func NewFsProductDesignModel(conn sqlx.SqlConn) FsProductDesignModel {
|
||||||
|
return &customFsProductDesignModel{
|
||||||
|
defaultFsProductDesignModel: newFsProductDesignModel(conn),
|
||||||
|
}
|
||||||
|
}
|
99
model/fsproductdesignmodel_gen.go
Executable file
99
model/fsproductdesignmodel_gen.go
Executable file
@ -0,0 +1,99 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fsProductDesignFieldNames = builder.RawFieldNames(&FsProductDesign{})
|
||||||
|
fsProductDesignRows = strings.Join(fsProductDesignFieldNames, ",")
|
||||||
|
fsProductDesignRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductDesignFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||||
|
fsProductDesignRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductDesignFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
fsProductDesignModel interface {
|
||||||
|
Insert(ctx context.Context, data *FsProductDesign) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*FsProductDesign, error)
|
||||||
|
Update(ctx context.Context, data *FsProductDesign) error
|
||||||
|
Delete(ctx context.Context, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultFsProductDesignModel struct {
|
||||||
|
conn sqlx.SqlConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
FsProductDesign struct {
|
||||||
|
Id int64 `db:"id"`
|
||||||
|
Sn string `db:"sn"` // 唯一标识
|
||||||
|
UserId int64 `db:"user_id"` // 用户ID
|
||||||
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
|
TemplateId int64 `db:"template_id"` // 模型ID
|
||||||
|
MaterialId int64 `db:"material_id"` // 材质ID
|
||||||
|
SizeId int64 `db:"size_id"` // 尺寸ID
|
||||||
|
OptionalId int64 `db:"optional_id"` // 选项ID
|
||||||
|
Cover string `db:"cover"` // 封面图
|
||||||
|
Info sql.NullString `db:"info"` // 保留的设计信息
|
||||||
|
Utime time.Time `db:"utime"` // 更新时间
|
||||||
|
Status int64 `db:"status"` // 状态
|
||||||
|
IsDel int64 `db:"is_del"` // 是否删除 0未删除 1删除
|
||||||
|
IsPay int64 `db:"is_pay"` // 是否已有支付 0 未 1 有
|
||||||
|
LogoColor sql.NullString `db:"logo_color"` // logo图片备选项
|
||||||
|
PageGuid string `db:"page_guid"` // 页面识别id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newFsProductDesignModel(conn sqlx.SqlConn) *defaultFsProductDesignModel {
|
||||||
|
return &defaultFsProductDesignModel{
|
||||||
|
conn: conn,
|
||||||
|
table: "`fs_product_design`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsProductDesignModel) Delete(ctx context.Context, id int64) error {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsProductDesignModel) FindOne(ctx context.Context, id int64) (*FsProductDesign, error) {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductDesignRows, m.table)
|
||||||
|
var resp FsProductDesign
|
||||||
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsProductDesignModel) Insert(ctx context.Context, data *FsProductDesign) (sql.Result, error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductDesignRowsExpectAutoSet)
|
||||||
|
ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.UserId, data.ProductId, data.TemplateId, data.MaterialId, data.SizeId, data.OptionalId, data.Cover, data.Info, data.Utime, data.Status, data.IsDel, data.IsPay, data.LogoColor, data.PageGuid)
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsProductDesignModel) Update(ctx context.Context, data *FsProductDesign) error {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductDesignRowsWithPlaceHolder)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, data.Sn, data.UserId, data.ProductId, data.TemplateId, data.MaterialId, data.SizeId, data.OptionalId, data.Cover, data.Info, data.Utime, data.Status, data.IsDel, data.IsPay, data.LogoColor, data.PageGuid, data.Id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsProductDesignModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
@ -35,6 +35,9 @@ func (c *FsCanteenProductModel) UpdateById(ctx context.Context, id int64, data *
|
|||||||
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` = ? ", id).Updates(&data).Error
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` = ? ", id).Updates(&data).Error
|
||||||
}
|
}
|
||||||
func (c *FsCanteenProductModel) UpdateByIdArr(ctx context.Context, ids []int64, data *FsCanteenProduct) error {
|
func (c *FsCanteenProductModel) UpdateByIdArr(ctx context.Context, ids []int64, data *FsCanteenProduct) error {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
|
||||||
}
|
}
|
||||||
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {
|
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {
|
||||||
|
88
model/gmodel/fscartmodel.go
Executable file
88
model/gmodel/fscartmodel.go
Executable file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsCart struct {
|
||||||
|
Id int64 `gorm:"primary_key" json:"id"` // id
|
||||||
|
UserId *int64 `gorm:"default:0" json:"user_id"` // 用户ID
|
||||||
|
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
|
||||||
|
TemplateId *int64 `gorm:"default:0" json:"template_id"` // 模板ID
|
||||||
|
PriceId *int64 `gorm:"default:0" json:"price_id"` // 价格ID
|
||||||
|
MaterialId *int64 `gorm:"default:0" json:"material_id"` // 材质ID
|
||||||
|
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
|
||||||
|
BuyNum *int64 `gorm:"default:0" json:"buy_num"` // 购买数量
|
||||||
|
Cover *string `gorm:"default:''" json:"cover"` // 截图
|
||||||
|
DesignId *int64 `gorm:"default:0" json:"design_id"` // 设计ID
|
||||||
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
|
Status *int64 `gorm:"default:1" json:"status"` // 状态位
|
||||||
|
OptionalId *int64 `gorm:"default:0" json:"optional_id"` // 选项ID
|
||||||
|
IsCheck *int64 `gorm:"default:0" json:"is_check"` // 是否选中状态(0:未选中,1:选中)
|
||||||
|
TsTime *time.Time `gorm:"" json:"ts_time"`
|
||||||
|
IsEmail *int64 `gorm:"default:0" json:"is_email"` // 是否发送邮件
|
||||||
|
}
|
||||||
|
type FsCartModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsCartModel(db *gorm.DB) *FsCartModel {
|
||||||
|
return &FsCartModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FindOneCartByParamsReq struct {
|
||||||
|
UserId *int64
|
||||||
|
ProductId *int64
|
||||||
|
TemplateId *int64
|
||||||
|
PriceId *int64
|
||||||
|
DesignId *int64
|
||||||
|
MaterialId *int64
|
||||||
|
Status *int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FsCartModel) FindOne(ctx context.Context, id int64) (resp FsCart, err error) {
|
||||||
|
err = c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).First(&resp).Error
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsCart{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartByParamsReq) (resp FsCart, err error) {
|
||||||
|
db := c.db.WithContext(ctx).Model(&FsCart{})
|
||||||
|
if req.UserId != nil {
|
||||||
|
db = db.Where("`user_id` = ?", req.UserId)
|
||||||
|
}
|
||||||
|
if req.ProductId != nil {
|
||||||
|
db = db.Where("`product_id` = ?", req.ProductId)
|
||||||
|
}
|
||||||
|
if req.TemplateId != nil {
|
||||||
|
db = db.Where("`template_id` = ?", req.TemplateId)
|
||||||
|
}
|
||||||
|
if req.PriceId != nil {
|
||||||
|
db = db.Where("`price_id` = ?", req.ProductId)
|
||||||
|
}
|
||||||
|
if req.DesignId != nil {
|
||||||
|
db = db.Where("`design_id` = ?", req.DesignId)
|
||||||
|
}
|
||||||
|
if req.MaterialId != nil {
|
||||||
|
db = db.Where("`material_id` = ?", req.MaterialId)
|
||||||
|
}
|
||||||
|
if req.Status != nil {
|
||||||
|
db = db.Where("`status` = ?", req.Status)
|
||||||
|
}
|
||||||
|
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsCart{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCart{}).Create(data).Error
|
||||||
|
}
|
||||||
|
func (c *FsCartModel) Update(ctx context.Context, id int64, data FsCart) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error
|
||||||
|
}
|
42
model/gmodel/fsproductdesignmodel.go
Executable file
42
model/gmodel/fsproductdesignmodel.go
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsProductDesign struct {
|
||||||
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
Sn *string `gorm:"default:''" json:"sn"` // 唯一标识
|
||||||
|
UserId *int64 `gorm:"default:0" json:"user_id"` // 用户ID
|
||||||
|
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
|
||||||
|
TemplateId *int64 `gorm:"default:0" json:"template_id"` // 模型ID
|
||||||
|
MaterialId *int64 `gorm:"default:0" json:"material_id"` // 材质ID
|
||||||
|
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
|
||||||
|
OptionalId *int64 `gorm:"default:0" json:"optional_id"` // 选项ID
|
||||||
|
Cover *string `gorm:"default:''" json:"cover"` // 封面图
|
||||||
|
Info *string `gorm:"default:''" json:"info"` // 保留的设计信息
|
||||||
|
Utime *time.Time `gorm:"" json:"utime"` // 更新时间
|
||||||
|
Status *int64 `gorm:"default:1" json:"status"` // 状态
|
||||||
|
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 0未删除 1删除
|
||||||
|
IsPay *int64 `gorm:"default:0" json:"is_pay"` // 是否已有支付 0 未 1 有
|
||||||
|
LogoColor *string `gorm:"default:''" json:"logo_color"` // logo图片备选项
|
||||||
|
PageGuid *string `gorm:"default:''" json:"page_guid"` // 页面识别id
|
||||||
|
}
|
||||||
|
type FsProductDesignModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductDesignModel(db *gorm.DB) *FsProductDesignModel {
|
||||||
|
return &FsProductDesignModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string) (resp FsProductDesign, err error) {
|
||||||
|
err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ? and `status` = ?", sn, 1).First(&resp).Error
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsProductDesign{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -45,6 +45,9 @@ func NewFsProductModel(db *gorm.DB) *FsProductModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
||||||
|
if len(productIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
db := p.db.Model(&FsProduct{}).
|
db := p.db.Model(&FsProduct{}).
|
||||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
||||||
switch sort {
|
switch sort {
|
||||||
@ -60,6 +63,9 @@ func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
|
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
|
||||||
|
if len(productTypes) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productTypes, 0, 1, 1)
|
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productTypes, 0, 1, 1)
|
||||||
switch sort {
|
switch sort {
|
||||||
case "sort-asc":
|
case "sort-asc":
|
||||||
|
@ -2,6 +2,7 @@ package gmodel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,9 +46,39 @@ func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, prod
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
|
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
|
||||||
|
if len(sizeIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
|
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FindOneProductPriceByParamsReq struct {
|
||||||
|
ProductId *int64
|
||||||
|
MaterialId *int64
|
||||||
|
SizeId *int64
|
||||||
|
Status *int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *FsProductPriceModel) FindOneProductPriceByParams(ctx context.Context, req FindOneProductPriceByParamsReq) (resp FsProductPrice, err error) {
|
||||||
|
db := p.db.WithContext(ctx).Model(&FsProductPrice{})
|
||||||
|
if req.ProductId != nil {
|
||||||
|
db = db.Where("`product_id` = ?", *req.ProductId)
|
||||||
|
}
|
||||||
|
if req.MaterialId != nil {
|
||||||
|
db = db.Where("`material_id` = ?", *req.MaterialId)
|
||||||
|
}
|
||||||
|
if req.SizeId != nil {
|
||||||
|
db = db.Where("`size_id` = ?", *req.SizeId)
|
||||||
|
}
|
||||||
|
if req.Status != nil {
|
||||||
|
db = db.Where("`status` = ?", *req.Status)
|
||||||
|
}
|
||||||
|
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsProductPrice{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -26,6 +26,9 @@ func NewFsProductSizeModel(db *gorm.DB) *FsProductSizeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {
|
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
db := s.db.Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
db := s.db.Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
||||||
switch sort {
|
switch sort {
|
||||||
case "sort-asc":
|
case "sort-asc":
|
||||||
|
@ -31,6 +31,9 @@ func NewFsProductTemplateV2Model(db *gorm.DB) *FsProductTemplateV2Model {
|
|||||||
return &FsProductTemplateV2Model{db}
|
return &FsProductTemplateV2Model{db}
|
||||||
}
|
}
|
||||||
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
|
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
|
||||||
|
if len(productIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -34,6 +34,9 @@ func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
|
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
|
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
Name: shopping-cart-confirmation
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8892
|
||||||
|
DataSource: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||||
|
Auth:
|
||||||
|
AccessSecret: fusen2023
|
||||||
|
AccessExpire: 604800
|
||||||
|
RefreshAfter: 345600
|
12
server/shopping-cart-confirmation/internal/config/config.go
Normal file
12
server/shopping-cart-confirmation/internal/config/config.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/types"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
DataSource string
|
||||||
|
Auth types.Auth
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
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/shopping-cart-confirmation/internal/logic"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/svc"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从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
|
||||||
|
}
|
||||||
|
|
||||||
|
var req types.CartAddReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewCartAddLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.CartAdd(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
server/shopping-cart-confirmation/internal/handler/routes.go
Normal file
22
server/shopping-cart-confirmation/internal/handler/routes.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/cart/add",
|
||||||
|
Handler: CartAddHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
126
server/shopping-cart-confirmation/internal/logic/cartaddlogic.go
Normal file
126
server/shopping-cart-confirmation/internal/logic/cartaddlogic.go
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/svc"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CartAddLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
|
||||||
|
return &CartAddLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加入购物车
|
||||||
|
func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if req.BuyNum == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeApiErr, "param buy_num can`t be 0")
|
||||||
|
}
|
||||||
|
if req.IsCheck != 0 && req.IsCheck != 1 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeApiErr, "param is_check should be 0 or 1")
|
||||||
|
}
|
||||||
|
req.DesignId = strings.Trim(req.DesignId, " ")
|
||||||
|
if req.DesignId == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeApiErr, "param design_id can`t be empty")
|
||||||
|
}
|
||||||
|
//查询是否有此设计
|
||||||
|
productDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
|
||||||
|
productDesignInfo, err := productDesignModel.FindOneBySn(l.ctx, req.DesignId)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product design info")
|
||||||
|
}
|
||||||
|
if productDesignInfo.Id == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product design info is not exists")
|
||||||
|
}
|
||||||
|
//查找是否有此材质、产品、大小id的阶梯价格
|
||||||
|
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||||
|
priceStatus := int64(1)
|
||||||
|
priceReq := gmodel.FindOneProductPriceByParamsReq{
|
||||||
|
ProductId: productDesignInfo.ProductId,
|
||||||
|
MaterialId: productDesignInfo.MaterialId,
|
||||||
|
SizeId: productDesignInfo.SizeId,
|
||||||
|
Status: &priceStatus,
|
||||||
|
}
|
||||||
|
productPriceInfo, err := productPriceModel.FindOneProductPriceByParams(l.ctx, priceReq)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product price info")
|
||||||
|
}
|
||||||
|
if productPriceInfo.Id == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, " product price info is not exists")
|
||||||
|
}
|
||||||
|
if *productPriceInfo.EachBoxNum == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, " product price info err: each box num can`t be zero")
|
||||||
|
}
|
||||||
|
//买的数量和每箱数量取余为0 且 份数大于等于最小购买数量才算满足条件
|
||||||
|
if (int64(req.BuyNum) % *productPriceInfo.EachBoxNum) != 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid buy number,please check")
|
||||||
|
}
|
||||||
|
if int64(float64(req.BuyNum)/float64(*productPriceInfo.EachBoxNum)) < *productPriceInfo.MinBuyNum {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid buy number,please check!")
|
||||||
|
}
|
||||||
|
//查询购物车
|
||||||
|
cartModel := gmodel.NewFsCartModel(l.svcCtx.MysqlConn)
|
||||||
|
cartStatus := int64(1)
|
||||||
|
cartReq := gmodel.FindOneCartByParamsReq{
|
||||||
|
UserId: &userinfo.UserId,
|
||||||
|
ProductId: productDesignInfo.ProductId,
|
||||||
|
TemplateId: productDesignInfo.TemplateId,
|
||||||
|
PriceId: &productPriceInfo.Id,
|
||||||
|
DesignId: &productDesignInfo.Id,
|
||||||
|
MaterialId: productDesignInfo.MaterialId,
|
||||||
|
Status: &cartStatus,
|
||||||
|
}
|
||||||
|
cartInfo, err := cartModel.FindOneCartByParams(l.ctx, cartReq)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get cart info")
|
||||||
|
}
|
||||||
|
now := time.Now().Unix()
|
||||||
|
nowTime := time.Now()
|
||||||
|
data := gmodel.FsCart{
|
||||||
|
UserId: &userinfo.UserId,
|
||||||
|
ProductId: productPriceInfo.ProductId,
|
||||||
|
TemplateId: productDesignInfo.TemplateId,
|
||||||
|
PriceId: &productPriceInfo.Id,
|
||||||
|
MaterialId: productDesignInfo.MaterialId,
|
||||||
|
SizeId: productDesignInfo.SizeId,
|
||||||
|
BuyNum: &req.BuyNum,
|
||||||
|
Cover: productDesignInfo.Cover,
|
||||||
|
DesignId: &productDesignInfo.Id,
|
||||||
|
Ctime: &now,
|
||||||
|
Status: &cartStatus,
|
||||||
|
OptionalId: productDesignInfo.OptionalId,
|
||||||
|
IsCheck: &req.IsCheck,
|
||||||
|
TsTime: &nowTime,
|
||||||
|
}
|
||||||
|
if cartInfo.Id == 0 {
|
||||||
|
err = cartModel.Create(l.ctx, data)
|
||||||
|
} else {
|
||||||
|
err = cartModel.Update(l.ctx, cartInfo.Id, data)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
|
||||||
|
}
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/initalize"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/config"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
|
||||||
|
MysqlConn *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
MysqlConn: initalize.InitMysql(c.DataSource),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||||
|
AuthKey := r.Header.Get("Authorization")
|
||||||
|
if len(AuthKey) <= 50 {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
||||||
|
// 检查签名方法是否为 HS256
|
||||||
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||||
|
}
|
||||||
|
// 返回用于验证签名的密钥
|
||||||
|
return svcCxt.Config.Auth.AccessSecret, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证成功返回
|
||||||
|
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||||
|
return claims, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
||||||
|
}
|
72
server/shopping-cart-confirmation/internal/types/types.go
Normal file
72
server/shopping-cart-confirmation/internal/types/types.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CartAddReq struct {
|
||||||
|
DesignId string `json:"design_id"` //设计sn
|
||||||
|
BuyNum int64 `json:"buy_num"` //购买数量
|
||||||
|
IsCheck int64 `json:"isCheck,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResponseJwt struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
AccessSecret string `json:"accessSecret"`
|
||||||
|
AccessExpire int64 `json:"accessExpire"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Auth struct {
|
||||||
|
AccessSecret string `json:"accessSecret"`
|
||||||
|
AccessExpire int64 `json:"accessExpire"`
|
||||||
|
RefreshAfter int64 `json:"refreshAfter"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set 设置Response的Code和Message值
|
||||||
|
func (resp *Response) Set(Code int, Message string) *Response {
|
||||||
|
return &Response{
|
||||||
|
Code: Code,
|
||||||
|
Message: Message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set 设置整个Response
|
||||||
|
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||||
|
return &Response{
|
||||||
|
Code: Code,
|
||||||
|
Message: Message,
|
||||||
|
Data: Data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||||
|
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
||||||
|
newResp := &Response{
|
||||||
|
Code: sr.Code,
|
||||||
|
}
|
||||||
|
if len(data) == 1 {
|
||||||
|
newResp.Data = data[0]
|
||||||
|
}
|
||||||
|
return newResp
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||||
|
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
||||||
|
newResp := &Response{
|
||||||
|
Code: sr.Code,
|
||||||
|
Message: msg,
|
||||||
|
}
|
||||||
|
if len(data) == 1 {
|
||||||
|
newResp.Data = data[0]
|
||||||
|
}
|
||||||
|
return newResp
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/config"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/handler"
|
||||||
|
"fusenapi/server/shopping-cart-confirmation/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/shopping-cart-confirmation.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
// var testConfigFile = flag.String("f", "../etc/shopping-cart-confirmation.yaml", "the config file")
|
||||||
|
// var cnf config.Config
|
||||||
|
|
||||||
|
// func GetTestServer() *rest.Server {
|
||||||
|
// flag.Parse()
|
||||||
|
|
||||||
|
// conf.MustLoad(*testConfigFile, &cnf)
|
||||||
|
|
||||||
|
// server := rest.MustNewServer(cnf.RestConf)
|
||||||
|
// defer server.Stop()
|
||||||
|
|
||||||
|
// ctx := svc.NewServiceContext(cnf)
|
||||||
|
// handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
// fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
||||||
|
// return server
|
||||||
|
// }
|
@ -1,23 +1,21 @@
|
|||||||
syntax = "v1"
|
syntax = "v1"
|
||||||
|
|
||||||
info (
|
info (
|
||||||
title: // TODO: add title
|
title: "购物车服务"
|
||||||
desc: // TODO: add description
|
desc: // TODO: add description
|
||||||
author: ""
|
author: "ldm"
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
import "basic.api"
|
||||||
type request {
|
service shopping-cart-confirmation {
|
||||||
// TODO: add members here and delete this comment
|
//添加入购物车
|
||||||
Name string `path:"name,options=you|me"` // parameters are auto validated
|
@handler CartAddHandler
|
||||||
|
post /cart/add (CartAddReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
type response {
|
//添加入购物车
|
||||||
// TODO: add members here and delete this comment
|
type CartAddReq {
|
||||||
Message string `json:"message"`
|
DesignId string `json:"design_id"` //设计sn
|
||||||
}
|
BuyNum int64 `json:"buy_num"` //购买数量
|
||||||
|
IsCheck int64 `json:"isCheck,optional"`
|
||||||
service user-auth {
|
|
||||||
@handler GreetHandler
|
|
||||||
get /greet/from/:name(request) returns (response);
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user