order.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package order
  2. import (
  3. "context"
  4. "jyOrderManager/internal/model"
  5. )
  6. // SaveOrder 订单保存
  7. func SaveOrder(ctx context.Context, param model.OrderParams, creatUser string) (string, error) {
  8. //var (
  9. // productArr []product.JyProduct
  10. // orderCode = fmt.Sprintf("%s%s", time.Now().Format("150405"), common.GetRandom(6))
  11. // actProduct = map[string]map[string]product.JyProduct{}
  12. //)
  13. //for _, tParam := range param.ProductArr {
  14. // //参数注入
  15. // tParam["phone"] = param.PersonPhone //开通手机号
  16. // tParam["order_code"] = orderCode //订单号
  17. // tParam["reqBuySet"] = param.BuySubject //购买主体
  18. // tParam["reqCompanyName"] = param.CompanyName //公司名称
  19. // productCode := gconv.String(tParam["product_code"])
  20. // pFunc, err := product.JyProFunc.GetProductInitFuncByCode(productCode)
  21. // if err != nil {
  22. // return "", err
  23. // }
  24. // pObj, err := pFunc(tParam)
  25. // if err != nil {
  26. // return "", gerror.Wrap(err, fmt.Sprintf("获取%s商品异常", productCode))
  27. // }
  28. //
  29. // var (
  30. // actCode = gconv.String(tParam["activityCode"]) //活动code
  31. // checkCode = common.If(actCode != "", 2, 1).(int) //1:普通商品 2:活动商品
  32. // )
  33. // if actCode != "" {
  34. // if _, ok := actProduct[actCode]; ok {
  35. // actProduct[actCode][productCode] = pObj
  36. // } else {
  37. // actProduct[actCode] = map[string]product.JyProduct{productCode: pObj}
  38. // }
  39. // }
  40. //
  41. // if err := pObj.Check(checkCode); err != nil {
  42. // return "", err
  43. // }
  44. //
  45. // productArr = append(productArr, pObj)
  46. //}
  47. //
  48. //// 活动商品校验完整,防止缺少增加商品
  49. //if len(actProduct) > 0 {
  50. // now := time.Now()
  51. // for actCode, productList := range actProduct {
  52. // act := service.Product().GetActivityByCode(actCode)
  53. // if act == nil {
  54. // return "", fmt.Errorf("未知活动code %s", actCode)
  55. // }
  56. // if now.After(act.EndTime) || now.Before(act.StartTime) {
  57. // return "", fmt.Errorf("活动%s不在有效期", actCode)
  58. // }
  59. // if len(productList) != len(act.Products) {
  60. // return "", fmt.Errorf("活动产品不完整 %s", actCode)
  61. // }
  62. // }
  63. //}
  64. //
  65. ////数据库操作
  66. //return orderCode, g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
  67. // //todo 插入订单表
  68. // if _, err := g.DB().Ctx(ctx).Insert(ctx, "dataexport_order", g.Map{
  69. // "order_code": orderCode,
  70. // "order_money": param.OrderMoney,
  71. // "pay_money": param.ContractMoney,
  72. // "product_type": "组合商品",
  73. // "create_person": "xxxx",
  74. // }); err != nil {
  75. // return gerror.Wrap(err, "插入订单表异常")
  76. // }
  77. // //todo 订单详情表
  78. // for _, p := range productArr {
  79. // if err := p.SaveUpdate(ctx); err != nil {
  80. // return err
  81. // }
  82. // }
  83. // //todo 销售业绩
  84. // SaveOrUpdateSaleMoneyTmp(ctx, orderCode)
  85. // return nil
  86. //})
  87. }