a
This commit is contained in:
@@ -174,6 +174,15 @@ func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, from
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobWithTitle(db *DaoDB, title string) (job *model.Job, err error) {
|
||||
sql := `
|
||||
SELECT * FROM job WHERE title = ? AND deleted_at = ? AND status = ?
|
||||
`
|
||||
sqlParams := []interface{}{title, utils.DefaultTimeValue, model.JobStatusDoing}
|
||||
err = GetRow(db, &job, sql, sqlParams)
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, span int, includeStep bool) (jobs []*GetJobsResult, err error) {
|
||||
sql := `
|
||||
SELECT a.*, b.name
|
||||
|
||||
@@ -215,8 +215,9 @@ func getFromSql(orderType, status int, alies string, userID string, pop int, cit
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE 1 = 1
|
||||
WHERE a.status = ? AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, model.UserStatusNormal, utils.DefaultTimeValue)
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
@@ -337,3 +338,163 @@ func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile
|
||||
getPayStatisticsResult.TotalIncome = getPayStatisticsResult.MemberIncome + getPayStatisticsResult.CashIncome
|
||||
return getPayStatisticsResult, err
|
||||
}
|
||||
|
||||
type GetManageStatisticsResult struct {
|
||||
Date time.Time `json:"date"` //日期
|
||||
BrowseCount int `json:"browseCount"` //点击次数
|
||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
||||
FinishCount int `json:"finishCount"` //完成任务数
|
||||
CancelCount int `json:"cancelCount"` //取消任务数
|
||||
TotalCash int `json:"totalCash"` //返现总额
|
||||
InversionRate float64 `json:"inversionRate"` //转化率
|
||||
}
|
||||
|
||||
func getFromSqlManage(status int, alies string, cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
||||
sql += `
|
||||
(SELECT COUNT(b.id) count,
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if status != 0 {
|
||||
sql += " AND b.status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
if jobTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, jobTime)
|
||||
}
|
||||
if endTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN ` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if len(jobIDs) > 0 {
|
||||
sql += ` AND a.id IN ` + GenQuestionMarks(len(jobIDs)) + `)`
|
||||
sqlParams = append(sqlParams, jobIDs)
|
||||
}
|
||||
sql += ") " + alies
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func getWhereSqlManage(cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
||||
if jobTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, jobTime)
|
||||
}
|
||||
if endTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN ` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if len(jobIDs) > 0 {
|
||||
sql += ` AND a.id IN ` + GenQuestionMarks(len(jobIDs)) + `)`
|
||||
sqlParams = append(sqlParams, jobIDs)
|
||||
}
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func GetManageStatistics(db *DaoDB, cityCodes []int, jobTime time.Time, jobIDs []int) (getManageStatisticsResult *GetManageStatisticsResult, err error) {
|
||||
endTime := jobTime.AddDate(0, 0, 1)
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT t1.count acceptCount, t2.count finish_count, t3.count cancel_count, t4.browse_count, t5.total_cash
|
||||
FROM
|
||||
`
|
||||
rSQL1, rSQLparams1 := getFromSqlManage(model.JobOrderStatusAccept, "t1", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL1 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams1...)
|
||||
rSQL2, rSQLparams2 := getFromSqlManage(model.JobOrderStatusFinish, "t2", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL2 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams2...)
|
||||
rSQL3, rSQLparams3 := getFromSqlManage(model.JobOrderStatusCancel, "t3", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL3 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams3...)
|
||||
sql += `
|
||||
(SELECT SUM(a.browse_count) browse_count
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
rSQL4, rSQLparams4 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL4
|
||||
sqlParams = append(sqlParams, rSQLparams4...)
|
||||
sql += `
|
||||
) t4
|
||||
`
|
||||
sql += `
|
||||
(SELECT COUNT(b.id) * a.avg_price total_cash
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ? AND b.status = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.JobOrderStatusFinish)
|
||||
rSQL5, rSQLparams5 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL5
|
||||
sqlParams = append(sqlParams, rSQLparams5...)
|
||||
sql += `
|
||||
) t5
|
||||
`
|
||||
err = GetRow(db, &getManageStatisticsResult, sql, sqlParams)
|
||||
getManageStatisticsResult.Date = jobTime
|
||||
getManageStatisticsResult.InversionRate = float64(getManageStatisticsResult.FinishCount) / float64(getManageStatisticsResult.BrowseCount)
|
||||
return getManageStatisticsResult, err
|
||||
}
|
||||
|
||||
type GetManageStatisticsJobResult struct {
|
||||
BrowseCount int `json:"browseCount"` //点击次数
|
||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
||||
FinishCount int `json:"finishCount"` //完成任务数
|
||||
CancelCount int `json:"cancelCount"` //取消任务数
|
||||
TotalCash int `json:"totalCash"` //返现总额
|
||||
InversionRate float64 `json:"inversionRate"` //转化率
|
||||
Title string `json:"title"` //任务标题
|
||||
}
|
||||
|
||||
func GetManageStatisticsJob(db *DaoDB, cityCodes []int, fromTime, toTime time.Time, jobIDs []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
sqlParams = []interface{}{}
|
||||
getManageStatisticsJobResult []*GetManageStatisticsJobResult
|
||||
)
|
||||
sql := `
|
||||
SELECT t1.count acceptCount, t2.count finish_count, t3.count cancel_count, a.browse_count, a.title, a.browse_count / t2.count inversion_rate, t4.total_cash
|
||||
FROM job a
|
||||
JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t1 ON t1.job_id = a.id
|
||||
JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t2 ON t2.job_id = a.id
|
||||
JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t3 ON t3.job_id = a.id
|
||||
`
|
||||
sql += `
|
||||
JOIN (SELECT COUNT(b.id) * a.avg_price total_cash, a.id
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id AND b.status = ?
|
||||
GROUP BY 2) t4 ON t4.id = a.id
|
||||
`
|
||||
sqlParams = append(sqlParams, model.JobOrderStatusAccept, model.JobOrderStatusFinish, model.JobOrderStatusCancel)
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.JobOrderStatusFinish)
|
||||
sql += " WHERE a.deleted_at = ?"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
rSQL, rSQLparams := getWhereSqlManage(cityCodes, fromTime, toTime, jobIDs)
|
||||
sql += rSQL
|
||||
sqlParams = append(sqlParams, rSQLparams...)
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
err = GetRows(db, &getManageStatisticsJobResult, sql, sqlParams)
|
||||
if err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
Data: getManageStatisticsJobResult,
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user