From ac6882ef5e05b4fe2f2b1c26e680b6da00e190ce Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Wed, 7 Jul 2021 16:54:17 +0800 Subject: [PATCH] aa --- business/jxstore/event/event_tcp.go | 4 +- business/model/bill.go | 116 ++++++ business/model/dao/dao_bill.go | 131 +++++++ business/model/dao/dao_job.go | 582 ++++++++++++++++++++++++++++ business/model/job.go | 340 ++++++++++++++++ 5 files changed, 1171 insertions(+), 2 deletions(-) create mode 100644 business/model/bill.go create mode 100644 business/model/dao/dao_bill.go create mode 100644 business/model/dao/dao_job.go create mode 100644 business/model/job.go diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index afbbdab2f..1d033aac7 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -387,7 +387,7 @@ func replaceContent(content string) (result string) { } if strings.Contains(result, byteSignQrCenter) && strings.Contains(result, byteSignQrCenterE) { if qrs := regexpQrc.FindStringSubmatch(result); len(qrs) > 0 { - lenqr = len(qrs[1]) + lenqr = len(qrs[1]) / 2 hexLenqr = fmt.Sprintf("%x", lenqr) if len(hexLenqr) < 2 { hexLenqr = "0" + hexLenqr @@ -398,7 +398,7 @@ func replaceContent(content string) (result string) { } if strings.Contains(result, byteSignQrLeft) && strings.Contains(result, byteSignQrLeftE) { if qrs := regexpQrl.FindStringSubmatch(result); len(qrs) > 0 { - lenqr = len(qrs[1]) + lenqr = len(qrs[1]) / 2 hexLenqr = fmt.Sprintf("%x", lenqr) if len(hexLenqr) < 2 { hexLenqr = "0" + hexLenqr diff --git a/business/model/bill.go b/business/model/bill.go new file mode 100644 index 000000000..ffc35e896 --- /dev/null +++ b/business/model/bill.go @@ -0,0 +1,116 @@ +package model + +const ( + BillTypeDeposit = 10 //发布任务 + BillTypeJob = 11 //做任务实得 + BillTypeJobCancelOverdue = 12 //任务过期或取消 + BillTypeJobAuditUnPassWithCancelOverdue = 13 //任务不通过时,任务已取消或过期 + BillTypeSpJob = 14 //特殊任务扣除 + BillTypeDivide = 15 //群员做任务分成 + BillTypeJobDivide = 16 //做任务实得(被扣除分成后) + BillTypeDropShipping = 17 //一件代发订单扣除 + BillTypeDropShippingDeposit = 18 //一件代发保证金 + BillTypeUnionShare = 19 //联盟任务分成 + + BillTypeMember = 20 //开通会员 + + BillTypeQuitGroup = 30 //退群 + + BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款 + + BillTypeCash = 8 //提现 + BillTypeInvest = 6 //充值 +) + +var ( + BillTypeNames = map[int]string{ + BillTypeDeposit: "发布任务", + BillTypeJob: "做任务实得", + BillTypeJobCancelOverdue: "任务过期或取消", + BillTypeJobAuditUnPassWithCancelOverdue: "任务不通过时,任务已取消或过期", + BillTypeSpJob: "特殊任务扣除", + BillTypeDivide: "群员做任务分成", + BillTypeJobDivide: "做任务实得(被扣除分成后)", + BillTypeDropShipping: "一件代发订单收入/扣除", + BillTypeDropShippingDeposit: "一件代发保证金", + BillTypeMember: "开通会员", + BillTypeQuitGroup: "退群", + BillTypeJdWaybillOverWeight: "京东物流超重扣款", + BillTypeCash: "提现", + BillTypeInvest: "充值", + } +) + +//账单收入表 +type BillIncome struct { + ModelIDCUL + + BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + Type int `json:"type"` //收入类型 + IncomePrice int `json:"incomePrice"` //收入金额 +} + +func (v *BillIncome) TableIndex() [][]string { + return [][]string{ + []string{"BillID"}, + []string{"CreatedAt"}, + } +} + +//账单支出表 +type BillExpend struct { + ModelIDCUL + + BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + Type int `json:"type"` //支出类型 + ExpendPrice int `json:"expendPrice"` //支出金额 +} + +func (v *BillExpend) TableIndex() [][]string { + return [][]string{ + []string{"BillID"}, + []string{"CreatedAt"}, + } +} + +//用户账单表 +type UserBill struct { + ModelIDCULD + + BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID + UserID string `orm:"column(user_id)" json:"userID"` //用户ID + AccountBalance int `json:"accountBalance"` //账户余额 +} + +func (v *UserBill) TableUnique() [][]string { + return [][]string{ + []string{"UserID"}, + } +} + +func (v *UserBill) TableIndex() [][]string { + return [][]string{ + []string{"BillID"}, + []string{"CreatedAt"}, + []string{"AccountBalance"}, + } +} + +type UnionOrderSettle struct { + ModelIDCUL + + BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID + VendorID int `orm:"column(vendor_id)" json:"vendorID"` //平台ID + Issue int `json:"issue"` //期数 + EarningPrice int `json:"earningPrice"` //结算金额 + OrderCount int `json:"orderCount"` //当期有效推广订单数量 + Comment string `json:"comment"` //备注 +} + +func (v *UnionOrderSettle) TableUnique() [][]string { + return [][]string{ + []string{"BillID", "VendorID", "Issue"}, + } +} diff --git a/business/model/dao/dao_bill.go b/business/model/dao/dao_bill.go new file mode 100644 index 000000000..499d803b1 --- /dev/null +++ b/business/model/dao/dao_bill.go @@ -0,0 +1,131 @@ +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 +} diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go new file mode 100644 index 000000000..5dff490b7 --- /dev/null +++ b/business/model/dao/dao_job.go @@ -0,0 +1,582 @@ +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 +} diff --git a/business/model/job.go b/business/model/job.go new file mode 100644 index 000000000..d0933fde9 --- /dev/null +++ b/business/model/job.go @@ -0,0 +1,340 @@ +package model + +import ( + "time" + + "git.rosy.net.cn/baseapi/platformapi/txcloudapi" +) + +const ( + JobStatusDoing = 0 //正在进行中 + JobStatusFinished = 1 //任务所有都被完成 + JobStatusFailed = -1 //任务发布失败 + JobStatusOverdue = -2 //任务过期 + + JobLimitCountTypePO = 1 //每人一次 + JobLimitCountTypePDO = 2 //每人每天一次 + JobLimitCountTypePWO = 3 //每人每周一次 + JobLimitCountTypeNoLimit = 4 //不限制 + + JobOrderStatusSpec = 1 //特殊状态(联盟任务) + JobOrderStatusAccept = 5 + JobOrderStatusWaitAudit = 10 + JobOrderStatusAuditPass = 15 + JobOrderStatusAuditUnPass = 20 + JobOrderStatusFinish = 110 + JobOrderStatusCancel = 115 + + JobTimerTypeAccept = 1 //接受任务 + JobTimerTypeSubmit = 2 //交任务 + JobTimerTypeDropShipping = 3 //一件代发限时发货 + + JobTimerStatusWait = 0 //正在进行 + JobTimerStatusFinish = 1 //定时任务已完成 + + JobTypeNormal = 0 //普通任务 + JobTypeMtMember = 1 //美团会员任务 + JobTypeJdDelivery = 2 //京东快递任务 + JobTypeOther = 3 //其他任务(可能是存储信息用的 + + JobCashbackPrice = 1 //返现类型固定返现 + JobCashbackPercentage = 2 //返现类型比例返现 + + JobCategoryIDwmtg = 3 //任务类型外卖推广 + JobCategoryIDOther = 4 //其他任务类型 + JobCategoryIDDropShipping = 5 //一件代发 + JobCategoryIDUnion = 6 //联盟任务 + + JobSpanTop = 1 //置顶 + JobSpanRecommend = 2 //推荐 + + JobCountrywideCode = 999 +) + +const ( + /*消费类型*/ + ConsumeTypePublishJob = 1 //发任务 + ConsumeTypeMember = 2 //充会员 + ConsumeTypeDelivery = 3 //发快递 +) + +var ( + DeliveryStatusName = map[int]string{ + OrderStatusNew: "上门取件中", + OrderStatusDelivering: "配送中", + OrderStatusFinished: "已妥投", + OrderStatusCanceled: "已取消", + } + + CashbackName = map[int]string{ + JobCashbackPrice: "固定返现", + JobCashbackPercentage: "比例返现", + } + + ConsumeName = map[int]string{ + ConsumeTypePublishJob: "发任务", + ConsumeTypeMember: "充会员", + ConsumeTypeDelivery: "发快递", + } + + TxWaybillNames = map[int]string{ + txcloudapi.StatusErr: "单号或代码错误", + txcloudapi.StatusNull: "暂无轨迹", + txcloudapi.StatusAccept: "快递收件", + txcloudapi.StatusDelivering: "在途中", + txcloudapi.StatusFinished: "已签收", + txcloudapi.StatusProblem: "问题件 (派件不成功或要求择日派送)", + txcloudapi.StatusException: "疑难件(收件人拒绝签收,地址有误或不能送达派送区域,收费等原因无法正常派送)", + txcloudapi.StatusFailed: "退件签收", + } +) + +type Job struct { + ModelIDCULD + + UserID string `orm:"column(user_id)" json:"userID"` //发布人ID + JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"` //任务类型 + JobSpanTop int `json:"jobSpanTop"` //置顶标签 + TopSeq int `json:"topSeq"` //置顶顺序 + JobSpanRecmd int `json:"jobSpanRecmd"` //推荐标签 + RecmdSeq int `json:"recmdSeq"` //推荐顺序 + Title string `orm:"size(255)" json:"title"` //任务标题 + Content string `orm:"size(500)" json:"content"` //任务内容 + Count int `json:"count"` //任务数量 + SurplusCount int `json:"surplusCount"` //剩余数量 + AvgPrice int `json:"avgPrice"` //单个任务金额或预估金额 + DropShippingSkuPrice int `json:"dropShippingSkuPrice"` //一件代发任务商品价格 + Percentage int `json:"percentage"` //如果是比例返现,返现比例 + CashbackType int `json:"cashbackType"` //返现方式,1为固定返现,2为比例返现 + TotalPrice int `json:"totalPrice"` //任务总金额 + Status int `json:"status"` //任务状态 + Address string `orm:"size(500)" json:"address"` //门店地址 + Lng int `json:"lng"` //乘了10的6次方 + Lat int `json:"lat"` //乘了10的6次方 + JobLng float64 `json:"jobLng"` //任务发布地址 + JobLat float64 `json:"jobLat"` //任务发布地址 + JobCityCode int `json:"jobCityCode"` //任务所属城市,999代表全国 + DropShippingAt int `json:"dropShippingAt"` //承诺一件代发几天内发货,小时数 + JobLimitAt int `json:"jobLimitAt"` //任务限时完成小时数 + AuditLimitAt int `json:"auditLimitAt"` //任务审核限时小时数 + FinishedAt *time.Time `orm:"null" json:"finishedAt"` //接单截止日期 + LimitCountType int `json:"limitCountType"` //任务限次类型,1为每人一次,2为每人每天一次,3为每人每周一次,4为不限制 + VendorID int `orm:"column(vendor_id)" json:"vendorID"` //推广平台 + StoreURL string `orm:"column(store_url)" json:"storeURL"` //门店链接 + SkuURL string `orm:"column(sku_url)" json:"skuURL"` //商品优惠券链接 + Type int `json:"type"` //任务类型,0为普通任务,1为特殊任务 + BrowseCount int `json:"browseCount"` //任务浏览量,点一下加一下 + UnionImg string `json:"unionImg"` //联盟任务分享链接的背景图 + UnionQrcodePosition string `json:"unionQrcodePosition"` //联盟任务分享链接的二维码图的方位 + UnionActID string `orm:"column(union_act_id)" json:"unionActID"` //联盟任务ID + // JobSteps []*JobStep `orm:"-" json:"jobSteps"` + // JobImgs []*JobImg `orm:"-" json:"jobImgs"` +} + +func (v *Job) TableIndex() [][]string { + return [][]string{ + []string{"UserID"}, + []string{"CreatedAt"}, + } +} + +type JobExt struct { + FinishedAtStr string `json:"finishedAtStr"` //接单截止日期 + Job + JobSteps []*JobStep `orm:"-" json:"jobSteps"` + JobImgs []*JobImg `orm:"-" json:"jobImgs"` +} + +type JobImg struct { + ModelIDCUL + + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + Img string `orm:"size(500)" json:"img"` //图片 +} + +func (v *JobImg) TableIndex() [][]string { + return [][]string{ + []string{"JobID"}, + } +} + +type JobCategory struct { + ModelIDCULD + + Name string `orm:"size(48)" json:"name"` //类型名称 + Img string `orm:"size(500)" json:"img"` //类型图片 +} + +func (v *JobCategory) TableUnique() [][]string { + return [][]string{ + []string{"Name"}, + } +} + +type JobStep struct { + ModelIDCULD + + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + StepCount int `json:"stepCount"` //步骤数 + Content string `orm:"size(500)" json:"content"` //步骤内容 + Img string `orm:"size(500)" json:"img"` //步骤图片 + Type int `json:"type"` //步骤类型,1为任务步骤,2为收集信息 +} + +func (v *JobStep) TableIndex() [][]string { + return [][]string{ + []string{"JobID"}, + } +} + +type JobOrder struct { + ModelIDCUL + + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + JobOrderID int64 `orm:"column(job_order_id)" json:"jobOrderID"` //任务订单号 + UserID string `orm:"column(user_id)" json:"userID"` //接任务人ID + Status int `json:"status"` //任务订单状态,接单,待审核,已审核,已结算等 + SubmitAuditAt time.Time `json:"submitAuditTime"` //提交审核日期 + AuditAt time.Time `json:"auditAt"` //审核日期 + Content string `josn:"content"` //任务审核内容 + Imgs string `json:"imgs"` //任务审核图片 + Comment string `json:"comment"` //审核理由 + UserActualPrice int `json:"userActualPrice"` //用户订单实际支付(用户自填) + + DropShippingCount int `json:"dropShippingCount"` //一件代发购买商品数量 + DropShippingDeliveryID int `orm:"column(drop_shipping_delivery_id)" json:"dropShippingDeliveryID"` + DropShippingName string `json:"dropShippingName"` + DropShippingMobile string `json:"dropShippingMobile"` + DropShippingAddress string `json:"dropShippingAddress"` + DropShippingDetailAddress string `json:"dropShippingDetailAddress"` + DropShippingLng float64 `json:"dropShippingLng"` + DropShippingLat float64 `json:"dropShippingLat"` + DropShippingAutoAddress string `json:"dropShippingAutoAddress"` + DropShippingCityCode int `json:"dropShippingCityCode"` + DropShippingDistrictCode int `json:"dropShippingDistrictCode"` + VendorWaybillID string `orm:"column(vendor_waybill_id)" json:"vendorWaybillID"` //运单号 + WaybillInfo string `orm:"type(text)" json:"waybillInfo"` //物流信息 + WaybillQueryTime time.Time `json:"waybillQueryTime"` //上次查询时间 + WaybillStatus int `json:"waybillStatus"` //运单状态(一件代发) + DropShippingConfirmTime time.Time `orm:"type(datetime);null" json:"dropShippingConfirmTime"` //确认收货时间 + DropShippingConfirmUser string `json:"dropShippingConfirmUser"` //确认收货人 +} + +func (v *JobOrder) TableIndex() [][]string { + return [][]string{ + []string{"JobID"}, + []string{"JobOrderID"}, + []string{"UserID"}, + } +} + +type JobTimer struct { + ModelIDCUL + + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + JobOrderID int64 `orm:"column(job_order_id)" json:"jobOrderID"` //任务订单号 + Type int `json:"type"` //定时任务类型,1为接受任务,2为提交审核 + Status int `json:"status"` //定时任务的状态,0表示正在进行,1表示已经结束 + StartAt time.Time `json:"startAt"` //定时任务开始时间 + LimitAt int `json:"limitAt"` //定时任务时长(小时数) +} + +func (v *JobTimer) TableIndex() [][]string { + return [][]string{ + []string{"JobID"}, + []string{"JobOrderID"}, + } +} + +type JobSpan struct { + ModelIDCULD + + JobID int `orm:"column(job_id)" json:"jobID"` //任务ID + EndAt *time.Time `json:"endAt"` //生效时间范围 + SpanType int `json:"spanType"` //1为置顶,2为推荐 +} + +func (v *JobSpan) TableIndex() [][]string { + return [][]string{ + []string{"JobID", "DeletedAt"}, + } +} + +type MtMember struct { + ModelIDCULD + + URL string `orm:"column(url)" json:"url"` //网址 + ExpiryDate time.Time `json:"expiryDate"` //有效期 + ShortLink string `json:"shortLink"` //密钥? +} + +func (v *MtMember) TableUnique() [][]string { + return [][]string{ + []string{"URL"}, + } +} + +func (v *MtMember) TableIndex() [][]string { + return [][]string{ + []string{"DeletedAt"}, + } +} + +type StationInfo struct { + ModelIDCUL + + StationID string `orm:"column(station_id)" json:"stationID"` + StationName string `json:"stationName"` + ProvinceName string `json:"provinceName"` + ProvinceID int `orm:"column(province_id)" json:"provinceID"` + CityName string `json:"cityName"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Location string `json:"location"` + StarNum string `json:"starNum"` + Phone string `json:"phone"` + StationPic string `json:"stationPic"` + StationBannerPic string `json:"stationBannerPic"` + Prices string `orm:"type(text)" json:"prices"` + Adverts string `orm:"type(text)" json:"adverts"` + District string `json:"district"` + CityID int `orm:"column(city_id)" json:"cityID"` + StationType int `json:"stationType"` + Distance float64 `json:"distance"` + OilInfo []*OilInfo `orm:"-" json:"oilInfo"` +} + +func (v *StationInfo) TableUnique() [][]string { + return [][]string{ + []string{"StationID"}, + } +} + +func (v *StationInfo) TableIndex() [][]string { + return [][]string{ + []string{"CityID", "ProvinceID"}, + } +} + +type OilInfo struct { + OilID string `json:"oilId"` + StationPrice string `json:"stationPrice"` + OilType string `json:"oilType"` + DiscountPrice string `json:"discountPrice"` + CountryPrice string `json:"countryPrice"` + OilgunCodes []string `json:"oilgunCodes"` + OilCode string `json:"oilCode"` +} + +type AddressDistinguish struct { + ModelIDCUL + + Address string `json:"address"` + Info string `orm:"type(text)" json:"info"` +} + +func (v *AddressDistinguish) TableUnique() [][]string { + return [][]string{ + []string{"Address"}, + } +}