|
@@ -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
|