65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package localjx
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
)
|
|
|
|
type GetJxShopUsersResult struct {
|
|
model.User
|
|
BuyCount int `json:"buyCount"`
|
|
ActualPayPrice int `json:"actualPayPrice"`
|
|
GoodCommentCount int `json:"goodCommentCount"`
|
|
BadCommentCount int `json:"badCommentCount"`
|
|
UserMembers []*model.UserMember `json:"userMembers"`
|
|
}
|
|
|
|
func GetJxShopUsers(ctx *jxcontext.Context, keyword string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
|
var (
|
|
requestList []*GetJxShopUsersResult
|
|
db = dao.GetDB()
|
|
)
|
|
sql := `
|
|
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.*, b.buy_count, b.actual_pay_price
|
|
FROM user a,
|
|
(SELECT a.user_id, COUNT(*) buy_count, SUM(c.actual_pay_price) actual_pay_price
|
|
FROM user a
|
|
JOIN auth_bind b ON b.user_id = a.user_id AND b.deleted_at = ? AND b.type_id = ?
|
|
JOIN goods_order c ON c.user_id = a.user_id AND c.status <> ?
|
|
WHERE a.deleted_at = ?
|
|
GROUP BY 1) b
|
|
WHERE a.user_id = b.user_id
|
|
`
|
|
sqlParams := []interface{}{
|
|
utils.DefaultTimeValue, api.WeixinMiniAppID2,
|
|
model.OrderStatusCanceled,
|
|
utils.DefaultTimeValue,
|
|
}
|
|
if keyword != "" {
|
|
sql += " AND (a.user_id LIKE ? OR a.name LIKE ? OR a.moblie LIKE ? OR a.user_id2 LIKE ?)"
|
|
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
|
}
|
|
sql += "LIMIT ? OFFSET ?"
|
|
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
sqlParams = append(sqlParams, pageSize, offset)
|
|
for _, v := range requestList {
|
|
userMembers, _ := dao.GetUserMember(db, v.UserID, "", model.MemberTypeDiscountCard, model.YES)
|
|
v.UserMembers = userMembers
|
|
}
|
|
dao.Begin(db)
|
|
defer dao.Commit(db)
|
|
if err = dao.GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
|
return &model.PagedInfo{
|
|
TotalCount: dao.GetLastTotalRowCount(db),
|
|
Data: requestList,
|
|
}, nil
|
|
}
|
|
return pagedInfo, err
|
|
}
|