Selaa lähdekoodia

feature(产品): 产品添加启用、停用状态

lk 2 vuotta sitten
vanhempi
commit
fe193a1a29

+ 3 - 0
opms_parent/app/dao/base/internal/base_product.go

@@ -37,6 +37,7 @@ type baseProductColumns struct {
 	DistPrice   string // 经销商价
 	AgentPrice  string // 签约代理价
 	MarketPrice string // 市场报价
+	State       string // 20停用 10正常(包括其他)
 	Remark      string // 备注
 	CreatedBy   string // 创建者
 	CreatedName string // 创建人
@@ -62,6 +63,7 @@ var (
 			DistPrice:   "dist_price",
 			AgentPrice:  "agent_price",
 			MarketPrice: "market_price",
+			State:       "state",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",
@@ -89,6 +91,7 @@ func NewBaseProductDao(tenant string) BaseProductDao {
 			DistPrice:   "dist_price",
 			AgentPrice:  "agent_price",
 			MarketPrice: "market_price",
+			State:       "state",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",

+ 16 - 0
opms_parent/app/handler/base/product.go

@@ -100,3 +100,19 @@ func (b *ProductHandler) UpdateById(ctx context.Context, req *model.UpdateProduc
 	return nil
 
 }
+
+//UpdateState 更新状态
+func (b *ProductHandler) UpdateState(ctx context.Context, req *model.UpdateStateReq, rsp *comm_def.CommonMsg) error {
+	s, err := server.NewProductService(ctx)
+	if err != nil {
+
+		return err
+	}
+	err = s.UpdateState(req)
+	if err != nil {
+
+		return err
+	}
+	return nil
+
+}

+ 8 - 0
opms_parent/app/model/base/base_product.go

@@ -21,6 +21,7 @@ type ProductSearchReq struct {
 	ProdClass    string `json:"ProdClass"`
 	OnlyHardware bool   `json:"onlyHardware"` // 只查询硬件产品
 	OnlySoftware bool   `json:"onlySoftware"` // 只查询软件产品
+	StateType    string `json:"stateType"`    // 状态
 	request.PageReq
 }
 
@@ -33,6 +34,7 @@ type AddProductReq struct {
 	DistPrice   string `p:"distPrice"   json:"distPrice"      v:"required#经销商价不允许为空"`
 	AgentPrice  string `p:"agentPrice"  json:"agentPrice"    v:"required#签约代理价不允许为空"`
 	MarketPrice string `p:"marketPrice" json:"marketPrice"   v:"required#市场报价不允许为空"`
+	State       string `p:"state"       json:"state"`
 	Remark      string
 }
 
@@ -42,6 +44,12 @@ type UpdateProductReq struct {
 	Id int `p:"id" json:"id" v:"required# id不能为空"`
 }
 
+//UpdateStateReq 修改数据
+type UpdateStateReq struct {
+	State string `p:"state"       json:"state"`
+	Id    int    `p:"id" json:"id" v:"required# id不能为空"`
+}
+
 //DeIds 批量删除
 type DeIds struct {
 	Ids []int64 `json:"ids,omitempty,string"`

+ 1 - 0
opms_parent/app/model/base/internal/base_product.go

@@ -18,6 +18,7 @@ type BaseProduct struct {
 	DistPrice   float64     `orm:"dist_price"   json:"distPrice"`   // 经销商价
 	AgentPrice  float64     `orm:"agent_price"  json:"agentPrice"`  // 签约代理价
 	MarketPrice float64     `orm:"market_price" json:"marketPrice"` // 市场报价
+	State       string      `orm:"state"        json:"state"`       // 20停用 10正常(包括其他)
 	Remark      string      `orm:"remark"       json:"remark"`      // 备注
 	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
 	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人

+ 16 - 0
opms_parent/app/service/base/base_product.go

@@ -46,6 +46,11 @@ func (s *productService) GetList(req *model.ProductSearchReq) (total int, produc
 	if req.OnlySoftware {
 		Dao = Dao.Where("prod_class in (10,20,30)")
 	}
+	if req.StateType == "启用" {
+		Dao = Dao.Where("state IS NULL OR state<>'20'")
+	} else if req.StateType == "禁用" {
+		Dao = Dao.Where("state='20'")
+	}
 
 	total, err = Dao.Count()
 	if err != nil {
@@ -78,6 +83,7 @@ func (s *productService) Create(req *model.AddProductReq) (lastInsertId int64, e
 		g.Log().Error(err)
 		return
 	}
+	product.State = "10"
 	service.SetCreatedInfo(product, s.GetCxtUserId(), s.GetCxtUserName())
 	lastInsertId, err = s.Dao.InsertAndGetId(product)
 	if err != nil {
@@ -109,6 +115,16 @@ func (s *productService) UpdateById(req *model.UpdateProductReq) (err error) {
 	return
 }
 
+// UpdateState 修改数据
+func (s *productService) UpdateState(req *model.UpdateStateReq) (err error) {
+	_, err = s.Dao.WherePri(req.Id).Update(fmt.Sprintf("state='%v'", req.State))
+	if err != nil {
+		g.Log().Error(err)
+		return
+	}
+	return
+}
+
 // DeleteByIds 删掉数据
 func (s *productService) DeleteByIds(ids []int64) (err error) {
 	if len(ids) == 1 {