This commit is contained in:
suyl
2021-05-22 15:39:10 +08:00
parent fc7c2238b1
commit a83d409423
4 changed files with 84 additions and 24 deletions

View File

@@ -644,7 +644,7 @@ func RefreshJDMembers(ctx *jxcontext.Context) (err error) {
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdStorePageCookie", model.ConfigTypeCookie, ""); err == nil {
api.JdAPI.SetJdCookie(configs[0].Value)
}
userMemebers, _ := dao.GetUserMember(db, "", "", "", model.VendorIDJD, 0, -1)
userMemebers, _ := dao.GetUserMemberWithoutDeleted(db, model.VendorIDJD)
for _, v := range userMemebers {
memberMap[v.Mobile] = v
}
@@ -709,17 +709,28 @@ func UserMemberReport(ctx *jxcontext.Context, vendorID int, keyword string, offs
)
var list []*dao.UserMemberReportResult
sql := `
SELECT SQL_CALC_FOUND_ROWS a.mobile, IF(a.vendor_id = ?, c.name, b.consignee_name) name, IF(a.deleted_at = '1970-01-01 00:00:00',1,0) status, a.vendor_id,
COUNT(DISTINCT b.vendor_store_id) buy_count, COUNT(DISTINCT bb.vendor_store_id) finished_count, SUM(DISTINCT b.actual_pay_price) buy_price,
SUM(DISTINCT b.actual_pay_price) finished_price, COUNT(d.score > 3) good_comment_count, COUNT(d.score < 3) bad_comment_count
FROM user_member a
LEFT JOIN goods_order b ON a.mobile = b.consignee_mobile2 AND a.vendor_id = b.vendor_id
LEFT JOIN goods_order bb ON a.mobile = bb.consignee_mobile2 AND bb.status = ? AND a.vendor_id = bb.vendor_id
LEFT JOIN user c ON c.mobile = a.mobile
LEFT JOIN jx_bad_comments d ON d.order_id = b.vendor_order_id
SELECT a.mobile, IF(a.vendor_id = ?, b.name, t1.consignee_name) name, IF(a.deleted_at = ?, ?, ?) status, a.vendor_id, t1.buy_count, t1.buy_price,
t1.good_comment_count, t1.bad_comment_count, t2.finished_count, t2.finished_price
FROM user_member a
LEFT JOIN user b ON a.mobile = b.mobile
LEFT JOIN (
SELECT a.mobile, MAX(b.consignee_name) consignee_name, COUNT(b.vendor_store_id) buy_count, SUM(ISNULL(b.actual_pay_price)) buy_price, COUNT(c.score > 3) good_comment_count, COUNT(c.score < 3) bad_comment_count
FROM user_member a
LEFT JOIN goods_order b ON a.mobile = b.consignee_mobile2 AND a.vendor_id = b.vendor_id AND b.order_type = ? AND b.store_id <> ?
LEFT JOIN jx_bad_comments c ON c.order_id = b.vendor_order_id
GROUP BY 1
) t1 ON t1.mobile = a.mobile
LEFT JOIN (
SELECT a.mobile, COUNT(b.vendor_store_id) finished_count, SUM(ISNULL(b.actual_pay_price)) finished_price
FROM user_member a
LEFT JOIN goods_order b ON a.mobile = b.consignee_mobile2 AND a.vendor_id = b.vendor_id AND b.order_type = ? AND status = ? AND b.store_id <> ?
GROUP BY 1
)t2 ON t2.mobile = a.mobile
`
sqlParams := []interface{}{
model.VendorIDJX, model.OrderStatusFinished,
model.VendorIDJX, utils.DefaultTimeValue, model.YES, model.NO,
model.OrderTypeNormal, model.MatterStoreID,
model.OrderTypeNormal, model.OrderStatusFinished, model.MatterStoreID,
}
if vendorID != -1 {
sql += " AND a.vendor_id = ?"
@@ -731,7 +742,6 @@ func UserMemberReport(ctx *jxcontext.Context, vendorID int, keyword string, offs
sqlParams = append(sqlParams, keywordLike, keywordLike)
}
sql += `
GROUP BY 1, 2, 3, 4
LIMIT ? OFFSET ?
`
pageSize = jxutils.FormalizePageSize(pageSize)