|
@@ -15,6 +15,7 @@ import (
|
|
|
"jyOrderManager/internal/model"
|
|
|
"log"
|
|
|
"math"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -85,6 +86,7 @@ func SaveDepositPayment(ctx context.Context, sDepositPayment model.SDepositPayme
|
|
|
var (
|
|
|
price, realPrice int64
|
|
|
orderArr = make(map[string]map[string]interface{})
|
|
|
+ depositId []string
|
|
|
)
|
|
|
for _, dl := range sDepositPayment.DepositList {
|
|
|
if dl.OrderCode == "" || dl.Money == 0 {
|
|
@@ -128,7 +130,7 @@ func SaveDepositPayment(ctx context.Context, sDepositPayment model.SDepositPayme
|
|
|
payMoney = gconv.Int64(value["realPrice"])
|
|
|
)
|
|
|
err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
- _, err := g.DB().Insert(ctx, model.DepositPaymentTable, g.Map{ //保证金支付信息
|
|
|
+ res, err := g.DB().Insert(ctx, model.DepositPaymentTable, g.Map{ //保证金支付信息
|
|
|
"order_code": key,
|
|
|
"pay_time": sDepositPayment.PayTime,
|
|
|
"pay_money": YuanToFen(payMoney),
|
|
@@ -149,70 +151,77 @@ func SaveDepositPayment(ctx context.Context, sDepositPayment model.SDepositPayme
|
|
|
if err != nil {
|
|
|
g.Log().Errorf(ctx, "新增保证金支付信息异常 %s", err.Error())
|
|
|
return errors.Wrap(err, "新增保证金支付信息异常")
|
|
|
- } else if realPrice == price { //保证金总金额 等于剩余需要回款的总金额
|
|
|
- //todo 1、是否需要关闭对应保证金的支付订单;2、保证金支付金额=合同金额 需要开通权限
|
|
|
- //是否需要开通权限 当前订单 保证金金额 == 剩余回款金额
|
|
|
- if payMoney == gconv.Int64(value["outstandingPayment"]) {
|
|
|
- productDetail, _ := g.DB().Ctx(ctx).Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_detail WHERE order_code ='%s' and returned_open =1 and is_service_open = 0 and status =1`, key)) //是否选中自动开通权限
|
|
|
- if !productDetail.IsEmpty() {
|
|
|
- var (
|
|
|
- uData map[string]interface{}
|
|
|
- entId, userPositionId int64
|
|
|
- )
|
|
|
- uData, entId, userPositionId, err = jyutil.GetCreateUserData(gconv.String(value["user_phone"]), gconv.String(value["company_name"]), gconv.Int(value["buy_subject"]) == 2)
|
|
|
- if err != nil {
|
|
|
- return errors.New("用户企业信息初始化失败")
|
|
|
- }
|
|
|
- if err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
- // 产品服务开通
|
|
|
- for _, m := range productDetail.List() {
|
|
|
- if !jyutil.IsServiceOpen(m) {
|
|
|
- continue
|
|
|
- }
|
|
|
- //参数注入
|
|
|
- m["userMap"] = map[string]interface{}{
|
|
|
- "userData": uData, "entId": entId, "userPositionId": userPositionId,
|
|
|
- }
|
|
|
- m["phone"] = value["user_phone"]
|
|
|
- m["order_code"] = key
|
|
|
- m["reqCompanyName"] = value["company_name"]
|
|
|
- m["amount"] = m["final_price"]
|
|
|
- m["reqSubject"] = value["buy_subject"]
|
|
|
- m["linked_orderId"] = m["linked_detail_id"]
|
|
|
- productCode := gconv.String(m["product_code"])
|
|
|
- pFunc, err4 := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
- if err4 != nil {
|
|
|
- return err4
|
|
|
- }
|
|
|
- pObj, err5 := pFunc(m)
|
|
|
- if err5 != nil {
|
|
|
- return gerror.Wrap(err5, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
- }
|
|
|
- if err = pObj.OpenService(ctx, time.Now()); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- if gconv.Int(value["buy_subject"]) == 2 {
|
|
|
- uData["userId"] = userPositionId
|
|
|
+ } else {
|
|
|
+ var insertId int64
|
|
|
+ insertId, err = res.LastInsertId()
|
|
|
+ if err == nil && insertId > 0 {
|
|
|
+ depositId = append(depositId, fmt.Sprint(insertId))
|
|
|
+ }
|
|
|
+ if realPrice == price { //保证金总金额 等于剩余需要回款的总金额
|
|
|
+ //todo 1、是否需要关闭对应保证金的支付订单;2、保证金支付金额=合同金额 需要开通权限
|
|
|
+ //是否需要开通权限 当前订单 保证金金额 == 剩余回款金额
|
|
|
+ if payMoney == gconv.Int64(value["outstandingPayment"]) {
|
|
|
+ productDetail, _ := g.DB().Ctx(ctx).Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_detail WHERE order_code ='%s' and returned_open =1 and is_service_open = 0 and status =1`, key)) //是否选中自动开通权限
|
|
|
+ if !productDetail.IsEmpty() {
|
|
|
+ var (
|
|
|
+ uData map[string]interface{}
|
|
|
+ entId, userPositionId int64
|
|
|
+ )
|
|
|
+ uData, entId, userPositionId, err = jyutil.GetCreateUserData(gconv.String(value["user_phone"]), gconv.String(value["company_name"]), gconv.Int(value["buy_subject"]) == 2)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("用户企业信息初始化失败")
|
|
|
}
|
|
|
- if orderUserId := gconv.String(value["user_id"]); orderUserId == "" || orderUserId != gconv.String(uData["userId"]) || (gconv.Int(value["buy_subject"]) == 2 && gconv.Int64(value["ent_id"]) != entId) {
|
|
|
- log.Printf("同步更新订单用户身份:orderUserId:%s,userId:%v,entId:%d\n", orderUserId, uData["userId"], entId)
|
|
|
- upData := g.Map{
|
|
|
- "user_id": uData["userId"],
|
|
|
+ if err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
+ // 产品服务开通
|
|
|
+ for _, m := range productDetail.List() {
|
|
|
+ if !jyutil.IsServiceOpen(m) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //参数注入
|
|
|
+ m["userMap"] = map[string]interface{}{
|
|
|
+ "userData": uData, "entId": entId, "userPositionId": userPositionId,
|
|
|
+ }
|
|
|
+ m["phone"] = value["user_phone"]
|
|
|
+ m["order_code"] = key
|
|
|
+ m["reqCompanyName"] = value["company_name"]
|
|
|
+ m["amount"] = m["final_price"]
|
|
|
+ m["reqSubject"] = value["buy_subject"]
|
|
|
+ m["linked_orderId"] = m["linked_detail_id"]
|
|
|
+ productCode := gconv.String(m["product_code"])
|
|
|
+ pFunc, err4 := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
+ if err4 != nil {
|
|
|
+ return err4
|
|
|
+ }
|
|
|
+ pObj, err5 := pFunc(m)
|
|
|
+ if err5 != nil {
|
|
|
+ return gerror.Wrap(err5, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
+ }
|
|
|
+ if err = pObj.OpenService(ctx, time.Now()); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if gconv.Int(value["buy_subject"]) == 2 {
|
|
|
+ uData["userId"] = userPositionId
|
|
|
}
|
|
|
- if entId > 0 { //企业服务
|
|
|
- upData["ent_id"] = entId
|
|
|
- if personPhone := gconv.String(value["personPhone"]); personPhone != "" {
|
|
|
- jyutil.EndAddUser(ctx, entId, gconv.String(value["user_phone"]), personPhone, gconv.String(value["personName"]))
|
|
|
+ if orderUserId := gconv.String(value["user_id"]); orderUserId == "" || orderUserId != gconv.String(uData["userId"]) || (gconv.Int(value["buy_subject"]) == 2 && gconv.Int64(value["ent_id"]) != entId) {
|
|
|
+ log.Printf("同步更新订单用户身份:orderUserId:%s,userId:%v,entId:%d\n", orderUserId, uData["userId"], entId)
|
|
|
+ upData := g.Map{
|
|
|
+ "user_id": uData["userId"],
|
|
|
+ }
|
|
|
+ if entId > 0 { //企业服务
|
|
|
+ upData["ent_id"] = entId
|
|
|
+ if personPhone := gconv.String(value["personPhone"]); personPhone != "" {
|
|
|
+ jyutil.EndAddUser(ctx, entId, gconv.String(value["user_phone"]), personPhone, gconv.String(value["personName"]))
|
|
|
+ }
|
|
|
}
|
|
|
+ //更新订单
|
|
|
+ _, err = g.DB().Update(ctx, consts.OrderListTableName, upData, "order_code=?", key)
|
|
|
}
|
|
|
- //更新订单
|
|
|
- _, err = g.DB().Update(ctx, consts.OrderListTableName, upData, "order_code=?", key)
|
|
|
+ return err
|
|
|
+ }); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return err
|
|
|
}
|
|
|
- return err
|
|
|
- }); err != nil {
|
|
|
- log.Println(err)
|
|
|
- return err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -221,6 +230,20 @@ func SaveDepositPayment(ctx context.Context, sDepositPayment model.SDepositPayme
|
|
|
})
|
|
|
return err
|
|
|
}
|
|
|
+ //cbs回款流水
|
|
|
+ //查询回款流水记录
|
|
|
+ if sDepositPayment.FlowType == 0 {
|
|
|
+ //修改回款流水记
|
|
|
+ updateTransactionData := map[string]interface{}{
|
|
|
+ "deposit_id": strings.Join(depositId, ","),
|
|
|
+ "ISRELATION": 3,
|
|
|
+ }
|
|
|
+ _, err := g.DB("cbs").Ctx(ctx).Update(ctx, "transaction", updateTransactionData, map[string]interface{}{"id": transactionMap["id"]})
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|
|
|
|