|
@@ -45,6 +45,9 @@ func OperateOrderRedPunch(ctx context.Context, params model.OrderRedPunchParams)
|
|
|
"detail_id": param.Id,
|
|
|
"activity_code": param.ActiveCode,
|
|
|
}
|
|
|
+ if params.IsRefundCall { // 退款自动生成的红冲记录 操作人为 系统字段
|
|
|
+ insertData["createPerson"] = "系统自动"
|
|
|
+ }
|
|
|
if strings.Contains(params.RedType, "签约主体") {
|
|
|
if param.PayMoney == 0 {
|
|
|
param.PayMoney = common.IntAll(orderData.Map()["pay_money"])
|
|
@@ -149,72 +152,90 @@ func OperateOrderRedPunch(ctx context.Context, params model.OrderRedPunchParams)
|
|
|
if refund_money >= params.PayMoney {
|
|
|
updateData["refund_status"] = 1
|
|
|
}
|
|
|
- if return_money >= params.PayMoney {
|
|
|
- updateData["return_status"] = 1
|
|
|
- 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`, params.OrderCode))
|
|
|
- if !productDetail.IsEmpty() {
|
|
|
- uData, entId, userPositionId, err := jyutil.GetCreateUserData(gconv.String(orderData.Map()["user_phone"]), gconv.String(orderData.Map()["company_name"]), gconv.Int(orderData.Map()["buy_subject"]) == 2)
|
|
|
- if err != nil {
|
|
|
- return errors.New("用户创建失败")
|
|
|
+ // 定金=支付金额 开通权限 修改状态
|
|
|
+ // 如果不是全额回款查询已支付保证金金额是否和订单金额相等 如果相等也展示权限开通按钮
|
|
|
+ var isDepositFullReturn bool
|
|
|
+ if has, err := HasDepositOperate(ctx, params.OrderCode); !has && err == nil { // 验证保证金是否已经有操作记录
|
|
|
+ if depositPayMoney, err := GetDepositPayMoney(ctx, params.OrderCode); depositPayMoney > 0 && err == nil { // 判断已支付保证金
|
|
|
+ if depositPayMoney == int64(params.PayMoney) {
|
|
|
+ isDepositFullReturn = true
|
|
|
}
|
|
|
- //全额回款开通权益
|
|
|
- if !consts.PhoneRegex.MatchString(gconv.String(orderData["user_phone"])) {
|
|
|
- return errors.New("手机号格式异常")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if return_money >= params.PayMoney || isDepositFullReturn {
|
|
|
+ updateData["return_status"] = 1
|
|
|
+ // 判断是否是退款调用 如果是退款调用生成红冲记录不要开权限 不改订单状态
|
|
|
+ if !params.IsRefundCall {
|
|
|
+ if isDepositFullReturn {
|
|
|
+ // 如果保证金金额==合同金额 更新订单状态为已完成
|
|
|
+ updateData["order_status"] = consts.OrderStatusFinished
|
|
|
}
|
|
|
- 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"] = orderData.Map()["user_phone"]
|
|
|
- m["order_code"] = params.OrderCode
|
|
|
- m["reqCompanyName"] = orderData.Map()["company_name"]
|
|
|
- m["amount"] = m["final_price"]
|
|
|
- m["reqSubject"] = orderData.Map()["buy_subject"]
|
|
|
- m["linked_orderId"] = m["linked_detail_id"]
|
|
|
- productCode := gconv.String(m["product_code"])
|
|
|
- pFunc, err := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- pObj, err := pFunc(m)
|
|
|
- if err != nil {
|
|
|
- return gerror.Wrap(err, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
- }
|
|
|
- if err := pObj.OpenService(ctx, time.Now()); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+ 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`, params.OrderCode))
|
|
|
+ if !productDetail.IsEmpty() {
|
|
|
+ uData, entId, userPositionId, err := jyutil.GetCreateUserData(gconv.String(orderData.Map()["user_phone"]), gconv.String(orderData.Map()["company_name"]), gconv.Int(orderData.Map()["buy_subject"]) == 2)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("用户创建失败")
|
|
|
}
|
|
|
- if gconv.Int(orderData.Map()["buy_subject"]) == 2 {
|
|
|
- uData["userId"] = userPositionId
|
|
|
+ //全额回款开通权益
|
|
|
+ if !consts.PhoneRegex.MatchString(gconv.String(orderData["user_phone"])) {
|
|
|
+ return errors.New("手机号格式异常")
|
|
|
}
|
|
|
- if orderUserId := gconv.String(orderData.Map()["user_id"]); orderUserId == "" || orderUserId != gconv.String(uData["userId"]) || (gconv.Int(orderData.Map()["buy_subject"]) == 2 && gconv.Int64(orderData.Map()["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(orderData.Map()["personPhone"]); personPhone != "" {
|
|
|
- jyutil.EndAddUser(ctx, entId, gconv.String(orderData.Map()["user_phone"]), personPhone, gconv.String(orderData.Map()["personName"]))
|
|
|
+ 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"] = orderData.Map()["user_phone"]
|
|
|
+ m["order_code"] = params.OrderCode
|
|
|
+ m["reqCompanyName"] = orderData.Map()["company_name"]
|
|
|
+ m["amount"] = m["final_price"]
|
|
|
+ m["reqSubject"] = orderData.Map()["buy_subject"]
|
|
|
+ m["linked_orderId"] = m["linked_detail_id"]
|
|
|
+ productCode := gconv.String(m["product_code"])
|
|
|
+ pFunc, err := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ pObj, err := pFunc(m)
|
|
|
+ if err != nil {
|
|
|
+ return gerror.Wrap(err, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
+ }
|
|
|
+ if err := pObj.OpenService(ctx, time.Now()); err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
}
|
|
|
- //更新订单
|
|
|
- _, err = g.DB().Update(ctx, consts.OrderListTableName, upData, "order_code=?", params.OrderCode)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ if gconv.Int(orderData.Map()["buy_subject"]) == 2 {
|
|
|
+ uData["userId"] = userPositionId
|
|
|
+ }
|
|
|
+ if orderUserId := gconv.String(orderData.Map()["user_id"]); orderUserId == "" || orderUserId != gconv.String(uData["userId"]) || (gconv.Int(orderData.Map()["buy_subject"]) == 2 && gconv.Int64(orderData.Map()["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(orderData.Map()["personPhone"]); personPhone != "" {
|
|
|
+ jyutil.EndAddUser(ctx, entId, gconv.String(orderData.Map()["user_phone"]), personPhone, gconv.String(orderData.Map()["personName"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新订单
|
|
|
+ _, err = g.DB().Update(ctx, consts.OrderListTableName, upData, "order_code=?", params.OrderCode)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return nil
|
|
|
- }); err != nil {
|
|
|
- log.Println(err)
|
|
|
- return err
|
|
|
+ return nil
|
|
|
+ }); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|