|
@@ -11,6 +11,7 @@ import (
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
"github.com/pkg/errors"
|
|
|
+ "jyOrderManager/internal/jyutil"
|
|
|
"jyOrderManager/internal/logic/order"
|
|
|
"jyOrderManager/internal/logic/product"
|
|
|
"jyOrderManager/internal/model"
|
|
@@ -30,7 +31,8 @@ var checkOrderProduct = func(ctx context.Context, orderCode string, param model.
|
|
|
}
|
|
|
|
|
|
if update { //待审核和已完成订单禁止修改
|
|
|
- orderDetailRes, err := g.DB().Query(ctx, "SELECT id FROM jy_order_detail WHERE order_code=?", param.OrderCode)
|
|
|
+ var orderDetailRes gdb.Result
|
|
|
+ orderDetailRes, err = g.DB().Query(ctx, "SELECT id FROM jy_order_detail WHERE order_code=?", param.OrderCode)
|
|
|
if err != nil || orderDetailRes.IsEmpty() {
|
|
|
err = gerror.Wrapf(err, "为查询到订单明细")
|
|
|
return
|
|
@@ -63,13 +65,14 @@ var checkOrderProduct = func(ctx context.Context, orderCode string, param model.
|
|
|
tParam["reqBuySet"] = param.BuySubject //购买主体
|
|
|
tParam["reqCompanyName"] = param.CompanyName //公司名称
|
|
|
productCode := gconv.String(tParam["product_code"])
|
|
|
- pFunc, err := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
- if err != nil {
|
|
|
+ pFunc, pErr := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
+ if pErr != nil {
|
|
|
+ err = gerror.Wrapf(pErr, "获取商品异常")
|
|
|
return
|
|
|
}
|
|
|
- pObj, err := pFunc(tParam)
|
|
|
- if err != nil {
|
|
|
- err = gerror.Wrap(err, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
+ pObj, pErr := pFunc(tParam)
|
|
|
+ if pErr != nil {
|
|
|
+ err = gerror.Wrap(pErr, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -84,7 +87,7 @@ var checkOrderProduct = func(ctx context.Context, orderCode string, param model.
|
|
|
actProduct[actCode] = map[string]product.JyProduct{productCode: pObj}
|
|
|
}
|
|
|
}
|
|
|
- if err = pObj.Check(checkCode); err != nil {
|
|
|
+ if err = pObj.Check(ctx, checkCode); err != nil {
|
|
|
return
|
|
|
}
|
|
|
productArr = append(productArr, pObj)
|
|
@@ -99,6 +102,11 @@ var checkOrderProduct = func(ctx context.Context, orderCode string, param model.
|
|
|
now := time.Now()
|
|
|
for actCode, productList := range actProduct {
|
|
|
act := service.Product().GetActivityByCode(actCode)
|
|
|
+ //当前用户是否有权限
|
|
|
+ if !service.Product().PowerCheck(act.Code, jyutil.GetUserDeptIdFromCtx(ctx)) {
|
|
|
+ err = fmt.Errorf("没有创建%s活动的权限", act.Name)
|
|
|
+ return
|
|
|
+ }
|
|
|
if act == nil {
|
|
|
err = fmt.Errorf("未知活动code %s", actCode)
|
|
|
return
|
|
@@ -124,7 +132,12 @@ var checkOrderProduct = func(ctx context.Context, orderCode string, param model.
|
|
|
// SaveOrderHandler 创建订单
|
|
|
func SaveOrderHandler(r *ghttp.Request) {
|
|
|
rData, err := func() (interface{}, error) {
|
|
|
- var param model.OrderParams
|
|
|
+ var (
|
|
|
+ param model.OrderParams
|
|
|
+ userName = r.Session.MustGet("entUserName", "").String()
|
|
|
+ entUserId = r.Session.MustGet("entUserId", "").Int64()
|
|
|
+ ctx = r.Context()
|
|
|
+ )
|
|
|
err := gconv.Struct(r.GetBody(), ¶m)
|
|
|
if err != nil {
|
|
|
return nil, gerror.Wrapf(err, "数据校验异常")
|
|
@@ -134,17 +147,14 @@ func SaveOrderHandler(r *ghttp.Request) {
|
|
|
orderCode = fmt.Sprintf("%s%s", time.Now().Format("150405"), common.GetRandom(6))
|
|
|
)
|
|
|
//产品参数校验
|
|
|
- productArr, _, err = checkOrderProduct(r.Context(), orderCode, param)
|
|
|
+
|
|
|
+ productArr, _, err = checkOrderProduct(ctx, orderCode, param)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//数据库操作
|
|
|
- if err := g.DB().Transaction(r.Context(), func(ctx context.Context, tx gdb.TX) error {
|
|
|
- var (
|
|
|
- userName = r.Session.MustGet("entUserName", "").String()
|
|
|
- entUserId = r.Session.MustGet("entUserId", "").Int64()
|
|
|
- )
|
|
|
+ if err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
//todo 插入订单表
|
|
|
if _, err := g.DB().Ctx(ctx).Insert(ctx, "dataexport_order", g.Map{
|
|
|
"order_code": orderCode,
|
|
@@ -181,11 +191,11 @@ func SaveOrderHandler(r *ghttp.Request) {
|
|
|
return gerror.Wrapf(err, "销售业绩异常")
|
|
|
}
|
|
|
//todo 合同
|
|
|
- if err := order.SaveOrUpdateContract(r.Context(), param.OrderCode, param.CompanyName, param.ContractMoney, param.Contract); err != nil {
|
|
|
+ if err := order.SaveOrUpdateContract(ctx, param.OrderCode, param.CompanyName, param.ContractMoney, param.Contract); err != nil {
|
|
|
return gerror.Wrapf(err, "合同异常")
|
|
|
}
|
|
|
//回款计划
|
|
|
- if err := order.SaveOrUpdateReturnPlant(r.Context(), param.OrderRemark, param.ContractMoney, param.ReturnPlant); err != nil {
|
|
|
+ if err := order.SaveOrUpdateReturnPlant(ctx, param.OrderRemark, param.ContractMoney, param.ReturnPlant); err != nil {
|
|
|
return gerror.Wrapf(err, "回款计划异常")
|
|
|
}
|
|
|
return nil
|
|
@@ -203,27 +213,28 @@ func SaveOrderHandler(r *ghttp.Request) {
|
|
|
// UpdateOrderHandler 订单修改
|
|
|
func UpdateOrderHandler(r *ghttp.Request) {
|
|
|
rData, err := func() (interface{}, error) {
|
|
|
- var param model.OrderParams
|
|
|
+ var (
|
|
|
+ param model.OrderParams
|
|
|
+ userName = r.Session.MustGet("entUserName", "").String()
|
|
|
+ entUserId = r.Session.MustGet("entUserId", "").Int64()
|
|
|
+ ctx = r.Context()
|
|
|
+ )
|
|
|
err := gconv.Struct(r.GetBody(), ¶m)
|
|
|
if err != nil {
|
|
|
return nil, gerror.Wrapf(err, "数据校验异常")
|
|
|
}
|
|
|
- orderRes, err := g.DB().GetOne(r.Context(), "SELECT * FROM dataexport_order WHERE order_code=?", param.OrderCode)
|
|
|
+ orderRes, err := g.DB().GetOne(ctx, "SELECT * FROM dataexport_order WHERE order_code=?", param.OrderCode)
|
|
|
if err != nil || orderRes.IsEmpty() {
|
|
|
err = gerror.Wrapf(err, "未知订单")
|
|
|
return nil, err
|
|
|
}
|
|
|
//产品参数校验
|
|
|
- productArr, removeIds, err := checkOrderProduct(r.Context(), param.OrderCode, param, orderRes.Map())
|
|
|
+ productArr, removeIds, err := checkOrderProduct(ctx, param.OrderCode, param, orderRes.Map())
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
//数据库操作
|
|
|
- if err := g.DB().Transaction(r.Context(), func(ctx context.Context, tx gdb.TX) error {
|
|
|
- var (
|
|
|
- userName = r.Session.MustGet("entUserName", "").String()
|
|
|
- entUserId = r.Session.MustGet("entUserId", "").Int64()
|
|
|
- )
|
|
|
+ if err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
if _, err := g.DB().Ctx(ctx).Update(ctx, "dataexport_order", g.Map{
|
|
|
"order_money": param.OrderMoney,
|
|
|
"pay_money": param.ContractMoney,
|
|
@@ -269,11 +280,11 @@ func UpdateOrderHandler(r *ghttp.Request) {
|
|
|
}
|
|
|
}
|
|
|
//todo 合同
|
|
|
- if err := order.SaveOrUpdateContract(r.Context(), param.OrderCode, param.CompanyName, param.ContractMoney, param.Contract); err != nil {
|
|
|
+ if err := order.SaveOrUpdateContract(ctx, param.OrderCode, param.CompanyName, param.ContractMoney, param.Contract); err != nil {
|
|
|
return gerror.Wrapf(err, "合同异常")
|
|
|
}
|
|
|
//todo 回款计划
|
|
|
- if err := order.SaveOrUpdateReturnPlant(r.Context(), param.OrderRemark, param.ContractMoney, param.ReturnPlant); err != nil {
|
|
|
+ if err := order.SaveOrUpdateReturnPlant(ctx, param.OrderRemark, param.ContractMoney, param.ReturnPlant); err != nil {
|
|
|
return gerror.Wrapf(err, "回款计划异常")
|
|
|
}
|
|
|
return nil
|