删一些东西
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetUserBill(db *DaoDB, userID, billID string) (userBill *model.UserBill, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_bill WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += ` AND user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if billID != "" {
|
||||
sql += ` AND bill_id = ?`
|
||||
sqlParams = append(sqlParams, billID)
|
||||
}
|
||||
err = GetRow(db, &userBill, sql, sqlParams)
|
||||
return userBill, err
|
||||
}
|
||||
|
||||
func GetBillExpend(db *DaoDB, userID string, billType int, fromTime, toTime time.Time) (billExpends []*model.BillExpend, err error) {
|
||||
sql := `
|
||||
SELECT b.*
|
||||
FROM user_bill a
|
||||
LEFT JOIN bill_expend b ON b.bill_id = a.bill_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if billType != 0 {
|
||||
sql += ` AND b.type = ?`
|
||||
sqlParams = append(sqlParams, billType)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
err = GetRows(db, &billExpends, sql, sqlParams)
|
||||
return billExpends, err
|
||||
}
|
||||
|
||||
func GetBillIncome(db *DaoDB, jobID int, billID int64) (billIncomes []*model.BillIncome, err error) {
|
||||
sql := `
|
||||
SELECT b.*
|
||||
FROM user_bill a
|
||||
LEFT JOIN bill_income b ON b.bill_id = a.bill_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if jobID != 0 {
|
||||
sql += ` AND b.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if billID != 0 {
|
||||
sql += ` AND b.bill_id = ?`
|
||||
sqlParams = append(sqlParams, billID)
|
||||
}
|
||||
err = GetRows(db, &billIncomes, sql, sqlParams)
|
||||
return billIncomes, err
|
||||
}
|
||||
|
||||
type UserBillDetail struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
LastOperator string `json:"lastOperator"`
|
||||
BillType int `json:"billType"`
|
||||
Price int `json:"price"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func GetUserBillDetail(db *DaoDB, userID string, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var userBillDetails []*UserBillDetail
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS k.* FROM (
|
||||
SELECT a.created_at, a.last_operator, a.type bill_type, a.income_price price, 'income' type
|
||||
FROM bill_income a
|
||||
JOIN user_bill b ON a.bill_id = b.bill_id AND b.user_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{userID}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
UNION ALL
|
||||
SELECT a.created_at, a.last_operator, a.type bill_type, a.expend_price price, 'expend' type
|
||||
FROM bill_expend a
|
||||
JOIN user_bill b ON a.bill_id = b.bill_id AND b.user_id = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
)k
|
||||
ORDER BY k.created_at LIMIT ? OFFSET ?
|
||||
`
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userBillDetails, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: userBillDetails,
|
||||
}
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
@@ -1,582 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
sortTypeDistance = 1 //距离
|
||||
sortTypeTime = 2 //发布时间
|
||||
sortTypeAvgPrice = 4 //奖励高低
|
||||
)
|
||||
|
||||
func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategory, err error) {
|
||||
sql := `
|
||||
SELECT * FROM job_category WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if name != "" {
|
||||
sql += ` AND name LIKE ?`
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
err = GetRows(db, &jobCategories, sql, sqlParams)
|
||||
return jobCategories, err
|
||||
}
|
||||
|
||||
type GetJobsResult struct {
|
||||
model.JobExt
|
||||
CategoryName string `json:"categoryName"` //分类名
|
||||
IndexImg string `json:"indexImg"` //任务封面
|
||||
Distance float64 `json:"distance"` //距用户距离
|
||||
}
|
||||
|
||||
func GetJobSteps(db *DaoDB, jobID int) (jobSteps []*model.JobStep, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_step
|
||||
WHERE job_id = ?
|
||||
AND deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{jobID, utils.DefaultTimeValue}
|
||||
err = GetRows(db, &jobSteps, sql, sqlParams)
|
||||
return jobSteps, err
|
||||
}
|
||||
|
||||
func GetJobImgs(db *DaoDB, jobID int) (jobImgs []*model.JobImg, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_img
|
||||
WHERE job_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{jobID}
|
||||
err = GetRows(db, &jobImgs, sql, sqlParams)
|
||||
return jobImgs, err
|
||||
}
|
||||
|
||||
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types, cityCodes []int, includeStep bool, fromTime, toTime time.Time, lng, lat float64, cityCode, span int, keyword string, sortType, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
jobs []*GetJobsResult
|
||||
sqlParams = []interface{}{lng, lat, utils.DefaultTimeValue, utils.DefaultTimeValue}
|
||||
)
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name, getDistance(?, ?, CAST(a.lng AS DECIMAL(15,6))/1000000, CAST(a.lat AS DECIMAL(15,6))/1000000) distance
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
if cityCode > 0 {
|
||||
sql += " AND (a.job_city_code = ? OR a.job_city_code = ?)"
|
||||
sqlParams = append(sqlParams, cityCode, model.JobCountrywideCode)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(categoryIDs) > 0 {
|
||||
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
|
||||
sqlParams = append(sqlParams, categoryIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(types) > 0 {
|
||||
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
|
||||
sqlParams = append(sqlParams, types)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if span != 0 {
|
||||
if span == model.JobSpanTop {
|
||||
sql += ` AND a.job_span_top = 1`
|
||||
} else {
|
||||
sql += ` AND a.job_span_recmd = 1`
|
||||
}
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += ` AND (a.title LIKE ? OR a.content LIKE ? OR a.address LIKE ? OR b.name LIKE ?)`
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
if sortType != 0 {
|
||||
if sortType == sortTypeDistance {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, distance`
|
||||
} else if sortType == -sortTypeDistance {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, distance DESC`
|
||||
} else if sortType == sortTypeAvgPrice {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.avg_price`
|
||||
} else if sortType == -sortTypeAvgPrice {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.avg_price DESC`
|
||||
} else if sortType == sortTypeTime {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.created_at`
|
||||
} else if sortType == -sortTypeTime {
|
||||
sql += ` ORDER BY status DESC, job_span_top DESC, top_seq, a.created_at DESC`
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &jobs, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: jobs,
|
||||
}
|
||||
for _, v := range jobs {
|
||||
if includeStep {
|
||||
if jobSteps, err := GetJobSteps(db, v.ID); err == nil && len(jobSteps) > 0 {
|
||||
v.JobSteps = jobSteps
|
||||
}
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobImgs = jobImgs
|
||||
v.IndexImg = jobImgs[0].Img
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = jobs
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (job *model.Job, err error) {
|
||||
jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, 0, includeStep)
|
||||
if err != nil {
|
||||
return job, err
|
||||
}
|
||||
if len(jobs) == 0 {
|
||||
return job, fmt.Errorf("未查询到对应的京东快递任务!")
|
||||
}
|
||||
if data, err := json.Marshal(jobs[0]); err == nil {
|
||||
json.Unmarshal(data, &job)
|
||||
}
|
||||
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
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(categoryIDs) > 0 {
|
||||
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
|
||||
sqlParams = append(sqlParams, categoryIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if len(types) > 0 {
|
||||
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
|
||||
sqlParams = append(sqlParams, types)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if span != 0 {
|
||||
if span == model.JobSpanTop {
|
||||
sql += ` AND a.job_span_top = 1`
|
||||
} else {
|
||||
sql += ` AND a.job_span_recmd = 1`
|
||||
}
|
||||
}
|
||||
err = GetRows(db, &jobs, sql, sqlParams...)
|
||||
for _, v := range jobs {
|
||||
if includeStep {
|
||||
if jobSteps, err := GetJobSteps(db, v.ID); err == nil && len(jobSteps) > 0 {
|
||||
v.JobSteps = jobSteps
|
||||
}
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobImgs = jobImgs
|
||||
}
|
||||
}
|
||||
return jobs, err
|
||||
}
|
||||
|
||||
func GetJobDetail(db *DaoDB, jobID int) (job *GetJobsResult, err error) {
|
||||
sql := `
|
||||
SELECT a.*, b.name
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
err = GetRow(db, &job, sql, sqlParams...)
|
||||
if job != nil {
|
||||
if jobSteps, err := GetJobSteps(db, job.ID); err == nil && len(jobSteps) > 0 {
|
||||
job.JobSteps = jobSteps
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, job.ID); err == nil && len(jobImgs) > 0 {
|
||||
job.JobImgs = jobImgs
|
||||
}
|
||||
} else {
|
||||
return job, fmt.Errorf("未查到到该任务!")
|
||||
}
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobOrdersNoPage(db *DaoDB, jobID int, jobOrderID int64, userID string, statusCompareStr string, fromTime, toTime time.Time, statuss []int) (jobOrders []*model.JobOrder, err error) {
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM job_order a
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if jobOrderID != 0 {
|
||||
sql += ` AND a.job_order_id = ?`
|
||||
sqlParams = append(sqlParams, jobOrderID)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if statusCompareStr != "" {
|
||||
sql += ` AND a.status ` + statusCompareStr
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
err = GetRows(db, &jobOrders, sql, sqlParams)
|
||||
return jobOrders, err
|
||||
}
|
||||
|
||||
type GetJobOrdersResult struct {
|
||||
model.JobOrder
|
||||
JobLimitAt int `json:"jobLimitAt"` //任务限时完成小时数
|
||||
AuditLimitAt int `json:"auditLimitAt"` //限时审核小时数
|
||||
JobOrderFinishAt time.Time `json:"jobOrderFinishAt"`
|
||||
JobOrderAuditFinishAt time.Time `json:"jobOrderAuditFinishAt"`
|
||||
JobIndexImg string `json:"jobIndexImg"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //推广平台
|
||||
AvgPrice int `json:"avgPrice"` //单个任务金额
|
||||
Title string `orm:"size(255)" json:"title"` //任务标题
|
||||
JobContent string `orm:"size(500)" json:"jobContent"`
|
||||
JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"`
|
||||
StoreURL string `orm:"column(store_url)" json:"storeURL"`
|
||||
}
|
||||
|
||||
func GetJobOrders(db *DaoDB, jobID int, jobOrderID int64, userID, jobUserID string, statusCompareStr string, fromTime, toTime time.Time, statuss []int, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var jobOrders []*GetJobOrdersResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.job_limit_at, b.vendor_id, b.avg_price, b.title, b.content job_content, b.audit_limit_at, b.job_category_id, b.store_url
|
||||
FROM job_order a
|
||||
JOIN job b ON a.job_id = b.id
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if jobOrderID != 0 {
|
||||
sql += ` AND a.job_order_id = ?`
|
||||
sqlParams = append(sqlParams, jobOrderID)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if jobUserID != "" {
|
||||
sql += ` AND b.user_id = ?`
|
||||
sqlParams = append(sqlParams, jobUserID)
|
||||
}
|
||||
if statusCompareStr != "" {
|
||||
sql += ` AND a.status ` + statusCompareStr
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &jobOrders, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: jobOrders,
|
||||
}
|
||||
for _, v := range jobOrders {
|
||||
if jobImgs, err := GetJobImgs(db, v.JobID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobIndexImg = jobImgs[0].Img
|
||||
}
|
||||
v.JobOrderFinishAt = v.JobOrder.CreatedAt.Add(time.Duration(v.JobLimitAt) * time.Hour)
|
||||
v.JobOrderAuditFinishAt = v.JobOrder.SubmitAuditAt.Add(time.Duration(v.AuditLimitAt) * time.Hour)
|
||||
}
|
||||
pagedInfo.Data = jobOrders
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetMtMember(db *DaoDB) (mtMember *model.MtMember, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM mt_member
|
||||
WHERE deleted_at = ?
|
||||
LIMIT 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRow(db, &mtMember, sql, sqlParams)
|
||||
return mtMember, err
|
||||
}
|
||||
|
||||
func GetJobTimers(db *DaoDB, status int) (jobTimers []*model.JobTimer, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_timer
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if status != -1 {
|
||||
sql += ` AND status = ?`
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
err = GetRows(db, &jobTimers, sql, sqlParams)
|
||||
return jobTimers, err
|
||||
}
|
||||
|
||||
func GetMtMembers(db *DaoDB) (num int, err error) {
|
||||
var mtMembers []*model.MtMember
|
||||
sql := `
|
||||
SELECT * FROM mt_member WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRows(db, &mtMembers, sql, sqlParams)
|
||||
num = len(mtMembers)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetUserSearch(db *DaoDB, userID, keyword string) (userSearchs []*model.UserSearch, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_search
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += " AND keyword = ?"
|
||||
sqlParams = append(sqlParams, keyword)
|
||||
}
|
||||
err = GetRows(db, &userSearchs, sql, sqlParams)
|
||||
return userSearchs, err
|
||||
}
|
||||
|
||||
func GetStationList(db *DaoDB) (stations []*model.StationInfo, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM station_info
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
err = GetRows(db, &stations, sql, sqlParams)
|
||||
return stations, err
|
||||
}
|
||||
|
||||
func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng float64, oilCode string, sortType, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
stations []*model.StationInfo
|
||||
distanceFlag bool
|
||||
sqlParams = []interface{}{}
|
||||
)
|
||||
if lng != 0 && lat != 0 {
|
||||
distanceFlag = true
|
||||
}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
`
|
||||
if distanceFlag {
|
||||
sql += `, getDistance(?, ?, longitude, latitude) distance`
|
||||
sqlParams = append(sqlParams, lng, lat)
|
||||
}
|
||||
sql += `
|
||||
FROM station_info
|
||||
WHERE 1 = 1
|
||||
`
|
||||
if stationName != "" {
|
||||
sql += " AND station_name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+stationName+"%")
|
||||
}
|
||||
if cityCode != 0 {
|
||||
sql += " AND city_id = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
if oilCode != "" {
|
||||
sql += " AND POSITION(? IN prices) > 0"
|
||||
sqlParams = append(sqlParams, oilCode)
|
||||
}
|
||||
if sortType != 0 {
|
||||
if sortType == 1 {
|
||||
sql += " ORDER BY distance"
|
||||
} else if sortType == -1 {
|
||||
sql += " ORDER BY distance DESC"
|
||||
} else if sortType == 2 {
|
||||
sql += " ORDER BY star_num"
|
||||
} else if sortType == -2 {
|
||||
sql += " ORDER BY star_num DESC"
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &stations, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: stations,
|
||||
}
|
||||
for _, v := range stations {
|
||||
var oilInfo []*model.OilInfo
|
||||
json.Unmarshal([]byte(strings.ReplaceAll(v.Prices, "\\", "")), &oilInfo)
|
||||
v.OilInfo = oilInfo
|
||||
}
|
||||
if math.Abs(utils.Int2Float64(sortType)) == 3 {
|
||||
if oilCode != "" {
|
||||
for i := 0; i < len(stations); i++ {
|
||||
for j := 0; j < len(stations)-i-1; j++ {
|
||||
var (
|
||||
index int
|
||||
index2 int
|
||||
)
|
||||
for k, v := range stations[j].OilInfo {
|
||||
if v.OilCode == oilCode {
|
||||
index = k
|
||||
}
|
||||
}
|
||||
for k, v := range stations[j+1].OilInfo {
|
||||
if v.OilCode == oilCode {
|
||||
index2 = k
|
||||
}
|
||||
}
|
||||
if sortType == 3 {
|
||||
if utils.Str2Float64(stations[j].OilInfo[index].DiscountPrice) > utils.Str2Float64(stations[j+1].OilInfo[index2].DiscountPrice) {
|
||||
temp := stations[j]
|
||||
stations[j] = stations[j+1]
|
||||
stations[j+1] = temp
|
||||
}
|
||||
} else if sortType == -3 {
|
||||
if utils.Str2Float64(stations[j].OilInfo[index].DiscountPrice) < utils.Str2Float64(stations[j+1].OilInfo[index2].DiscountPrice) {
|
||||
temp := stations[j]
|
||||
stations[j] = stations[j+1]
|
||||
stations[j+1] = temp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = stations
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetMaxJobTopSeq(db *DaoDB) (maxSeq int, err error) {
|
||||
Seq := &struct {
|
||||
TopSeq int
|
||||
}{}
|
||||
sql := `
|
||||
SELECT MAX(top_seq) top_seq FROM job WHERE deleted_at = ? AND status = ? AND job_span_top = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, model.JobStatusDoing, 1}
|
||||
if err = GetRow(db, &Seq, sql, sqlParams); err == nil {
|
||||
return Seq.TopSeq, err
|
||||
}
|
||||
return maxSeq, err
|
||||
}
|
||||
|
||||
func GetMaxJobRecmdSeq(db *DaoDB) (maxSeq int, err error) {
|
||||
Seq := &struct {
|
||||
RecmdSeq int
|
||||
}{}
|
||||
sql := `
|
||||
SELECT MAX(recmd_seq) recmd_seq FROM job WHERE deleted_at = ? AND status = ? AND job_span_recmd = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, model.JobStatusDoing, 1}
|
||||
if err = GetRow(db, &Seq, sql, sqlParams); err == nil {
|
||||
return Seq.RecmdSeq, err
|
||||
}
|
||||
return maxSeq, err
|
||||
}
|
||||
|
||||
func GetJobSpans(db *DaoDB) (jobSpans []*model.JobSpan, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_span
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRows(db, &jobSpans, sql, sqlParams)
|
||||
return jobSpans, err
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetVendorMatterCategory(db *DaoDB, vendorID int) (vendorMatterCat []*model.VendorMatterCategory, err error) {
|
||||
sql := `
|
||||
SELECT * FROM vendor_matter_category WHERE deleted_at = ? AND vendor_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, vendorID}
|
||||
err = GetRows(db, &vendorMatterCat, sql, sqlParams)
|
||||
return vendorMatterCat, err
|
||||
}
|
||||
@@ -1,424 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type UserDeliveryAddressEx struct {
|
||||
model.UserDeliveryAddress
|
||||
|
||||
UserName string `json:"userName"`
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
ParentCode int `json:"parentCode"`
|
||||
}
|
||||
|
||||
type GetSelfInfoResult struct {
|
||||
model.User
|
||||
model.UserBill
|
||||
WaitCashPrice int `json:"waitCashPrice"`
|
||||
WaitRealCashPrice int `json:"waitRealCashPrice"`
|
||||
UserMembers []*model.UserMember `json:"userMembers"`
|
||||
PopedUserName string `json:"popedUserName"`
|
||||
UnReadMessageCount int `json:"unReadMessageCount"`
|
||||
}
|
||||
|
||||
func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT *
|
||||
FROM user t1
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.%s = ?
|
||||
`, fieldName)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.UserStatusNormal,
|
||||
fieldValue,
|
||||
}
|
||||
// globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
|
||||
err = GetRow(db, &user, sql, sqlParams...)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func GetUserByIDWithMembers(db *DaoDB, fieldName, fieldValue string) (getSelfInfoResult *GetSelfInfoResult, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.*, t2.bill_id, t2.account_balance, t3.name pop_user_name
|
||||
FROM user t1
|
||||
JOIN user_bill t2 ON t2.user_id = t1.user_id AND t2.deleted_at = ?
|
||||
LEFT JOIN user t3 ON t3.user_id = t1.pop_user
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.%s = ?
|
||||
`, fieldName)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.UserStatusNormal,
|
||||
fieldValue,
|
||||
}
|
||||
// globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
|
||||
err = GetRow(db, &getSelfInfoResult, sql, sqlParams...)
|
||||
if messageGroupReads, err := GetMessageGroupRead(db, getSelfInfoResult.User.UserID, 0); err == nil {
|
||||
var unReadCount int
|
||||
for _, v := range messageGroupReads {
|
||||
unReadCount += v.UnReadCount
|
||||
}
|
||||
getSelfInfoResult.UnReadMessageCount = unReadCount
|
||||
}
|
||||
return getSelfInfoResult, err
|
||||
}
|
||||
|
||||
func GetUsers(db *DaoDB, userType int, keyword, popUser string, userIDs, userID2s, mobiles []string, offset, pageSize int) (userList []*model.User, totalCount int, err error) {
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
if userType == 0 {
|
||||
userType = 255
|
||||
}
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*
|
||||
FROM user t1
|
||||
WHERE t1.status = 1 AND t1.deleted_at = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(userID2s) > 0 {
|
||||
sql += " AND t1.user_id2 IN (" + GenQuestionMarks(len(userID2s)) + ")"
|
||||
sqlParams = append(sqlParams, userID2s)
|
||||
}
|
||||
if len(mobiles) > 0 {
|
||||
sql += " AND t1.mobile IN (" + GenQuestionMarks(len(mobiles)) + ")"
|
||||
sqlParams = append(sqlParams, mobiles)
|
||||
}
|
||||
if popUser != "" {
|
||||
sql += " AND t1.pop_user = ?"
|
||||
sqlParams = append(sqlParams, popUser)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (t1.user_id LIKE ? OR t1.user_id2 LIKE ? OR t1.mobile LIKE ? OR t1.email LIKE ? OR t1.name LIKE ?)"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCountTx(txDB)
|
||||
}
|
||||
return userList, totalCount, err
|
||||
}
|
||||
|
||||
func GetUsers2(db *DaoDB, keyword string, userID string, pop int, mobile string, fromTime, toTime time.Time, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
userList []*model.User
|
||||
)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS DISTINCT
|
||||
a.*
|
||||
FROM user a`
|
||||
for _, v := range consumeTypes {
|
||||
switch v {
|
||||
case model.ConsumeTypePublishJob:
|
||||
sql += " JOIN job b ON b.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND b.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND b.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
case model.ConsumeTypeMember:
|
||||
sql += " JOIN user_member c ON c.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND c.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND c.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
case model.ConsumeTypeDelivery:
|
||||
sql += " JOIN delivery_order d ON d.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND d.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND d.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE a.status = 1 AND a.deleted_at = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
} else {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND a.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " AND a.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (a.user_id LIKE ? OR a.mobile LIKE ? OR a.email LIKE ? OR a.name LIKE ?)"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 1 {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 1 {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userList, sql, sqlParams...); err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: userList,
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
func GetUser(db *DaoDB, userID string) (user *model.GetUserResult, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT
|
||||
t1.*, IF(t2.accept_order_count is NULL, 0, t2.accept_order_count) accept_order_count, IF(t3.finished_order_count is NULL, 0, t3.finished_order_count) finished_order_count
|
||||
FROM user t1
|
||||
LEFT JOIN (SELECT user_id, COUNT(user_id) accept_order_count FROM job_order WHERE user_id = ? GROUP BY 1)t2 ON t2.user_id = t1.user_id
|
||||
LEFT JOIN (SELECT user_id, COUNT(user_id) finished_order_count FROM job_order WHERE user_id = ? AND status = ? GROUP BY 1)t3 ON t3.user_id = t1.user_id
|
||||
WHERE t1.status = ? AND t1.deleted_at = ? AND t1.user_id = ? `
|
||||
sqlParams = append(sqlParams, userID, userID, model.JobOrderStatusFinish, model.YES, utils.DefaultTimeValue, userID)
|
||||
err = GetRow(db, &user, sql, sqlParams...)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func DeleteUsers(db *DaoDB, userIDs []string) (num int64, err error) {
|
||||
if len(userIDs) > 0 {
|
||||
sql := `
|
||||
UPDATE user t1
|
||||
JOIN auth_bind t2 ON t2.user_id = t1.user_id
|
||||
SET
|
||||
t1.deleted_at = ?,
|
||||
t2.deleted_at = ?
|
||||
WHERE t1.user_id IN (` + GenQuestionMarks(len(userIDs)) + ");"
|
||||
now := time.Now()
|
||||
sqlParams := []interface{}{
|
||||
now,
|
||||
now,
|
||||
userIDs,
|
||||
}
|
||||
num, err = ExecuteSQL(db, sql, sqlParams...)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func QueryUserDeliveryAddress(db *DaoDB, addressID int64, userIDs []string, addType int, offset, pageSize int) (addressList []*UserDeliveryAddressEx, totalCount int, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*,
|
||||
t2.name user_name,
|
||||
district.name district_name,
|
||||
city.name city_name,
|
||||
cp.code parent_code
|
||||
FROM user_delivery_address t1
|
||||
LEFT JOIN user t2 ON t2.user_id = t1.user_id
|
||||
LEFT JOIN place district ON district.code = t1.district_code
|
||||
LEFT JOIN place city ON city.code = t1.city_code
|
||||
LEFT JOIN place cp ON cp.code = city.parent_code
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if addressID > 0 {
|
||||
sql += " AND t1.id = ? "
|
||||
sqlParams = append(sqlParams, addressID)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if addType != 0 {
|
||||
sql += " AND t1.type = ? "
|
||||
sqlParams = append(sqlParams, addType)
|
||||
}
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sql += `
|
||||
ORDER BY t1.is_default DESC, t1.consignee_name
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &addressList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCountTx(txDB)
|
||||
}
|
||||
return addressList, totalCount, err
|
||||
}
|
||||
|
||||
func ClearUserDeliveryAddressDefault(db *DaoDB, userID string, defAddressID int) (err error) {
|
||||
sql := `
|
||||
UPDATE user_delivery_address t1
|
||||
SET t1.is_default = 0
|
||||
WHERE t1.deleted_at = ? AND t1.user_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
userID,
|
||||
}
|
||||
if defAddressID > 0 {
|
||||
sql += " AND t1.id <> ?"
|
||||
sqlParams = append(sqlParams, defAddressID)
|
||||
}
|
||||
_, err = ExecuteSQL(db, sql, sqlParams...)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserOrderSMS(db *DaoDB, mobile, name string) (userOrderSms *model.UserOrderSms, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_order_sms
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if mobile != "" {
|
||||
sql += " AND mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
if name != "" {
|
||||
sql += " AND name like ?"
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
err = GetRow(db, &userOrderSms, sql, sqlParams)
|
||||
return userOrderSms, err
|
||||
}
|
||||
|
||||
func GetUserMember(db *DaoDB, userID string, memberType int) (userMembers []*model.UserMember, err error) {
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM user_member a
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if memberType != 0 {
|
||||
sql += " AND a.member_type = ?"
|
||||
sqlParams = append(sqlParams, memberType)
|
||||
}
|
||||
err = GetRows(db, &userMembers, sql, sqlParams)
|
||||
return userMembers, err
|
||||
}
|
||||
|
||||
type GetUserAllWaitCashPriceResult struct {
|
||||
UserID string `orm:"column(user_id)" json:"userID"`
|
||||
Price int `json:"price"`
|
||||
}
|
||||
|
||||
func GetUserAllWaitCashPrice(db *DaoDB, userID string) (price int, err error) {
|
||||
var result = &GetUserAllWaitCashPriceResult{}
|
||||
sql := `
|
||||
SELECT SUM(IF(d.id IS NOT NULL, IF(d.divide_percentage = 0, b.avg_price, b.avg_price*(100-d.divide_percentage)/100),b.avg_price)) price, a.user_id
|
||||
FROM job_order a
|
||||
JOIN job b ON a.job_id = b.id
|
||||
LEFT JOIN message_group_member c ON a.user_id = c.member_user_id
|
||||
LEFT JOIN message_group d ON d.group_id = c.group_id AND d.type = ?
|
||||
WHERE a.user_id = ?
|
||||
AND a.status = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.GroupTypeMulit,
|
||||
userID,
|
||||
model.JobOrderStatusWaitAudit,
|
||||
}
|
||||
err = GetRow(db, &result, sql, sqlParams)
|
||||
return result.Price, err
|
||||
}
|
||||
|
||||
func GetUserUnionBind(db *DaoDB, userID string, vendorID int, unionID string) (userBinds []*model.UserUnionBind, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_union_bind WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if unionID != "" {
|
||||
sql += " AND union_id = ?"
|
||||
sqlParams = append(sqlParams, unionID)
|
||||
}
|
||||
err = GetRows(db, &userBinds, sql, sqlParams)
|
||||
return userBinds, err
|
||||
}
|
||||
|
||||
func GetUserUnionBindImg(db *DaoDB, unionID, actID string) (userBinds *model.UserUnionBindImg, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_union_bind_img WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if unionID != "" {
|
||||
sql += " AND union_id = ?"
|
||||
sqlParams = append(sqlParams, unionID)
|
||||
}
|
||||
if actID != "" {
|
||||
sql += " AND act_id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
err = GetRow(db, &userBinds, sql, sqlParams)
|
||||
return userBinds, err
|
||||
}
|
||||
@@ -142,66 +142,6 @@ func GetOperateEvents(db *DaoDB, name string, apiFunctions []string, operateType
|
||||
return operateEventExt, totalCount, err
|
||||
}
|
||||
|
||||
func GetImMessageRecord(db *DaoDB, groupID int, userID, toUserID string, storeID, vendorID int, fromTime, toTime time.Time, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var msg []*model.ImMessageRecord
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
FROM im_message_record
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if groupID != 0 {
|
||||
sql += " AND group_id = ?"
|
||||
sqlParams = append(sqlParams, groupID)
|
||||
if groupID == model.SysGroupID {
|
||||
sql += " AND to_user_id = ?"
|
||||
sqlParams = append(sqlParams, toUserID)
|
||||
}
|
||||
}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if storeID != 0 {
|
||||
sql += " AND store_id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if vendorID >= 0 {
|
||||
sql += " AND vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at >= ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at <= ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &msg, sql, sqlParams); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: msg,
|
||||
}
|
||||
for _, v := range msg {
|
||||
if user, err := GetUser(db, v.UserID); err == nil {
|
||||
v.UserInfo = user
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = msg
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
type GetMessageGroupsResult struct {
|
||||
model.MessageGroup
|
||||
Avatar string `json:"avatar"`
|
||||
|
||||
Reference in New Issue
Block a user