new create admin order,express add company

This commit is contained in:
2026-09-02 18:02:57 +08:00
parent 02819d159a
commit e0a63bbef9
38 changed files with 3023 additions and 265 deletions
+49 -34
View File
@@ -15,39 +15,58 @@ const (
OrderPayStatusFail = 4 //支付失败
OrderPayStatusLose = 5 //已失效
OrderDeliverTypeSend = 1 //需要发货
OrderDeliverTypeNotSend = 2 //不需要发货
OrderTypeSale = 1 //销售
OrderTypeStore = 2 //为门店
OrderTypePersonal = 3 //为个人
OrderTypeHome = 4 //为个人家庭试用
DeliverTypeOrder = 1 //订单
DeliverTypeSupply = 3 //补货
SendStatusOver = 1 //为已签收
SendStatusWait = 2 //为待发货
SendStatusIn = 3 //为发货中
SendStatusOk = 4 //为已发货
SendStatusCancel = 5 //已取消
OrderVerifyStatusOK = 1
OrderVerifyStatusFail = 2
OrderVerifyStatusWait = 3
)
type OrderCreate struct {
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
StoreId int `gorm:"column:store_id;type:int(11);comment:美容院关联ID号" json:"store_id"`
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
SaleName string `gorm:"column:sale_name;type:varchar(50);comment:销售姓名" json:"sale_name"`
SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"`
SaleProvince int `gorm:"column:sale_province;type:int(11);default:0;comment:销售到的地域" json:"sale_province"`
UserId int `gorm:"column:user_id;type:int(11);comment:用户ID" json:"user_id"`
UserName string `gorm:"column:user_name;type:varchar(255);comment:用户名" json:"user_name"`
SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"`
Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"`
Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"`
Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"`
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
GroupId int `gorm:"column:group_id;type:int(11);default:0" json:"group_id"`
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
IsSupply uint8 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"`
Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"`
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"`
ExpiredTime utils.CustomTime `json:"expired_time" gorm:"expired_time"` // 过期时间
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型1为销售2为门店3为个人;NOT NULL" json:"create_type"`
Type uint8 `gorm:"column:type;type:tinyint(1);default:0;comment:类型 1 销售,2为门店,3为个人,4为个人家庭试用,5为个人门店试用" json:"type"`
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
StoreId int `gorm:"column:store_id;type:int(11);comment:美容院关联ID号" json:"store_id"`
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
SaleName string `gorm:"column:sale_name;type:varchar(50);comment:销售姓名" json:"sale_name"`
SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"`
SaleProvince int `gorm:"column:sale_province;type:int(11);default:0;comment:销售到的地域" json:"sale_province"`
UserId int `gorm:"column:user_id;type:int(11);comment:用户ID" json:"user_id"`
UserName string `gorm:"column:user_name;type:varchar(255);comment:用户名" json:"user_name"`
SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"`
Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"`
Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"`
Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"`
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
GroupId int `gorm:"column:group_id;type:int(11);default:0" json:"group_id"`
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
IsSupply uint8 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"`
Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"`
DeliverStatus uint8 `json:"deliver_status" gorm:"deliver_status"` // 发货状态,1为已签收,2为待发货,3为发货中,4为已发货
DeliverType uint8 `json:"deliver_type" gorm:"deliver_type"` // 发货类型,1为需要发货,2为不需要发货
SignTime utils.CustomTime `json:"sign_time" gorm:"sign_time"` // 签收时间
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态1为通过2为失败3为待审核,0为正常订单不需要审核" json:"verify_status"`
ExpiredTime utils.CustomTime `json:"expired_time" gorm:"expired_time"` // 过期时间
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型,1为销售,2为门店,3为个人;NOT NULL" json:"create_type"`
Type uint8 `gorm:"column:type;type:tinyint(1);default:0;comment:类型 1 销售,2为门店,3为个人,4为个人家庭试用,5为个人门店试用" json:"type"`
}
type OrderInfo struct {
@@ -180,9 +199,13 @@ type OrderImitateInfo struct {
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"`
DeliverStatus uint8 `gorm:"column:deliver_status;type:tinyint(1);default:2;comment:发货状态,1为已签收,2为待发货,3为发货中,4为已发货" json:"deliver_status"`
DeliverType uint8 `json:"deliver_type" gorm:"deliver_type"` // 发货类型,1为需要发货,2为不需要发货
Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"`
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
Reason string `json:"reason" gorm:"reason"` // 原因
AdminId int64 `json:"admin_id" gorm:"admin_id"` // 操作人ID
AdminName string `json:"admin_name" gorm:"admin_name"` // 操作人姓名
}
type OrderImitateItems struct {
@@ -225,11 +248,3 @@ type OrderTaskAndAwardHalfYear struct {
type OrderTaskAndAwardYear struct {
TaskAwardYearStatus uint8 `gorm:"column:task_award_year_status;type:tinyint(1);default:2;comment:结算任务与奖励年,1 为已结算,2为未结算" json:"task_awark_year_status"`
}
type OrderAuditing struct {
Id int64 `json:"id" gorm:"id"` // ID
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"`
Reason string `json:"reason" gorm:"reason"` // 原因
AdminId int64 `json:"admin_id" gorm:"admin_id"` // 操作人ID
AdminName string `json:"admin_name" gorm:"admin_name"` // 操作人姓名
}
+1 -1
View File
@@ -16,7 +16,7 @@ type OrderProductCreate struct {
type OrderProductInfo struct {
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
ProductId int `gorm:"column:product_id;type:int(11);comment:产品ID;NOT NULL" json:"product_id"`
ProductId int64 `gorm:"column:product_id;type:int(11);comment:产品ID;NOT NULL" json:"product_id"`
ProductName string `gorm:"column:product_name;type:varchar(255);comment:产品名;NOT NULL" json:"product_name"`
Price float64 `gorm:"column:price;type:decimal(10,2);comment:产品单价格;NOT NULL" json:"price"`
Number int `gorm:"column:number;type:int(11);default:0;comment:购买的数量;NOT NULL" json:"number"`
@@ -4,13 +4,16 @@ import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
chore "lone-services/rpc/chore/pb"
express "lone-services/rpc/express/pb"
"lone-services/rpc/order/pb"
product "lone-services/rpc/product/pb"
"lone-services/services/order/internal/dao"
"lone-services/services/order/internal/model"
"lone-services/services/order/internal/svc"
"lone-services/services/order/validator"
"strconv"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -40,7 +43,7 @@ func (l *OrderAuditingLogic) OrderAuditing(in *order.OrderAuditingRequest) (*ord
return l.fail(utils.ErrorNoLoginInfo)
}
var action = utils.ActionAdd{}
var info dao.OrderAuditing
var info dao.OrderImitateInfo
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
modelObj := model.OrderModel{}.Init()
err := modelObj.GetOne(w, &info)
@@ -51,22 +54,184 @@ func (l *OrderAuditingLogic) OrderAuditing(in *order.OrderAuditingRequest) (*ord
if info.Id < utils.NumberOne {
return l.fail(utils.ErrorNotFund)
}
if info.VerifyStatus != dao.OrderVerifyStatusWait {
return l.fail(utils.ErrorVerifyReview)
}
action.OldContent = info
info.VerifyStatus = uint8(in.Status)
info.Reason = in.Reason
info.AdminName = adminInfo.Name
info.AdminId = adminInfo.ID
modelObj.Begin()
row, editErr := modelObj.Edit(w, info)
if editErr != nil {
modelObj.Rollback()
l.Logger.Error(editErr)
return l.fail(utils.Fail)
}
if in.Status == utils.StatusOk {
deliverGoods, status := l.getDeliveryInfo(info)
if status != utils.Ok {
modelObj.Rollback()
return l.fail(status)
}
status = l.setDeliverGoods(deliverGoods)
if status != utils.Ok {
modelObj.Rollback()
return l.fail(status)
}
} else {
status := l.recover(info.OrderSn)
if status != utils.Ok {
modelObj.Rollback()
return l.fail(status)
}
}
modelObj.Commit()
if row > utils.NumberZero {
action.NewContent = info
action.Reason = in.Reason
action.Type = utils.LogActionTypeStatus
action.ModuleName = utils.LogActionModuleOrder
l.Logger.Error("set action log", action)
utils.SetActionLog(adminInfo, action)
}
return l.ok(utils.NumberOne)
}
func (l *OrderAuditingLogic) getDeliveryInfo(info dao.OrderImitateInfo) (express.DeliveryOrderCreateRequest, utils.Status) {
deliverGoods := express.DeliveryOrderCreateRequest{
ObjId: strconv.FormatInt(info.Id, utils.NumberTen),
Mobile: info.Mobile,
Address: info.Address,
Addressee: info.Addressee,
ObjSn: info.OrderSn,
Type: dao.DeliverTypeOrder,
Status: dao.SendStatusWait,
}
if info.DeliverType == dao.OrderDeliverTypeSend {
deliverGoods.Status = dao.SendStatusOver
}
w := modelbase.Params{Eq: map[string]string{"order_sn": info.OrderSn}}
var orderProducts []dao.OrderProductInfo
err := model.OrderProductModel{}.Init().Items(w, &orderProducts)
if err != nil || len(orderProducts) < utils.NumberOne {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorNotFund
}
var productIds []int64
idsNumber := make(map[int64]int)
for _, item := range orderProducts {
productIds = append(productIds, item.ProductId)
idsNumber[item.ProductId] = item.Number
}
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
if err != nil {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
productClient := product.NewProductClient(cli.Conn())
productItems, err := productClient.ItemsByIds(l.ctx, &product.ItemsByIdsReq{Ids: productIds})
if err != nil {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
for _, item := range productItems.Items {
number := utils.NumberZero
if _, ok := idsNumber[item.Id]; ok {
number = idsNumber[item.Id]
}
deliverGoods.ProductInfo = append(deliverGoods.ProductInfo, &express.DeliverOrderProductInfo{
ProductId: item.Id,
Number: int32(number),
Type: int32(item.Type),
ProductName: item.Name,
Price: item.Price,
})
}
clic, err := svc.GetRpcClient(l.svcCtx.ChoreSvcName)
if err != nil {
logx.Errorf("get region err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
var regionIds []int64
for _, item := range strings.Split(info.DistrictIds, utils.DecollatorComma) {
id, _ := strconv.Atoi(item)
regionIds = append(regionIds, int64(id))
}
clicClient := chore.NewChoreClient(clic.Conn())
regionItems, err := clicClient.RegionsByIds(l.ctx, &chore.RegionsByIdsReq{Ids: regionIds})
if err != nil {
logx.Errorf("get region err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
switch len(regionItems.Items) {
case utils.NumberOne:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
case utils.NumberTwo:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
deliverGoods.City = regionItems.Items[utils.NumberOne].Name
case utils.NumberThree:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
deliverGoods.City = regionItems.Items[utils.NumberOne].Name
deliverGoods.County = regionItems.Items[utils.NumberTwo].Name
}
return deliverGoods, utils.Ok
}
func (l *OrderAuditingLogic) setDeliverGoods(data express.DeliveryOrderCreateRequest) utils.Status {
cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName)
if err != nil {
return utils.ErrorInternalServer
}
client := express.NewExpressClient(cli.Conn())
_, err = client.DeliveryOrderCreate(l.ctx, &data)
if err != nil {
logx.Errorf("set products err: %v", err)
return utils.ErrorInternalServer
}
return utils.Ok
}
func (l *OrderAuditingLogic) recover(orderSn string) utils.Status {
w := modelbase.Params{Eq: map[string]string{"order_sn": orderSn}}
var orderProducts []dao.OrderProductInfo
err := model.OrderProductModel{}.Init().Items(w, &orderProducts)
if err != nil || len(orderProducts) < utils.NumberOne {
logx.Errorf("get products err: %v", err)
return utils.ErrorNotFund
}
var data product.NumberItemsReq
data.Type = utils.NumberTwo
for _, item := range orderProducts {
data.Items = append(data.Items, &product.NumberItem{Id: item.ProductId, Number: uint32(item.Number)})
}
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
if err != nil {
return utils.ErrorInternalServer
}
productClient := product.NewProductClient(cli.Conn())
_, err = productClient.NumberItems(l.ctx, &data)
if err != nil {
logx.Errorf("set products err: %v", err)
return utils.ErrorInternalServer
}
return utils.Ok
}
@@ -44,9 +44,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde
w := modelbase.Params{
Eq: map[string]string{
"id": strconv.FormatInt(in.AddressId, utils.NumberTen),
"type": strconv.Itoa(dao.OrderTypeStore),
"target_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
"id": strconv.FormatInt(in.AddressId, utils.NumberTen),
"type": strconv.Itoa(dao.OrderTypeStore),
},
}
var address dao.Address
@@ -65,25 +64,18 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde
Address: address.Address,
Addressee: address.Name,
DistrictIds: address.DistrictIds,
DeliverType: dao.OrderDeliverTypeSend,
}
ww := modelbase.Params{
Eq: map[string]string{
"type": strconv.Itoa(dao.OrderTypeStore),
"store_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
},
if in.Type != dao.OrderDeliverTypeNotSend {
data.DeliverType = dao.OrderDeliverTypeNotSend
data.DeliverStatus = dao.SendStatusOver
data.SignTime = utils.Now()
}
data.StoreId = int(adminInfo.ID)
data.StoreName = adminInfo.Name
data.SaleId = int(adminInfo.SaleId)
data.GroupId = int(adminInfo.GroupId)
data.SaleMobile = adminInfo.SaleMobile
data.SaleProvince = int(adminInfo.SaleProvince)
data.CreateType = dao.OrderTypeStore
data.Type = dao.OrderTypeStore
data.OrderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID)
var cart dao.Cart
data.OrderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), address.TargetId)
ids, pErr := svc.GetCartInfo(in.Info)
if pErr != utils.Ok {
@@ -140,12 +132,6 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde
}
}
_, err = model.CartModel{}.Init().Del(ww, &cart)
if err != nil {
mobileObj.Rollback()
return l.fail(utils.Fail)
}
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
if err != nil {
mobileObj.Rollback()
@@ -196,7 +196,6 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
logx.Errorf("get products err: %v", err)
return l.out(utils.Fail, "产品库存不足")
}
mobileObj.Commit()
return l.ok(utils.NumberOne)
@@ -152,7 +152,6 @@ func (l *WebCreateOneLogic) WebCreateOne(in *order.CreateOrderOneRequest) (*orde
return l.out(utils.Fail,
productInfo.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(in.Num)))
}
mobileObj.Commit()
return l.ok(utils.NumberOne)
+15 -4
View File
@@ -74,26 +74,37 @@ func GetRpcClient(serviceName string) (zrpc.Client, error) {
}
type ServiceContext struct {
Config config.Config
DB *gorm.DB
Prefix string
Config config.Config
DB *gorm.DB
Prefix string
ProductSvcName string //服务名
ExpressSvcName string
ChoreSvcName string
}
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
//启动仅读取配置,不建立rpc连接 多个服务就多个
productSvc := utils.GetConfigString("services.product")
ExpressSvc := utils.GetConfigString("services.express")
ChoreSvc := utils.GetConfigString("services.chore")
if productSvc == utils.StringEmpty {
logx.Error("config services.product empty")
}
if ExpressSvc == utils.StringEmpty {
logx.Error("config services.express empty")
}
if ChoreSvc == utils.StringEmpty {
logx.Error("config services.chore empty")
}
svcCtx := &ServiceContext{
Config: c,
DB: db,
Prefix: utils.GetConfigString("mysql.prefix"),
ProductSvcName: productSvc,
ExpressSvcName: ExpressSvc,
ChoreSvcName: ChoreSvc,
}
return svcCtx