This commit is contained in:
suyl
2021-05-20 15:46:18 +08:00
parent b08499204e
commit 01b0b01187
2 changed files with 74 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
package dao
import (
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"time"
"git.rosy.net.cn/baseapi/utils"
@@ -375,33 +377,93 @@ func DeletePriceReferHistory(db *DaoDB, snapDate time.Time) (num int64, err erro
return ExecuteSQL(db, sql, sqlParams...)
}
type UserMemberReportResult struct {
Mobile string `json:"mobile"` //电话
Name string `json:"name"` //姓名
Status int `json:"status"` //状态
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
BuyCount int `json:"buyCount"` //购买次数
NewPrice int64 `json:"newPrice"` //最近订单金额
FinishedCount int `json:"finishedCount"` //完成订单数
BuyPrice int `json:"buyPrice"` //购买总金额
FinishedPrice int `json:"finishedPrice"` //完成订单金额
GoodsCommentCount int `json:"goodsCommentCount"` //好评数
BadCommentCount int `json:"badCommentCount"` //差评数
CityCode int `json:"cityCode"` // 常住城市
CityName string `json:"cityName"`
}
func UserMemberReport(db *DaoDB, vendorID int, keyword string, offset, pageSize int) (page *model.PagedInfo, err error) {
var list []*UserMemberReportResult
sql := `
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.mobile, IF(a.vendor_id = ?, c.name, b.consignee_name) name,
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',0,1) status, a.vendor_id,
COUNT(b.*) buy_count, COUNT(bb.*) finished_count, SUM(b.actual_pay_price) buy_price, SUM(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 b.status <> ?
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
GROUP BY 1, 2
LEFT JOIN jx_bad_comments d ON d.order_id = b.vendor_order_id
`
sqlParams := []interface{}{
model.VendorIDJX, model.OrderStatusCanceled,
model.VendorIDJX, model.OrderStatusFinished,
}
if vendorID != -1 {
sql += " AND a.vendor_id = ?"
sqlParams = append(sqlParams, vendorID)
}
if keyword != "" {
keywordLike := "%" + keyword + "%"
sql += " AND (a.mobile LIKE ? OR name LIKE ?)"
sqlParams = append(sqlParams, keywordLike, keywordLike)
}
sql += "LIMIT ? OFFSET ?"
sql += `
GROUP BY 1, 2, 3
LIMIT ? OFFSET ?
`
pageSize = jxutils.FormalizePageSize(pageSize)
sqlParams = append(sqlParams, pageSize, offset)
txDB, _ := Begin(db)
defer Commit(db, txDB)
if err = GetRowsTx(txDB, &page, sql, sqlParams...); err == nil {
return &model.PagedInfo{
if err = GetRowsTx(txDB, &list, sql, sqlParams...); err == nil {
page = &model.PagedInfo{
TotalCount: GetLastTotalRowCount2(db, txDB),
Data: page,
}, nil
//Data: page,
}
task := tasksch.NewParallelTask("", tasksch.NewParallelConfig().SetIsContinueWhenError(true), jxcontext.AdminCtx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
v := batchItemList[0].(*UserMemberReportResult)
var good *model.GoodsOrder
sql := `
SELECT * FROM goods_order WHERE consignee_mobile2 = ? AND vendor_id = ? LIMIT 1 OFFSET 0
`
sqlParams := []interface{}{v.Mobile, v.VendorID}
GetRow(db, &good, sql, sqlParams)
if good != nil {
v.NewPrice = good.ActualPayPrice
}
var place *model.Place
sql2 := `
SELECT a.* FROM place a,(
SELECT b.city_code, COUNT(*) count
FROM goods_order a
LEFT JOIN store b ON b.id = IF(a.jx_store_id = 0, store_id, jx_store_id)
WHERE consignee_mobile2 = ? AND vendor_id = ?
GROUP BY 1
ORDER BY COUNT(*)
LIMIT 1 OFFSET 0)b
WHERE a.code = b.city_code
`
GetRow(db, &place, sql2, sqlParams)
if place != nil {
v.CityName = place.Name
v.CityCode = place.Code
}
return retVal, err
}, list)
tasksch.HandleTask(task, nil, true).Run()
task.GetResult(0)
page.Data = list
}
return page, err
}

View File

@@ -150,6 +150,7 @@ func (c *ReportController) GetStoreManageState() {
// @router /UserMemberReport [get]
func (c *ReportController) UserMemberReport() {
c.callUserMemberReport(func(params *tReportUserMemberReportParams) (retVal interface{}, errCode string, err error) {
retVal, err = report.UserMemberReport(params.Ctx, params.VendorID, params.Keyword, params.Offset, params.PageSize)
return retVal, "", err
})
}