fix
This commit is contained in:
@@ -52,7 +52,7 @@ type OrderCreate struct {
|
||||
|
||||
type OrderInfo struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
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"`
|
||||
@@ -75,6 +75,7 @@ type OrderInfo struct {
|
||||
OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);comment:支付订单号" json:"out_trade_no"`
|
||||
OldAddress string `gorm:"column:old_address;type:varchar(255);comment:老的收发货信息,如果有这个就表明是修改过收货地址" json:"old_address"`
|
||||
Type uint8 `gorm:"column:type;type:tinyint(1);default:0;comment:类型 1 销售,2为门店,3为个人,4为个人家庭试用,5为个人门店试用" json:"type"`
|
||||
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"`
|
||||
SignTime utils.CustomTime `gorm:"column:sign_time;type:datetime;comment:签收时间" json:"sign_time"`
|
||||
CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型,1为销售,2为门店,3为个人;NOT NULL" json:"create_type"`
|
||||
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP;comment:订单创建时间" json:"create_time"`
|
||||
@@ -87,7 +88,7 @@ type OrderInfo struct {
|
||||
type OrderPay struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
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"`
|
||||
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
|
||||
@@ -101,7 +102,7 @@ type OrderPay struct {
|
||||
|
||||
type OrderDown struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
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"`
|
||||
@@ -128,7 +129,7 @@ type OrderDown struct {
|
||||
|
||||
type OrderSaleItems struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
|
||||
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
|
||||
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
|
||||
@@ -140,7 +141,7 @@ type OrderSaleItems struct {
|
||||
|
||||
type OrderAccount struct {
|
||||
Id int `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
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"`
|
||||
UserId int `gorm:"column:user_id;type:int(11);comment:用户ID" json:"user_id"`
|
||||
SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"`
|
||||
@@ -172,7 +173,7 @@ type OrderDeliverGoodsStatus struct {
|
||||
|
||||
type OrderImitateInfo struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
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"`
|
||||
@@ -192,7 +193,7 @@ type OrderImitateItems struct {
|
||||
|
||||
type OrderDownInfo struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
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"`
|
||||
@@ -224,3 +225,11 @@ 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"` // 操作人姓名
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error)
|
||||
}
|
||||
|
||||
w.Like = make(map[string]string)
|
||||
w.Eq = make(map[string]string)
|
||||
w.Other = make(map[string]string)
|
||||
w.Eq = make(map[string]string)
|
||||
if in.ProductId > utils.NumberZero {
|
||||
w.Other["FIND_IN_SET(?, product_ids)"] = strconv.FormatInt(in.ProductId, utils.NumberTen)
|
||||
}
|
||||
@@ -86,8 +86,19 @@ func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error)
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
var ids []string
|
||||
for _, v := range info {
|
||||
l.Logger.Error("order_sn:", v.OrderSn)
|
||||
ids = append(ids, v.OrderSn)
|
||||
}
|
||||
l.Logger.Error("ids:", ids)
|
||||
l.Logger.Error(len(ids), utils.NumberOne)
|
||||
var productItems []dao.OrderProducts
|
||||
err = model.OrderProductModel{}.Init().Items(w, &productItems)
|
||||
ww := modelbase.Params{
|
||||
In: map[string][]string{"order_sn": ids},
|
||||
}
|
||||
err = model.OrderProductModel{}.Init().Items(ww, &productItems)
|
||||
if err != nil {
|
||||
utils.Logger.Error("product err:", err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
|
||||
@@ -64,8 +64,21 @@ func (l *OrderAuditingItemsLogic) OrderAuditingItems(in *order.OrderAuditingItem
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
var ids []string
|
||||
for _, v := range info {
|
||||
ids = append(ids, v.OrderSn)
|
||||
}
|
||||
|
||||
if len(ids) < utils.NumberOne {
|
||||
return l.ok(items)
|
||||
}
|
||||
|
||||
var productItems []dao.OrderProducts
|
||||
err = model.OrderProductModel{}.Init().Items(w, &productItems)
|
||||
ww := modelbase.Params{
|
||||
In: map[string][]string{"order_sn": ids},
|
||||
}
|
||||
err = model.OrderProductModel{}.Init().Items(ww, &productItems)
|
||||
if err != nil {
|
||||
utils.Logger.Error("product err:", err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
|
||||
@@ -2,6 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/validator"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
@@ -25,7 +31,42 @@ func NewOrderAuditingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ord
|
||||
}
|
||||
|
||||
func (l *OrderAuditingLogic) OrderAuditing(in *order.OrderAuditingRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &order.Response{}, nil
|
||||
var v validator.AdminOrderAuditingValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
var action = utils.ActionAdd{}
|
||||
var info dao.OrderAuditing
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
modelObj := model.OrderModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.OldContent = info
|
||||
info.VerifyStatus = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Reason = in.Reason
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleOrder
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,13 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/validator"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
@@ -25,7 +32,133 @@ func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Order
|
||||
}
|
||||
|
||||
func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.AdminOrderCreateValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
return &order.Response{}, nil
|
||||
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),
|
||||
},
|
||||
}
|
||||
var address dao.Address
|
||||
err := model.AddressModel{}.Init().GetOne(w, &address)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if address.Id < utils.NumberOne {
|
||||
return l.out(utils.Fail, "地址不存在")
|
||||
}
|
||||
|
||||
data := dao.OrderCreate{
|
||||
Note: in.Note,
|
||||
Mobile: address.Mobile,
|
||||
VerifyStatus: model.VerifyCheckIn,
|
||||
Address: address.Address,
|
||||
Addressee: address.Name,
|
||||
DistrictIds: address.DistrictIds,
|
||||
}
|
||||
|
||||
ww := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"type": strconv.Itoa(dao.OrderTypeStore),
|
||||
},
|
||||
}
|
||||
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
|
||||
ww.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
data.OrderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID)
|
||||
|
||||
var cart dao.Cart
|
||||
|
||||
ids, pErr := svc.GetCartInfo(in.Info)
|
||||
if pErr != utils.Ok {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
products, pErr := svc.GetCartData(l.svcCtx.ProductSvcName, ids)
|
||||
if pErr != utils.Ok {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
keys := make([]string, utils.NumberZero, len(products.Items))
|
||||
var totalPrice float64
|
||||
errData := make(map[int64]int64)
|
||||
productItems := []dao.OrderProductCreate{}
|
||||
for _, item := range products.Items {
|
||||
if buyNum, ok := ids[item.Id]; ok {
|
||||
if buyNum > int64(item.Number) {
|
||||
errData[item.Id] = int64(item.Number)
|
||||
return l.out(utils.Fail,
|
||||
item.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(item.Number)))
|
||||
} else {
|
||||
keys = append(keys, strconv.Itoa(int(item.Id)))
|
||||
totalPrice += item.Price * float64(buyNum)
|
||||
productItems = append(productItems, dao.OrderProductCreate{
|
||||
OrderSn: data.OrderSn,
|
||||
ProductId: int(item.Id),
|
||||
ProductName: item.Name,
|
||||
Price: item.Price,
|
||||
Number: int(buyNum),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(keys) < utils.NumberOne {
|
||||
return l.out(utils.Fail, "购买信息不存在")
|
||||
}
|
||||
data.ProductIds = strings.Join(keys, utils.DecollatorComma)
|
||||
data.TotalPrice = totalPrice
|
||||
mobileObj := model.OrderModel{}.Init()
|
||||
|
||||
mobileObj.Begin()
|
||||
err = mobileObj.Create(&data)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
for _, item := range productItems {
|
||||
err = model.OrderProductModel{}.Init().Create(&item)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = model.CartModel{}.Init().Del(ww, &cart)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
//TODO 扣库存接口
|
||||
//cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
|
||||
//if err != nil {
|
||||
// mobileObj.Rollback()
|
||||
// return l.fail(utils.Fail)
|
||||
//}
|
||||
|
||||
//productClient := product.NewProductClient(cli.Conn())
|
||||
//_, err = productClient.Number(l.ctx, &product.NumberReq{Id: item.Id, Type: utils.NumberOne, Number: buyNum})
|
||||
//if err != nil {
|
||||
// mobileObj.Rollback()
|
||||
// logx.Errorf("get products err: %v", err)
|
||||
// return l.fail(utils.Fail, "产品库存不足")
|
||||
//}
|
||||
|
||||
mobileObj.Commit()
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,25 @@ import (
|
||||
"lone-services/services/order/internal/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
PayStatusOk = 1 //1为已支付
|
||||
PayStatusNo = 2 //2为未支付
|
||||
PayStatusIn = 3 //为支付中
|
||||
PayStatusFail = 4 //4支付失败,5已失效
|
||||
PayStatusCancel = 5 //5已失效
|
||||
|
||||
AccountOrderStatusOk = 1 //已结算
|
||||
AccountOrderStatusNo = 2 //未结算
|
||||
|
||||
AccountShareStatusOk = 1 //已结算
|
||||
AccountShareStatusNo = 2 //未结算
|
||||
|
||||
VerifyOk = 1 //通过
|
||||
VerifyRefuse = 2 //拒绝
|
||||
VerifyCheckIn = 3 //一审中
|
||||
VerifySecondCheckIn = 4 //二审中
|
||||
)
|
||||
|
||||
type OrderModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user