duxin 4 ay önce
ebeveyn
işleme
fb1ee9691c

+ 0 - 4
internal/controller/orderList.go

@@ -18,10 +18,6 @@ func OrderList(r *ghttp.Request) {
 		if err != nil {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
 		}
-		value, err := r.Session.Get("positionId")
-		if err != nil || value.Int() <= 0 {
-			return nil, errors.New("userid err")
-		}
 		list, err := order.List(r.Context(), param)
 		list, err := order.List(r.Context(), param)
 		if err != nil {
 		if err != nil {
 			return nil, errors.Wrap(err, "订单list异常")
 			return nil, errors.Wrap(err, "订单list异常")

+ 1 - 1
internal/logic/order/detail.go

@@ -26,7 +26,7 @@ func init() {
 func Detail(ctx context.Context, param model.OrderDetailParams) (map[string]interface{}, error) {
 func Detail(ctx context.Context, param model.OrderDetailParams) (map[string]interface{}, error) {
 	result := make(map[string]interface{})
 	result := make(map[string]interface{})
 	//订单 暂无备注字段
 	//订单 暂无备注字段
-	orderData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT order_code,buy_subject,user_nickname,user_phone,company_name,create_person,create_time,last_update_person,last_update_time,order_status,audit_status,pay_way,order_channel,payment_user,pay_money-(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode=%s and 'state'=1) as pay_money,order_money,return_status,refund_status,filter FROM  dataexport_order WHERE order_code =%s `, param.OrderCode, param.OrderCode))
+	orderData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT order_code,buy_subject,user_nickname,user_phone,company_name,create_person,create_time,last_update_person,last_update_time,order_status,audit_status,pay_way,order_channel,payment_user,pay_money+(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode=%s) as pay_money,order_money,return_status,refund_status,filter FROM  dataexport_order WHERE order_code =%s `, param.OrderCode, param.OrderCode))
 	if err != nil || orderData.IsEmpty() {
 	if err != nil || orderData.IsEmpty() {
 		return nil, err
 		return nil, err
 	}
 	}

+ 12 - 30
internal/logic/order/list.go

@@ -15,9 +15,8 @@ import (
 func List(ctx context.Context, param model.OrderListParams) (map[string]interface{}, error) {
 func List(ctx context.Context, param model.OrderListParams) (map[string]interface{}, error) {
 	var (
 	var (
 		orderSql []string
 		orderSql []string
-		adminId  = jyutil.GetUserMsgFromCtx(ctx).PositionId
+		adminId  = gconv.String(common.If(jyutil.GetUserMsgFromCtx(ctx).EntId > 0, jyutil.GetUserMsgFromCtx(ctx).EntUserId, jyutil.GetUserMsgFromCtx(ctx).MgoUserId))
 	)
 	)
-
 	if param.Page <= 0 {
 	if param.Page <= 0 {
 		param.Page = 1
 		param.Page = 1
 	}
 	}
@@ -31,10 +30,10 @@ func List(ctx context.Context, param model.OrderListParams) (map[string]interfac
 		if countRes > 0 {
 		if countRes > 0 {
 			orderSql = append(orderSql, " a.order_channel = 'xdqd04' ")
 			orderSql = append(orderSql, " a.order_channel = 'xdqd04' ")
 		} else {
 		} else {
-			orderSql = append(orderSql, fmt.Sprintf(" f.ent_userId= %d ", adminId))
+			orderSql = append(orderSql, fmt.Sprintf(" f.ent_userId= '%s' ", adminId))
 		}
 		}
 	} else {
 	} else {
-		orderSql = append(orderSql, fmt.Sprintf(`(a.ent_userId =%d or f.ent_userId =%d)`, adminId, adminId))
+		orderSql = append(orderSql, fmt.Sprintf(`(a.salesperson_entUserId ='%s' or f.ent_userId ='%s')`, adminId, adminId))
 	}
 	}
 	if param.SearchContent != "" {
 	if param.SearchContent != "" {
 		orderSql = append(orderSql, fmt.Sprintf(`  (a.order_code = '%s' or a.company_name LIKE '%s' or a.user_phone LIKE '%s')`,
 		orderSql = append(orderSql, fmt.Sprintf(`  (a.order_code = '%s' or a.company_name LIKE '%s' or a.user_phone LIKE '%s')`,
@@ -122,28 +121,8 @@ func List(ctx context.Context, param model.OrderListParams) (map[string]interfac
 	if param.OrderTimeEnd != "" {
 	if param.OrderTimeEnd != "" {
 		orderSql = append(orderSql, fmt.Sprintf("a.create_time<='%s'", param.OrderTimeEnd))
 		orderSql = append(orderSql, fmt.Sprintf("a.create_time<='%s'", param.OrderTimeEnd))
 	}
 	}
-	sql := fmt.Sprintf(`SELECT 
-    a.order_code,
-    a.company_name,
-    a.user_phone,
-    a.user_nickname,
-    a.buy_subject,
-    a.audit_status,
-    a.order_status,
-    a.pay_money - IFNULL(g.orderMoney, 0) as pay_money,
-    a.commission,
-    a.return_status,
-    IFNULL(c.return_money, 0) as return_money,
-    IFNULL(b.invoiced_amount, 0) as invoiced_amount,
-    a.refund_status,
-    IFNULL(d.refund_money, 0) as refund_money,
-    f.ent_userId,
-    e.contract_status,
-    e.contract_time,
-    e.contract_archive_status,
-    e.contract_archive_time,
-    (SELECT product_type FROM jy_order_detail where order_code = a.order_code order by final_price desc, id desc LIMIT 1) as productType,
-    (SELECT filter FROM jy_order_detail where order_code = a.order_code order by final_price desc, id desc LIMIT 1) as filter
+	sqlWhere := `SELECT 
+   %s
 FROM 
 FROM 
     dataexport_order a 
     dataexport_order a 
 LEFT JOIN (
 LEFT JOIN (
@@ -178,7 +157,7 @@ LEFT JOIN (
         order_code
         order_code
 ) d ON a.order_code = d.order_code
 ) d ON a.order_code = d.order_code
 LEFT JOIN (
 LEFT JOIN (
-    SELECT ordercode, ent_userId FROM order_sale_record WHERE ent_userId = %d and state in (1,2)
+    SELECT ordercode, ent_userId FROM order_sale_record WHERE ent_userId = '%s' and state in (1,2) GROUP BY ordercode,ent_userId
 ) f ON a.order_code = f.ordercode
 ) f ON a.order_code = f.ordercode
 LEFT JOIN contract e ON a.order_code = e.order_code 
 LEFT JOIN contract e ON a.order_code = e.order_code 
 LEFT JOIN (
 LEFT JOIN (
@@ -191,16 +170,19 @@ LEFT JOIN (
         orderCode
         orderCode
 ) g ON a.order_code = g.orderCode   
 ) g ON a.order_code = g.orderCode   
 WHERE 
 WHERE 
-    %s`, adminId, strings.Join(orderSql, " and "))
+    %s`
+	sql := fmt.Sprintf(sqlWhere, " a.order_code,\n    a.company_name,\n    a.user_phone,\n    a.user_nickname,\n    a.buy_subject,\n    a.audit_status,\n    a.order_status,\n    a.pay_money - IFNULL(g.orderMoney, 0) as pay_money,\n    a.commission,\n    a.return_status,\n    IFNULL(c.return_money, 0) as return_money,\n    IFNULL(b.invoiced_amount, 0) as invoiced_amount,\n    a.refund_status,\n    IFNULL(d.refund_money, 0) as refund_money,\n    f.ent_userId,\n    e.contract_status,\n    e.contract_time,\n    e.contract_archive_status,\n    e.contract_archive_time,\n    (SELECT product_type FROM jy_order_detail where order_code = a.order_code order by final_price desc, id desc LIMIT 1) as productType,\n    (SELECT filter FROM jy_order_detail where order_code = a.order_code order by final_price desc, id desc LIMIT 1) as filter", adminId, strings.Join(orderSql, " and "))
+	sqlCount := fmt.Sprintf(sqlWhere, " count(1) ", adminId, strings.Join(orderSql, " and "))
 
 
+	log.Println("list count sql :", sqlCount)
 	log.Println("list sql :", sql)
 	log.Println("list sql :", sql)
-	count, err := g.DB().GetCount(ctx, sql)
+	count, err := g.DB().GetCount(ctx, sqlCount)
 	if err != nil {
 	if err != nil {
 		log.Println("count err:=", err.Error())
 		log.Println("count err:=", err.Error())
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	list, err := g.DB().Query(ctx, fmt.Sprintf(`%s order by create_time desc LIMIT %d,%d`, sql, (param.Page-1)*param.Size, param.Size))
+	list, err := g.DB().Query(ctx, fmt.Sprintf(`%s order by a.create_time desc LIMIT %d,%d`, sql, (param.Page-1)*param.Size, param.Size))
 	if err != nil {
 	if err != nil {
 		log.Println("list err:=", err.Error())
 		log.Println("list err:=", err.Error())
 		return nil, err
 		return nil, err

+ 6 - 6
internal/logic/order/redPunch.go

@@ -18,8 +18,8 @@ import (
 
 
 // OperateOrderRedPunch 红冲
 // OperateOrderRedPunch 红冲
 func OperateOrderRedPunch(ctx context.Context, param model.OrderRedPunchParams) error {
 func OperateOrderRedPunch(ctx context.Context, param model.OrderRedPunchParams) error {
-	orderData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT pay_money-(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode=%s and 'state'=1) as pay_money FROM dataexport_order  WHERE order_code = %s`, param.OrderCode, param.OrderCode))
-	if err != nil || !orderData.IsEmpty() {
+	orderData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT pay_money+(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode='%s') as pay_money FROM dataexport_order  WHERE order_code = '%s'`, param.OrderCode, param.OrderCode))
+	if err != nil || orderData.IsEmpty() {
 		return errors.New("未找到订单")
 		return errors.New("未找到订单")
 	}
 	}
 	updateData := map[string]interface{}{}
 	updateData := map[string]interface{}{}
@@ -51,7 +51,7 @@ func OperateOrderRedPunch(ctx context.Context, param model.OrderRedPunchParams)
 			"orderCode":        param.OrderCode,
 			"orderCode":        param.OrderCode,
 			"correctionReason": param.CorrectionReason,
 			"correctionReason": param.CorrectionReason,
 			"createTime":       date.NowFormat(date.Date_Full_Layout),
 			"createTime":       date.NowFormat(date.Date_Full_Layout),
-			"createPerson":     "context.User.Username",
+			"createPerson":     jyutil.GetUserMsgFromCtx(ctx).EntUserName,
 			"proceduresMoney":  param.ProceduresMoney * -1,
 			"proceduresMoney":  param.ProceduresMoney * -1,
 			"redType":          param.RedType,
 			"redType":          param.RedType,
 		}
 		}
@@ -63,7 +63,7 @@ func OperateOrderRedPunch(ctx context.Context, param model.OrderRedPunchParams)
 			"orderCode":        param.OrderCode,
 			"orderCode":        param.OrderCode,
 			"correctionReason": param.CorrectionReason,
 			"correctionReason": param.CorrectionReason,
 			"createTime":       date.NowFormat(date.Date_Full_Layout),
 			"createTime":       date.NowFormat(date.Date_Full_Layout),
-			"createPerson":     "context.User.Username",
+			"createPerson":     jyutil.GetUserMsgFromCtx(ctx).EntUserName,
 			"redType":          param.RedType,
 			"redType":          param.RedType,
 		}
 		}
 		var signingSubject string
 		var signingSubject string
@@ -103,8 +103,8 @@ func OperateOrderRedPunch(ctx context.Context, param model.OrderRedPunchParams)
 
 
 		updateData["procedures_money"] = param.ProceduresMoney
 		updateData["procedures_money"] = param.ProceduresMoney
 		insertData["proceduresMoney"] = param.ProceduresMoney - common.IntAll(orderData.Map()["procedures_money"])
 		insertData["proceduresMoney"] = param.ProceduresMoney - common.IntAll(orderData.Map()["procedures_money"])
-		returnData, _ := g.DB().GetOne(ctx, `select IFNULL(sum(return_money),0) as return_money from return_money_record where order_code=? and state=1`, param.OrderCode)
-		refundData, _ := g.DB().GetOne(ctx, `select IFNULL(sum(refund_money),0) as refund_money from refund_record where order_code=?`, param.OrderCode)
+		returnData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`select IFNULL(sum(return_money),0) as return_money from return_money_record where order_code='%s' and state=1`, param.OrderCode))
+		refundData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`select IFNULL(sum(refund_money),0) as refund_money from refund_record where order_code='%s'`, param.OrderCode))
 		return_money := common.IntAll(returnData.Map()["return_money"])
 		return_money := common.IntAll(returnData.Map()["return_money"])
 		refund_money := common.IntAll(refundData.Map()["refund_money"])
 		refund_money := common.IntAll(refundData.Map()["refund_money"])
 		if param.PayMoney-param.Commission-param.ProceduresMoney <= return_money-refund_money {
 		if param.PayMoney-param.Commission-param.ProceduresMoney <= return_money-refund_money {

+ 7 - 5
internal/logic/order/refund.go

@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"io/ioutil"
 	"io/ioutil"
 	"jyOrderManager/internal/model"
 	"jyOrderManager/internal/model"
@@ -48,7 +49,7 @@ func ConfirmRefund(ctx context.Context, param model.OrderRefundParams) error {
 					"pay_status": -1,
 					"pay_status": -1,
 				}, map[string]interface{}{"id": param.DetailId})
 				}, map[string]interface{}{"id": param.DetailId})
 			}
 			}
-			data, _ := g.DB().Query(ctx, "invoice", qMap, "", "create_time", 0, 0)
+			data, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM invoice WHERE order_code = '%s' order by create_time `, param.OrderCode))
 			if !data.IsEmpty() {
 			if !data.IsEmpty() {
 				if data.Len() > 1 {
 				if data.Len() > 1 {
 					invoiceSerialnum := common.ObjToString(data.List()[1]["invoice_serialnum"])
 					invoiceSerialnum := common.ObjToString(data.List()[1]["invoice_serialnum"])
@@ -79,8 +80,8 @@ func ConfirmRefund(ctx context.Context, param model.OrderRefundParams) error {
 				}, map[string]interface{}{"id": param.DetailId})
 				}, map[string]interface{}{"id": param.DetailId})
 			}
 			}
 			var returnStatus int
 			var returnStatus int
-			returnData, _ := g.DB().GetOne(ctx, `select IFNULL(sum(return_money),0) as return_money from return_money_record where order_code=? and state=1`, orderCode)
-			refundData, _ := g.DB().GetOne(ctx, `select IFNULL(sum(refund_money),0) as refund_money from refund_record where order_code=?`, orderCode)
+			returnData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`select IFNULL(sum(return_money),0) as return_money from return_money_record where order_code='%s' and state=1`, orderCode))
+			refundData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`select IFNULL(sum(refund_money),0) as refund_money from refund_record where order_code='%s'`, orderCode))
 			return_money := common.IntAll(returnData.Map()["return_money"])
 			return_money := common.IntAll(returnData.Map()["return_money"])
 			refund_money := common.IntAll(refundData.Map()["refund_money"])
 			refund_money := common.IntAll(refundData.Map()["refund_money"])
 			if return_money == refund_money {
 			if return_money == refund_money {
@@ -107,7 +108,7 @@ func RefundInvoice(ctx context.Context, invoiceSerialnum, orderCode string) {
 	if invoiceSerialnum != "" {
 	if invoiceSerialnum != "" {
 		query := make(map[string]interface{})
 		query := make(map[string]interface{})
 		query["invoice_serialnum"] = invoiceSerialnum
 		query["invoice_serialnum"] = invoiceSerialnum
-		invoiceData, _ := g.DB().GetOne(ctx, "invoice", query, "invoice_code,invoice_number,invoice_serialnum", "")
+		invoiceData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT invoice_code,invoice_number,invoice_serialnum FROM invoice WHERE invoice_serialnum = '%s' order by create_time `, invoiceSerialnum))
 		if !invoiceData.IsEmpty() {
 		if !invoiceData.IsEmpty() {
 			req_ := make(map[string]interface{})
 			req_ := make(map[string]interface{})
 			req_["fpdm"] = invoiceData.Map()["invoice_code"]
 			req_["fpdm"] = invoiceData.Map()["invoice_code"]
@@ -116,7 +117,8 @@ func RefundInvoice(ctx context.Context, invoiceSerialnum, orderCode string) {
 			req_["orderCode"] = orderCode
 			req_["orderCode"] = orderCode
 			b, _ := json.Marshal(req_)
 			b, _ := json.Marshal(req_)
 			buffer := bytes.NewBuffer(b)
 			buffer := bytes.NewBuffer(b)
-			request, err := http.NewRequest("POST", "SysConfigs.InvoiceInterfaceAddress", buffer)
+			invoiceInterfaceAddress := gconv.String(g.Cfg().MustGet(context.Background(), "invoiceInterfaceAddress").String())
+			request, err := http.NewRequest("POST", invoiceInterfaceAddress, buffer)
 			if err != nil {
 			if err != nil {
 				log.Println("SysConfigs.InvoiceInterfaceAddress err ", err.Error())
 				log.Println("SysConfigs.InvoiceInterfaceAddress err ", err.Error())
 				return
 				return

+ 2 - 1
internal/logic/order/seal.go

@@ -4,6 +4,7 @@ import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/common"
 	"context"
 	"context"
 	"errors"
 	"errors"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
 	"jyOrderManager/internal/model"
 	"jyOrderManager/internal/model"
 	"time"
 	"time"
@@ -13,7 +14,7 @@ import (
 func OperateOrderSeal(ctx context.Context, param model.OrderSealParams) (map[string]interface{}, error) {
 func OperateOrderSeal(ctx context.Context, param model.OrderSealParams) (map[string]interface{}, error) {
 	switch param.RegType {
 	switch param.RegType {
 	case "post": //增加记录`
 	case "post": //增加记录`
-		_d, _ := g.DB().GetOne(ctx, "dataexport_order", map[string]interface{}{"order_code": param.OrderCode}, "audit_status,order_status", "")
+		_d, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT audit_status,order_status FROM dataexport_order WHERE order_code = '%s'`, param.OrderCode))
 		if _d.IsEmpty() {
 		if _d.IsEmpty() {
 			return nil, errors.New("订单获取失败")
 			return nil, errors.New("订单获取失败")
 		}
 		}

+ 1 - 1
internal/logic/order/selfInvoice.go

@@ -16,7 +16,7 @@ func SelfInvoice(ctx context.Context, param model.OrderDetailParams) (map[string
 		isFullBilling, isApplyBilling bool
 		isFullBilling, isApplyBilling bool
 	)
 	)
 	//订单信息查询
 	//订单信息查询
-	orderData, _ := g.DB().GetOne(ctx, fmt.Sprintf("select   pay_money-(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode=%s and 'state'=1) as pay_money,applybill_status,signing_subject from  dataexport_order  where  order_code ='%s'", param.OrderCode, param.OrderCode))
+	orderData, _ := g.DB().GetOne(ctx, fmt.Sprintf("select   pay_money+(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode='%s' ) as pay_money,applybill_status,signing_subject from  dataexport_order  where  order_code ='%s'", param.OrderCode, param.OrderCode))
 	if orderData.IsEmpty() {
 	if orderData.IsEmpty() {
 		return nil, errors.New("订单编号不存在")
 		return nil, errors.New("订单编号不存在")
 	}
 	}