1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693 |
- package db
- import (
- "context"
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "time"
- "youngee_m_api/consts"
- "youngee_m_api/model/common_model"
- "youngee_m_api/model/gorm_model"
- "youngee_m_api/model/http_model"
- "youngee_m_api/util"
- "github.com/caixw/lib.go/conv"
- "github.com/sirupsen/logrus"
- "gorm.io/gorm"
- )
- func GetWithdrawRecords(ctx context.Context, pageSize, pageNum int32, req *http_model.WithdrawalRecordsRequest, condition *common_model.WithdrawRecordsCondition) (*http_model.WithdrawalRecordsPreview, error) {
- db := GetReadDB(ctx)
- var withdrawRecords []*gorm_model.YounggeeWithdrawRecord
- db = db.Debug().Model(gorm_model.YounggeeWithdrawRecord{})
- conditionType := reflect.TypeOf(condition).Elem()
- conditionValue := reflect.ValueOf(condition).Elem()
- for i := 0; i < conditionType.NumField(); i++ {
- field := conditionType.Field(i)
- tag := field.Tag.Get("condition")
- value := conditionValue.FieldByName(field.Name)
- if tag == "submit_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("submit_at like '%s%%'", value.Interface()))
- }
- if tag == "withdraw_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("withdraw_at like '%s%%'", value.Interface()))
- }
- if !util.IsBlank(value) && tag != "submit_at" && tag != "withdraw_at" {
- db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
- }
- }
- if req.TalentName != "" {
- fmt.Println("TalentName:", req.TalentName)
- db1 := GetReadDB(ctx)
- var talentId string
- db1.Model(gorm_model.YoungeeTalentInfo{}).Select("id").Where(fmt.Sprintf("talent_wx_nickname like '%%%s%%'", req.TalentName)).Find(&talentId)
- db = db.Where("talent_id = ?", talentId)
- }
- // 查询总数
- var total int64
- if err := db.Count(&total).Error; err != nil {
- logrus.WithContext(ctx).Errorf("[GetWithdrawRecords] error query mysql total, err:%+v", err)
- return nil, err
- }
- // 查询该页数据
- limit := pageSize
- offset := pageSize * pageNum // assert pageNum start with 0
- err := db.Order("submit_at").Limit(int(limit)).Offset(int(offset)).Find(&withdrawRecords).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[GetWithdrawRecords] error query mysql limit, err:%+v", err)
- return nil, err
- }
- var talentIds []string
- for _, withdrawRecord := range withdrawRecords {
- talentIds = append(talentIds, withdrawRecord.TalentID)
- }
- talentIdToTalentInfoMap := make(map[string]gorm_model.YoungeeTalentInfo)
- for _, talentId := range talentIds {
- db1 := GetReadDB(ctx)
- talentInfo := gorm_model.YoungeeTalentInfo{}
- db1.Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId).Find(&talentInfo)
- talentIdToTalentInfoMap[talentId] = talentInfo
- }
- var withdrawRecordsDatas []*http_model.WithdrawalRecordsData
- for _, withdrawRecord := range withdrawRecords {
- withdrawRecordsData := new(http_model.WithdrawalRecordsData)
- withdrawRecordsData.WithdrawId = withdrawRecord.WithdrawID
- withdrawRecordsData.TalentId = withdrawRecord.TalentID
- withdrawRecordsData.TalentName = talentIdToTalentInfoMap[withdrawRecord.TalentID].TalentWxNickname
- withdrawRecordsData.WithdrawAmount = float32(withdrawRecord.WithdrawAmount)
- withdrawRecordsData.AmountPayable = float32(withdrawRecord.AmountPayable)
- withdrawRecordsData.ReceiveInfo = withdrawRecord.ReceiveInfo
- withdrawRecordsData.BankType = withdrawRecord.BankType
- withdrawRecordsData.Phone = talentIdToTalentInfoMap[withdrawRecord.TalentID].TalentPhoneNumber
- withdrawRecordsData.SubmitAt = conv.MustString(withdrawRecord.SubmitAt, "")[0:19]
- withdrawRecordsData.WithdrawAt = conv.MustString(withdrawRecord.WithdrawAt, "")[0:19]
- withdrawRecordsDatas = append(withdrawRecordsDatas, withdrawRecordsData)
- }
- var withdrawRecordsPreview http_model.WithdrawalRecordsPreview
- withdrawRecordsPreview.WithdrawalRecordsData = withdrawRecordsDatas
- withdrawRecordsPreview.Total = total
- return &withdrawRecordsPreview, nil
- }
- func GetWithdrawRecord(ctx context.Context, req *http_model.GetWithdrawalRecordRequest) (*http_model.WithdrawalRecordPreview, error) {
- db := GetReadDB(ctx)
- //fmt.Println("talentId:", req.TalentId)
- var withdrawRecords []*gorm_model.YounggeeWithdrawRecord
- db = db.Debug().Model(gorm_model.YounggeeWithdrawRecord{}).Where("talent_id = ? AND status = ?", req.TalentId, 2).Find(&withdrawRecords)
- var withdrawRecordsPreview http_model.WithdrawalRecordPreview
- var withdrawRecordsDatas []*http_model.WithdrawalRecordData
- for _, withdrawRecord := range withdrawRecords {
- withdrawRecordData := new(http_model.WithdrawalRecordData)
- withdrawRecordData.WithdrawAmount = float32(withdrawRecord.WithdrawAmount)
- withdrawRecordData.WithdrawAt = conv.MustString(withdrawRecord.WithdrawAt, "")[0:19]
- withdrawRecordsDatas = append(withdrawRecordsDatas, withdrawRecordData)
- }
- withdrawRecordsPreview.WithdrawalRecordData = withdrawRecordsDatas
- return &withdrawRecordsPreview, nil
- }
- func GetWithdrawNums(ctx context.Context) (*http_model.WithdrawNums, error) {
- var withdrawNums int64
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("status = 1").Count(&withdrawNums).Error
- if err != nil {
- return nil, err
- }
- WithdrawNums := new(http_model.WithdrawNums)
- WithdrawNums.WithdrawNums = int(withdrawNums)
- return WithdrawNums, err
- }
- func GetRechargeValue(ctx context.Context, request http_model.GetRechargeValueRequest) (*http_model.RechargeValue, error) {
- var rechargeValue float64
- db := GetReadDB(ctx)
- var rechargelist []gorm_model.YounggeeRechargeRecord
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("status = ?", request.Status).Find(rechargelist).Error
- if err != nil {
- return nil, err
- }
- for _, recharge := range rechargelist {
- rechargeValue += recharge.RechargeAmount
- }
- RechargeValue := new(http_model.RechargeValue)
- RechargeValue.RechargeValue = rechargeValue
- return RechargeValue, err
- }
- func GetInvoiceValue(ctx context.Context, request http_model.GetInvoiceValueRequest) (*http_model.InvoiceValue, error) {
- var invoicevalue float64
- db := GetReadDB(ctx)
- var invoicelist []gorm_model.YounggeeInvoiceRecord
- err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("status = ?", request.Status).Find(invoicelist).Error
- if err != nil {
- return nil, err
- }
- for _, invoice := range invoicelist {
- invoicevalue += invoice.InvoiceAmount
- }
- InvoiceValue := new(http_model.InvoiceValue)
- InvoiceValue.InvoiceValue = invoicevalue
- return InvoiceValue, err
- }
- func GetSupplierWithdrawPrevalue(ctx context.Context, request http_model.GetSupplierWithdrawPrevalueRequest) (*http_model.WithdrawValue, error) {
- var withdrawvalue float64
- db := GetReadDB(ctx)
- var withdrawlist []gorm_model.YounggeeSupplierWithdraw
- // 获取所有符合条件的发票
- err := db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("withdraw_status =2").Find(&withdrawlist).Error
- if err != nil {
- return nil, err
- }
- for _, withdraw := range withdrawlist {
- withdrawvalue += withdraw.WithdrawAmount
- }
- return &http_model.WithdrawValue{
- withdrawvalue,
- }, err
- }
- func GetTalentWithdrawPrevalue(ctx context.Context, request http_model.GetTalentWithdrawPrevalueRequest) (*http_model.TalentWithdrawValue, error) {
- var withdrawvalue float64
- db := GetReadDB(ctx)
- var withdrawlist []gorm_model.YounggeeWithdrawRecord
- // 获取所有符合条件的发票
- err := db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("withdraw_status =1").Find(&withdrawlist).Error
- if err != nil {
- return nil, err
- }
- for _, withdraw := range withdrawlist {
- withdrawvalue += withdraw.WithdrawAmount
- }
- return &http_model.TalentWithdrawValue{
- withdrawvalue,
- }, err
- }
- func GetWithDrawInfo(ctx context.Context, request http_model.GetWithDrawInfoRequest) (*http_model.WithDrawInfoResponse, error) {
- db := GetReadDB(ctx)
- var withdrawinfo gorm_model.YounggeeWithdrawRecord
- fmt.Println(request.Withdrawid)
- err := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("withdraw_id = ?", request.Withdrawid).Find(&withdrawinfo).Error
- if err != nil {
- return nil, err
- }
- res := &http_model.WithDrawInfoResponse{
- Operator: withdrawinfo.Name,
- WithdrawAmount: withdrawinfo.WithdrawAmount,
- AmountPayable: withdrawinfo.AmountPayable,
- }
- return res, nil
- }
- func GetWithdrawValue(ctx context.Context, request http_model.GetWithdrawValueRequest) (*http_model.ALlWithdrawValue, error) {
- var withdrawvalue float64
- db := GetReadDB(ctx)
- var withdrawlist []gorm_model.YounggeeWithdrawRecord
- // 获取所有符合条件的发票
- err := db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("withdraw_status =2").Find(&withdrawlist).Error
- if err != nil {
- return nil, err
- }
- for _, withdraw := range withdrawlist {
- withdrawvalue += withdraw.WithdrawAmount
- }
- var swithdrawlist []gorm_model.YounggeeSupplierWithdraw
- // 获取所有符合条件的发票
- err = db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("withdraw_status =3").Find(&swithdrawlist).Error
- if err != nil {
- return nil, err
- }
- for _, withdraw := range withdrawlist {
- withdrawvalue += withdraw.WithdrawAmount
- }
- return &http_model.ALlWithdrawValue{
- withdrawvalue,
- }, err
- }
- func GetSupplierInvoiceValue(ctx context.Context, request http_model.GetSupplierInvoiceValueRequest) (*http_model.SupplierInvoiceValue, error) {
- var invoicevalue float64
- db := GetReadDB(ctx)
- var invoicelist []gorm_model.YounggeeSupplierInvoice
- // 获取所有符合条件的发票
- err := db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("status = ?", request.Status).Find(&invoicelist).Error
- if err != nil {
- return nil, err
- }
- // 收集所有的 TaskIDs
- var taskIDList []int
- for _, invoice := range invoicelist {
- TaskIDs := strings.Split(invoice.IncomeIds, ",")
- for _, taskId := range TaskIDs {
- // 将 taskId 转换为 int 并添加到 taskIDList 中
- if id, err := strconv.Atoi(taskId); err == nil {
- taskIDList = append(taskIDList, id)
- }
- }
- }
- // 批量查询所有相关的收入数据
- var supplierIncome []gorm_model.YounggeeSupplierIncome
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id IN ?", taskIDList).Find(&supplierIncome).Error
- if err != nil {
- return &http_model.SupplierInvoiceValue{}, err
- }
- // 将查询到的 SupplierIncome 存入 map,以便快速查找
- incomeMap := make(map[int]gorm_model.YounggeeSupplierIncome)
- for _, income := range supplierIncome {
- incomeMap[income.IncomeId] = income
- }
- // 根据每个发票的 IncomeIds 查找对应的收入数据,并累加 SupplierChargeActual
- for _, invoice := range invoicelist {
- TaskIDs := strings.Split(invoice.IncomeIds, ",")
- for _, taskId := range TaskIDs {
- // 将 taskId 转换为 int
- if id, err := strconv.Atoi(taskId); err == nil {
- if income, exists := incomeMap[id]; exists {
- invoicevalue += income.SupplierChargeActual
- }
- }
- }
- }
- // 返回最终的发票值
- InvoiceValue := new(http_model.SupplierInvoiceValue)
- InvoiceValue.InvoiceValue = invoicevalue
- return InvoiceValue, nil
- }
- func GetInvoiceNums(ctx context.Context) (*http_model.InvoiceNums, error) {
- var invoiceNums int64
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("status = 1").Count(&invoiceNums).Error
- if err != nil {
- return nil, err
- }
- InvoiceNums := new(http_model.InvoiceNums)
- InvoiceNums.InvoiceNums = int(invoiceNums)
- return InvoiceNums, err
- }
- func GetRechargeNums(ctx context.Context) (*http_model.RechargeNums, error) {
- var rechargeNums int64
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("status = 1").Count(&rechargeNums).Error
- if err != nil {
- return nil, err
- }
- RechargeNums := new(http_model.RechargeNums)
- RechargeNums.RechargeNums = rechargeNums
- return RechargeNums, err
- }
- func AcceptRecharge(ctx context.Context, req http_model.AcceptRechargeRequest) (*http_model.AcceptRechargeData, error) {
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id=?", req.Id).Updates(map[string]interface{}{"status": 2, "agree_at": time.Now()}).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call AcceptRecharge error,err:%+v", err)
- return nil, err
- }
- res := &http_model.AcceptRechargeData{
- Id: req.Id,
- }
- return res, nil
- }
- func RefuseRecharge(ctx context.Context, req http_model.RefuseRechargeRequest) (*http_model.RefuseRechargeData, error) {
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id=?", req.Id).Updates(map[string]interface{}{"status": 3, "refuse_at": time.Now(), "fail_reason": req.FailReason}).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call RefuseRecharge error,err:%+v", err)
- return nil, err
- }
- res := &http_model.RefuseRechargeData{
- Id: req.Id,
- }
- return res, nil
- }
- func GetRechargeInfo(ctx context.Context, req http_model.GetRechargeInfoRequest) (*http_model.RechargeInfoResponse, error) {
- db := GetReadDB(ctx)
- var rechargeinfo gorm_model.YounggeeRechargeRecord
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).First(&rechargeinfo).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call GetRechargeInfo error,err:%+v", err)
- return nil, err
- }
- var operator string
- enterprise := gorm_model.Enterprise{}
- result := db.Where(gorm_model.Enterprise{EnterpriseID: rechargeinfo.EnterpriseID}).First(&enterprise)
- if result.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
- return nil, result.Error
- }
- if rechargeinfo.SubAccountID != 0 {
- subaccountinfo := gorm_model.YounggeeSubAccount{}
- userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: rechargeinfo.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
- if userResult.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
- return nil, userResult.Error
- }
- operator = subaccountinfo.SubAccountName
- } else {
- operator = enterprise.BusinessName
- }
- res := &http_model.RechargeInfoResponse{
- RechargeAmount: rechargeinfo.RechargeAmount,
- Operator: operator,
- MainAccount: enterprise.BusinessName,
- }
- return res, nil
- }
- func GetPreRechargeList(ctx context.Context, req http_model.GetPreRechargeListRequest) (*http_model.PreRechargeListData, error) {
- db := GetReadDB(ctx)
- // 获取分页参数
- page := req.PageNum
- pageSize := req.PageSize
- if page < 1 {
- page = 1
- }
- if pageSize < 1 {
- pageSize = 10 // 设置默认每页记录数为 10
- }
- var prerechargelist []gorm_model.YounggeeRechargeRecord
- var total int64
- // 先查询当前页的数据,不考虑 "Others" 筛选条件
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).
- Where("status = ?", req.Status).
- Offset((page - 1) * pageSize). // 计算偏移量
- Limit(pageSize). // 设置每页限制
- Find(&prerechargelist).Error
- if err != nil {
- return &http_model.PreRechargeListData{}, err
- }
- // 在查询到的数据上进行筛选 (比如 "Others" 筛选条件)
- filteredList := make([]gorm_model.YounggeeRechargeRecord, 0)
- for _, recharge := range prerechargelist {
- var operator string
- enterprise := gorm_model.Enterprise{}
- result := db.Where(gorm_model.Enterprise{EnterpriseID: recharge.EnterpriseID}).First(&enterprise)
- if result.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
- return nil, result.Error
- }
- if recharge.SubAccountID != 0 {
- subaccountinfo := gorm_model.YounggeeSubAccount{}
- userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: recharge.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
- if userResult.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
- return nil, userResult.Error
- }
- operator = subaccountinfo.SubAccountName
- } else {
- operator = enterprise.BusinessName
- }
- // 进行 "Others" 筛选条件
- if req.Others != "" {
- if operator != req.Others && req.Others != recharge.RechargeID {
- continue
- }
- }
- // 满足筛选条件的记录添加到 filteredList
- filteredList = append(filteredList, recharge)
- }
- // 计算筛选后的总记录数
- total = int64(len(filteredList))
- // 构建返回结果
- rechargePointers := make([]*http_model.PreRechargeListResponse, 0, len(filteredList))
- for _, recharge := range filteredList {
- var operator string
- enterprise := gorm_model.Enterprise{}
- result := db.Where(gorm_model.Enterprise{EnterpriseID: recharge.EnterpriseID}).First(&enterprise)
- if result.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
- return nil, result.Error
- }
- if recharge.SubAccountID != 0 {
- subaccountinfo := gorm_model.YounggeeSubAccount{}
- userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: recharge.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
- if userResult.Error != nil {
- logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
- return nil, userResult.Error
- }
- operator = subaccountinfo.SubAccountName
- } else {
- operator = enterprise.BusinessName
- }
- // 构建返回响应数据
- response := &http_model.PreRechargeListResponse{
- ID: recharge.RechargeID,
- EnterPrise: enterprise.BusinessName,
- Operator: operator,
- RechargeAmount: recharge.RechargeAmount,
- RechargeMethod: recharge.RechargeMethod,
- TransferVoucherUrl: recharge.TransferVoucherUrl,
- Phone: recharge.Phone,
- CommitAt: recharge.CommitAt.Format("2006-01-02 15:04:05"),
- ConfirmAt: recharge.ConfirmAt.Format("2006-01-02 15:04:05"),
- RefuseAt: recharge.RefuseAt.Format("2006-01-02 15:04:05"),
- FailReason: recharge.FailReason,
- }
- rechargePointers = append(rechargePointers, response)
- }
- return &http_model.PreRechargeListData{
- PreRechargeListinfo: rechargePointers,
- Total: total, // 返回筛选后的总记录数
- }, nil
- }
- func GetRechargenums(db *gorm.DB, status int) (int64, error) {
- query := db.Model(&gorm_model.YounggeeRechargeRecord{}).Where("status = ?", status)
- // 计算总数
- var total int64
- if err := query.Count(&total).Error; err != nil {
- return 0, err
- }
- return total, nil
- }
- func GetRechargeCount(ctx context.Context) (*http_model.RechargeCountResponse, error) {
- db := GetReadDB(ctx)
- pre, _ := GetRechargenums(db, 1)
- ing, _ := GetRechargenums(db, 2)
- ed, _ := GetRechargenums(db, 3)
- res := &http_model.RechargeCountResponse{
- PreRechargeNums: pre,
- RechargeNums: ing,
- FailNums: ed,
- }
- return res, nil
- }
- func GetWithdrawnums(db *gorm.DB, status int) (int64, error) {
- query := db.Model(&gorm_model.YounggeeWithdrawRecord{}).Where("status = ?", status)
- // 计算总数
- var total int64
- if err := query.Count(&total).Error; err != nil {
- return 0, err
- }
- return total, nil
- }
- func GetWithdrawCount(ctx context.Context) (*http_model.WithdrawCountResponse, error) {
- db := GetReadDB(ctx)
- pre, _ := GetWithdrawnums(db, 1)
- ing, _ := GetWithdrawnums(db, 2)
- ed, _ := GetWithdrawnums(db, 3)
- res := &http_model.WithdrawCountResponse{
- PreWithdrawNums: pre,
- WithdrawNums: ing,
- FailNums: ed,
- }
- return res, nil
- }
- func GetTalentWithdrawList(ctx context.Context, req *http_model.GetTalentWithdrawListRequest) (*http_model.TalentWithdrawListData, error) {
- db := GetReadDB(ctx)
- pageSize := req.PageSize
- var withdrawlist []gorm_model.YounggeeWithdrawRecord
- var total int64
- // 计算总记录数
- query := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("status = ?", req.Status)
- if req.Others != "" {
- query = query.Where("withdraw_id LIKE ? OR Name LIKE ?", "%"+req.Others+"%", "%"+req.Others+"%")
- }
- // 添加 during 条件(时间范围筛选)
- if req.During != "" {
- // 解析 during 参数为时间
- startTime, err := time.Parse("2006-01-02", req.During)
- if err != nil {
- return nil, fmt.Errorf("invalid during format, expected 'YYYY-MM-DD'")
- }
- endTime := startTime.Add(24 * time.Hour).Add(-1 * time.Second) // 当天的 23:59:59
- // 添加时间范围条件
- var timeField string
- switch req.Status {
- case 1:
- timeField = "submit_at"
- case 2:
- timeField = "withdraw_at"
- case 3:
- timeField = "reject_at"
- }
- query = query.Where(
- fmt.Sprintf("%s BETWEEN ? AND ?", timeField), // 字段名安全拼接
- startTime,
- endTime,
- )
- }
- if err := query.Count(&total).Error; err != nil {
- return nil, err
- }
- // 添加分页逻辑
- if pageSize == 0 {
- pageSize = 10
- }
- pageNum := req.PageNum
- if pageNum == 0 {
- pageNum = 1
- }
- offset := (pageNum - 1) * pageSize
- if err := query.Offset(offset).Limit(pageSize).Find(&withdrawlist).Error; err != nil {
- return nil, err
- }
- withdrawPointers := make([]*http_model.TalentWithdrawListResponse, 0, len(withdrawlist))
- for _, withdraw := range withdrawlist {
- response := &http_model.TalentWithdrawListResponse{
- WithdrawId: withdraw.WithdrawID,
- TalentId: withdraw.TalentID,
- WithdrawAmount: withdraw.WithdrawAmount,
- ActualAmount: withdraw.AmountPayable,
- ReajectAt: withdraw.RejectAt.Format("2006-01-02 15:04:05"),
- SubmitAt: withdraw.SubmitAt.Format("2006-01-02 15:04:05"),
- WithdrawAt: withdraw.WithdrawAt.Format("2006-01-02 15:04:05"),
- RejectReason: withdraw.RejectReason,
- Name: withdraw.Name,
- PhoneNumber: withdraw.PhoneNum,
- IdcardNumber: withdraw.IdcardNum,
- BankNumber: withdraw.BankNum,
- }
- withdrawPointers = append(withdrawPointers, response)
- }
- return &http_model.TalentWithdrawListData{
- TalentwithdrawList: withdrawPointers,
- Total: total,
- }, nil
- }
- func ConfirmWithdrawal(ctx context.Context, withdrawIdsStr string) (*http_model.ConfirmWithdrawalResponse, error) {
- // 分割 withdrawId 列表
- withdrawIds := strings.Split(withdrawIdsStr, ",")
- res := http_model.ConfirmWithdrawalResponse{
- WithdrawId: withdrawIdsStr,
- }
- if len(withdrawIds) == 0 {
- return &res, fmt.Errorf("empty withdrawIds list")
- }
- db := GetReadDB(ctx) // 使用统一的 DB 实例
- // 开启事务
- return &res, db.Transaction(func(tx *gorm.DB) error {
- // 1. 批量更新提现记录状态
- if err := tx.Model(&gorm_model.YounggeeWithdrawRecord{}).
- Where("withdraw_id IN (?)", withdrawIds).
- Updates(map[string]interface{}{
- "status": 2,
- "withdraw_at": time.Now(),
- }).Error; err != nil {
- return fmt.Errorf("批量更新提现记录失败: %v", err)
- }
- // 2. 获取所有提现记录的 IncomeIdList(保留重复项)
- var withdrawRecords []gorm_model.YounggeeWithdrawRecord
- if err := tx.Where("withdraw_id IN (?)", withdrawIds).
- Find(&withdrawRecords).Error; err != nil {
- return fmt.Errorf("查询提现记录失败: %v", err)
- }
- // 3. 收集所有 IncomeId(包含重复项)
- var rawIncomeIds []string
- talentAmountMap := make(map[string]float64) // talentID -> 总提现金额
- for _, record := range withdrawRecords {
- // 按原始顺序保留所有 IncomeId(含重复)
- ids := strings.Split(record.IncomeIdList, ",")
- rawIncomeIds = append(rawIncomeIds, ids...)
- // 累加提现金额
- talentAmountMap[record.TalentID] += record.WithdrawAmount
- }
- // 4. 更新所有 Income 记录状态(含重复项)
- if len(rawIncomeIds) > 0 {
- if err := tx.Model(&gorm_model.YounggeeTalentIncome{}).
- Where("id IN (?)", rawIncomeIds).
- Update("withdraw_status", 1).Error; err != nil {
- return fmt.Errorf("更新收入状态失败: %v", err)
- }
- }
- // 5. 查询所有 Income 记录详情(含重复项)
- var incomeList []gorm_model.YounggeeTalentIncome
- if err := tx.Where("id IN (?)", rawIncomeIds).
- Find(&incomeList).Error; err != nil {
- return fmt.Errorf("查询收入详情失败: %v", err)
- }
- // 6. 按类型收集所有任务ID(含重复项)
- type TaskRef struct {
- Type int
- TaskIDs []string
- }
- var taskRefs []TaskRef
- for _, income := range incomeList {
- var taskID string
- switch income.Type {
- case 1:
- taskID = income.SectaskID
- case 2:
- taskID = income.TaskID
- case 3:
- taskID = income.LocalTaskId
- default:
- continue
- }
- // 允许重复的 TaskID
- taskRefs = append(taskRefs, TaskRef{
- Type: income.Type,
- TaskIDs: []string{taskID},
- })
- }
- // 7. 批量更新任务状态(允许重复更新)
- for _, ref := range taskRefs {
- var model interface{}
- switch ref.Type {
- case 1:
- model = &gorm_model.YounggeeSecTaskInfo{}
- case 2:
- model = &gorm_model.YoungeeTaskInfo{}
- case 3:
- model = &gorm_model.YoungeeLocalTaskInfo{}
- default:
- continue
- }
- if err := tx.Model(model).
- Where("task_id IN (?)", ref.TaskIDs).
- Update("withdraw_status", 4).Error; err != nil {
- return fmt.Errorf("更新任务状态失败: %v", err)
- }
- }
- // 8. 更新人才账户金额
- for talentID, amount := range talentAmountMap {
- if err := tx.Model(&gorm_model.YoungeeTalentInfo{}).
- Where("id = ?", talentID).
- Updates(map[string]interface{}{
- "withdrawing": gorm.Expr("withdrawing - ?", amount),
- "withdrawed": gorm.Expr("withdrawed + ?", amount),
- }).Error; err != nil {
- return fmt.Errorf("更新人才账户失败: %v", err)
- }
- }
- return nil
- })
- }
- func RefuseTalentWithdrawal(ctx context.Context, req *http_model.RefuseTalentWithdrawalRequest) error {
- db := GetReadDB(ctx)
- // 获取撤回记录
- var withdrwainfo gorm_model.YounggeeWithdrawRecord
- err := db.Debug().Model(gorm_model.YounggeeWithdrawRecord{}).
- Where("withdraw_id = ?", req.WithdrawId).
- First(&withdrwainfo).Error // 使用 First 而不是 Updates 来查询数据
- if err != nil {
- logrus.WithContext(ctx).Errorf("[finance db] Query YounggeeWithdrawRecord error, err:%+v", err)
- return err
- }
- // 更新 YounggeeWithdrawRecord
- err = db.Debug().Model(gorm_model.YounggeeWithdrawRecord{}).
- Where("withdraw_id = ?", req.WithdrawId).
- Updates(gorm_model.YounggeeWithdrawRecord{
- Status: 3,
- RejectAt: time.Now(),
- RejectReason: req.Reason,
- }).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[finance db] Update YounggeeWithdrawRecord error, err:%+v", err)
- return err
- }
- // 更新 YoungeeTalentInfo
- err = db.Debug().Model(gorm_model.YoungeeTalentInfo{}).
- Where("id = ?", withdrwainfo.TalentID).
- Updates(map[string]interface{}{
- "withdrawing": gorm.Expr("withdrawing + ?", withdrwainfo.WithdrawAmount),
- "canwithdraw": gorm.Expr("canwithdraw - ?", withdrwainfo.WithdrawAmount),
- }).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[finance db] Update YoungeeTalentInfo error, err:%+v", err)
- return err
- }
- return nil
- }
- func GetBankInfo(ctx context.Context, req *http_model.GetBankInfoRequest) (*http_model.BankInfo, error) {
- //db := GetReadDB(ctx)
- //if req.BankId == "" {
- // return nil, nil
- //}
- //var infoBank *gorm_model.InfoBank
- //db.Debug().Model(gorm_model.InfoBank{}).Where("id = ?", req.BankId).First(&infoBank)
- db1 := GetReadDB(ctx)
- var infoRegion *gorm_model.InfoRegion
- db1.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(req.BankOpenAddress, 0)).First(&infoRegion)
- provinceCode := conv.MustString(req.BankOpenAddress, "")[0:2] + "0000"
- var province *gorm_model.InfoRegion
- db1.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(provinceCode, 0)).First(&province)
- cityCode := conv.MustString(req.BankOpenAddress, "")[0:4] + "00"
- var city *gorm_model.InfoRegion
- db1.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city)
- data := new(http_model.BankInfo)
- //data.BankName = infoBank.Name
- data.BankOpenAddress = province.RegionName + city.RegionName + infoRegion.RegionName
- //db.Model(gorm_model.InfoBank{}).Where("")
- return data, nil
- }
- // GetEnterpriseIDByBusiness 根据企业名称查找企业ID
- func GetEnterpriseIDByBusiness(ctx context.Context, BusinessName string) int64 {
- db := GetReadDB(ctx)
- var EnterpriseID int64
- db = db.Model([]gorm_model.Enterprise{}).Select("enterprise_id").Where("business_name", BusinessName).First(&EnterpriseID)
- return EnterpriseID
- }
- // GetEnterpriseIDByUserId 根据企业名称查找企业ID
- func GetEnterpriseIDByUserId(ctx context.Context, UserId int64) int64 {
- db := GetReadDB(ctx)
- var EnterpriseID int64
- db = db.Model([]gorm_model.Enterprise{}).Select("enterprise_id").Where("user_id", UserId).First(&EnterpriseID)
- return EnterpriseID
- }
- // GetUserIDByUsername 根据用户名称查UserID
- func GetUserIDByUsername(ctx context.Context, Username string) int64 {
- db := GetReadDB(ctx)
- var UserID int64
- db = db.Model([]gorm_model.YounggeeUser{}).Select("id").Where(fmt.Sprintf("username like '%%%s%%'", Username)).First(&UserID)
- return UserID
- }
- func GetInvoiceRecords(ctx context.Context, req *http_model.InvoiceRecordsRequest, condition *common_model.InvoiceRecordsCondition) (*http_model.InvoiceRecordsData, error) {
- db := GetReadDB(ctx)
- var invoiceRecords []*gorm_model.YounggeeInvoiceRecord
- db = db.Debug().Model(gorm_model.YounggeeInvoiceRecord{}).Where("status = ?", req.InvoiceStatus)
- conditionType := reflect.TypeOf(condition).Elem()
- conditionValue := reflect.ValueOf(condition).Elem()
- for i := 0; i < conditionType.NumField(); i++ {
- field := conditionType.Field(i)
- tag := field.Tag.Get("condition")
- value := conditionValue.FieldByName(field.Name)
- if tag == "submit_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("submit_at like '%s%%'", value.Interface()))
- }
- if tag == "billing_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("billing_at like '%s%%'", value.Interface()))
- }
- }
- if req.Username != "" {
- UserID := GetUserIDByUsername(ctx, req.Username)
- enterpriseId := GetEnterpriseIDByUserId(ctx, UserID)
- db = db.Where("enterprise_id = ?", enterpriseId)
- }
- if req.UserId != 0 {
- enterpriseId := GetEnterpriseIDByUserId(ctx, req.UserId)
- db = db.Where("enterprise_id = ?", enterpriseId)
- }
- // 查询总数
- var total int64
- if err := db.Count(&total).Error; err != nil {
- logrus.WithContext(ctx).Errorf("[GetInvoiceRecords] error query mysql total, err:%+v", err)
- return nil, err
- }
- if req.InvoiceStatus != 3 {
- db.Order("submit_at")
- } else {
- db.Order("billing_at desc")
- }
- // 查询该页数据
- limit := req.PageSize
- offset := req.PageSize * req.PageNum // assert pageNum start with 0
- err := db.Limit(int(limit)).Offset(int(offset)).Find(&invoiceRecords).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[GetInvoiceRecords] error query mysql limit, err:%+v", err)
- return nil, err
- }
- enterpriseIdToUserInfoMap := make(map[string]gorm_model.Enterprise)
- regionAddressMap := make(map[string]string)
- for _, invoiceRecord := range invoiceRecords {
- if _, ok := enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID]; !ok {
- db1 := GetReadDB(ctx)
- enterpriseInfo := gorm_model.Enterprise{}
- db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", invoiceRecord.EnterpriseID).Find(&enterpriseInfo)
- enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID] = enterpriseInfo
- }
- if _, ok := regionAddressMap[invoiceRecord.EnterpriseID]; !ok {
- db1 := GetReadDB(ctx)
- var regionCode string
- db1.Model(gorm_model.YounggeeInvoiceAddress{}).Select("region_code").Where("enterprise_id = ?", invoiceRecord.EnterpriseID).Find(®ionCode)
- regionAddressMap[invoiceRecord.EnterpriseID] = GetRegion(ctx, conv.MustInt(regionCode, 0))
- }
- }
- var InvoiceRecords []*http_model.InvoiceRecordsPreviews
- for _, invoiceRecord := range invoiceRecords {
- InvoiceRecord := new(http_model.InvoiceRecordsPreviews)
- InvoiceRecord.BillingId = invoiceRecord.BillingID
- InvoiceRecord.InvoiceInfo = invoiceRecord.InvoiceSnap
- InvoiceRecord.AddressInfo = invoiceRecord.AddressSnap
- InvoiceRecord.InvoiceAddress = regionAddressMap[invoiceRecord.EnterpriseID]
- InvoiceRecord.InvoiceType = invoiceRecord.InvoiceType
- InvoiceRecord.Amount = invoiceRecord.InvoiceAmount
- InvoiceRecord.Phone = invoiceRecord.Phone
- InvoiceRecord.ShipmentNumber = invoiceRecord.ShipmentNumber
- InvoiceRecord.BusinessName = enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID].BusinessName
- InvoiceRecord.UserId = invoiceRecord.EnterpriseID
- InvoiceRecord.Username = GetUsernameByUserID(ctx, enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID].UserID)
- InvoiceRecord.SubmitAt = conv.MustString(invoiceRecord.SubmitAt, "")[:19]
- InvoiceRecord.BillingAt = conv.MustString(invoiceRecord.BillingAt, "")[:19]
- InvoiceRecords = append(InvoiceRecords, InvoiceRecord)
- }
- var InvoiceRecordsData http_model.InvoiceRecordsData
- InvoiceRecordsData.InvoiceRecordsPreviews = InvoiceRecords
- InvoiceRecordsData.Total = strconv.FormatInt(total, 10)
- return &InvoiceRecordsData, nil
- }
- func GetInvoiceList(ctx context.Context, req http_model.GetInvoiceListRequest) (*http_model.InvoiceListData, error) {
- db := GetReadDB(ctx)
- // 获取分页参数
- page := req.PageNum
- pageSize := req.PageSize
- if page < 1 {
- page = 1
- }
- if pageSize < 1 {
- pageSize = 10 // 设置默认每页记录数为 10
- }
- var invoicelist []gorm_model.YounggeeInvoiceRecord
- var total int64
- // 计算总记录数
- err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("status = ?", req.Status).Count(&total).Error
- if err != nil {
- return &http_model.InvoiceListData{}, err
- }
- // 查询当前页的数据
- err = db.Model(gorm_model.YounggeeInvoiceRecord{}).
- Offset((page - 1) * pageSize). // 计算偏移量
- Limit(pageSize). // 设置每页限制
- Find(&invoicelist).Error
- if err != nil {
- return &http_model.InvoiceListData{}, err
- }
- invoicePointers := make([]*http_model.InvoiceListResponse, 0, len(invoicelist))
- for _, invoice := range invoicelist {
- var operator string
- if invoice.SubAccountID == 0 {
- operator = GetEnterprisenameByEnterpriseID(ctx, invoice.EnterpriseID)
- } else {
- operator = GetOperatorBySubacountID(ctx, invoice.SubAccountID)
- }
- response := &http_model.InvoiceListResponse{
- BillingID: invoice.BillingID,
- InvoiceAmount: invoice.InvoiceAmount,
- Operator: operator,
- SubmitAt: invoice.SubmitAt,
- AgreeAt: invoice.BillingAt,
- TaskNumber: GetTasknum(invoice.TaskIds),
- InvoiceType: invoice.InvoiceType,
- }
- invoicePointers = append(invoicePointers, response)
- }
- return &http_model.InvoiceListData{
- InvoiceListinfo: invoicePointers,
- Total: total,
- }, nil
- }
- func GetSupplierWithdrawList(ctx context.Context, req http_model.GetSupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
- db := GetReadDB(ctx)
- // 获取分页参数
- page := req.PageNum
- pageSize := req.PageSize
- if page < 1 {
- page = 1
- }
- if pageSize < 1 {
- pageSize = 10 // 设置默认每页记录数为 10
- }
- var withdrawlist []gorm_model.YounggeeSupplierWithdraw
- var total int64
- // 计算总记录数
- err := db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("withdraw_status = ?", req.Status).Count(&total).Error
- if err != nil {
- return &http_model.SupplierWithdrawListData{}, err
- }
- // 查询当前页的数据
- err = db.Model(gorm_model.YounggeeSupplierWithdraw{}).
- Offset((page - 1) * pageSize). // 计算偏移量
- Limit(pageSize). // 设置每页限制
- Find(&withdrawlist).Error
- if err != nil {
- return &http_model.SupplierWithdrawListData{}, err
- }
- withdrawPointers := make([]*http_model.SupplierWithdrawListResponse, 0, len(withdrawlist))
- for _, withdraw := range withdrawlist {
- var supplier gorm_model.Supplier
- err = db.Model(gorm_model.Supplier{}).Where("supplier_id = ?", withdraw.SupplierId).First(&supplier).Error
- if err != nil {
- return &http_model.SupplierWithdrawListData{}, err
- }
- var name string
- if supplier.SupplierType == 1 {
- name = supplier.Name
- } else {
- name = supplier.CompanyName
- }
- var InvoiceIDList []string
- TaskIDs := strings.Split(withdraw.InvoiceIds, ",")
- for _, taskId := range TaskIDs {
- InvoiceIDList = append(InvoiceIDList, taskId)
- }
- var invoiceIncome []gorm_model.YounggeeSupplierInvoice
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id IN ?", InvoiceIDList).Find(&invoiceIncome).Error
- if err != nil {
- return &http_model.SupplierWithdrawListData{}, err
- }
- // 收集所有的 incomeIDs
- var incomelist []string
- for _, invoice := range invoiceIncome {
- TaskIDs := strings.Split(invoice.IncomeIds, ",")
- for _, taskId := range TaskIDs {
- incomelist = append(incomelist, taskId)
- }
- }
- var supplier_income []gorm_model.YounggeeSupplierIncome
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", incomelist).Find(&supplier_income).Error
- if err != nil {
- return &http_model.SupplierWithdrawListData{}, err
- }
- var taskinfo []http_model.Tasklist
- taskinfo = make([]http_model.Tasklist, 0, len(supplier_income)) // 预分配足够的空间
- for _, income := range supplier_income {
- var info http_model.Tasklist
- // 根据 IncomeType 判断信息的来源
- switch income.IncomeType {
- case 1:
- info.Id = income.SProjectId
- case 3:
- info.Id = income.SLocalLifeId
- }
- info.Fee = income.SupplierChargeActual
- // 添加到任务信息列表
- taskinfo = append(taskinfo, info)
- }
- withdrawinfo := &http_model.Withdrawinfo{
- Name: withdraw.Name,
- IdNumber: withdraw.IdNumber,
- BankName: withdraw.BankName,
- BankNumber: withdraw.BankNumber,
- Phone: withdraw.Phone,
- }
- response := &http_model.SupplierWithdrawListResponse{
- WithDrawId: withdraw.SupplierWithdrawId,
- WithdrawAmount: withdraw.WithdrawAmount,
- ActualAmount: withdraw.AmountPayable,
- PhoneNumber: withdraw.Phone,
- SupplierName: supplier.SupplierName,
- Name: name,
- WithDrawinfo: withdrawinfo,
- SubmitAt: withdraw.SupplyTime,
- AggreeAt: withdraw.AgreeTime,
- ReajectAt: withdraw.RejectTime,
- ReajectReason: withdraw.FailReson,
- Taskinfo: &taskinfo,
- SupplierId: supplier.SupplierId,
- Avater: supplier.Avater,
- }
- withdrawPointers = append(withdrawPointers, response)
- }
- return &http_model.SupplierWithdrawListData{
- WithdrawListinfo: withdrawPointers,
- Total: total,
- }, nil
- }
- func GetSupplierInvoiceList(ctx context.Context, req http_model.GetSupplierInvoiceListRequest) (*http_model.SupplierInvoiceListData, error) {
- db := GetReadDB(ctx)
- // 获取分页参数
- page := req.PageNum
- pageSize := req.PageSize
- if page < 1 {
- page = 1
- }
- if pageSize < 1 {
- pageSize = 10 // 设置默认每页记录数为 10
- }
- var invoicelist []gorm_model.YounggeeSupplierInvoice
- var total int64
- // 计算总记录数
- err := db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_status = ?", req.Status).Count(&total).Error
- if err != nil {
- return &http_model.SupplierInvoiceListData{}, err
- }
- // 查询当前页的数据
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).
- Offset((page - 1) * pageSize). // 计算偏移量
- Limit(pageSize). // 设置每页限制
- Find(&invoicelist).Error
- if err != nil {
- return &http_model.SupplierInvoiceListData{}, err
- }
- invoicePointers := make([]*http_model.SupplierInvoiceListResponse, 0, len(invoicelist))
- for _, invoice := range invoicelist {
- var supplier gorm_model.Supplier
- err = db.Model(gorm_model.Supplier{}).Where("supplier_id = ?", invoice.SupplierId).First(&supplier).Error
- if err != nil {
- return &http_model.SupplierInvoiceListData{}, err
- }
- var name string
- if supplier.SupplierType == 1 {
- name = supplier.Name
- } else {
- name = supplier.CompanyName
- }
- var TaskIDList []string
- TaskIDs := strings.Split(invoice.IncomeIds, ",")
- for _, taskId := range TaskIDs {
- TaskIDList = append(TaskIDList, taskId)
- }
- var supplier_income []gorm_model.YounggeeSupplierIncome
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", TaskIDs).Find(&supplier_income).Error
- if err != nil {
- return &http_model.SupplierInvoiceListData{}, err
- }
- var taskinfo []http_model.Tasklist
- taskinfo = make([]http_model.Tasklist, 0, len(supplier_income)) // 预分配足够的空间
- var AllFee float64
- for _, income := range supplier_income {
- var info http_model.Tasklist
- // 根据 IncomeType 判断信息的来源
- switch income.IncomeType {
- case 1:
- info.Id = income.SProjectId
- case 3:
- info.Id = income.SLocalLifeId
- }
- info.Fee = income.SupplierChargeActual
- AllFee += income.SupplierChargeActual
- // 添加到任务信息列表
- taskinfo = append(taskinfo, info)
- }
- response := &http_model.SupplierInvoiceListResponse{
- InvoiceId: invoice.InvoiceId,
- SubmitAt: invoice.UploadInvoiceTime,
- AggreeAt: invoice.AgreeTime,
- ReajectAt: invoice.RejectTime,
- SupplierId: invoice.SupplierId,
- ReajectReason: invoice.FailReason,
- PhoneNumber: supplier.PhoneNumber,
- Name: name,
- SupplierName: supplier.SupplierName,
- CompanyName: invoice.Company,
- Taskinfo: &taskinfo,
- InvoiceAmount: AllFee,
- Avater: supplier.Avater,
- InvoiceUrl: invoice.InvoiceUrl,
- }
- invoicePointers = append(invoicePointers, response)
- }
- return &http_model.SupplierInvoiceListData{
- InvoiceListinfo: invoicePointers,
- Total: total,
- }, nil
- }
- func GetInvoiceInfo(ctx context.Context, request http_model.GetInvoiceInfoRequest) (*http_model.InvoiceInfoResponse, error) {
- db := GetReadDB(ctx)
- var invoice gorm_model.YounggeeInvoiceRecord
- err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("billing_id=?", request.BillingID).First(&invoice).Error
- if err != nil {
- return nil, err
- }
- res := &http_model.InvoiceInfoResponse{
- Businessname: GetEnterprisenameByEnterpriseID(ctx, invoice.EnterpriseID),
- TaxCode: invoice.TaxCode,
- RegisteredAddress: invoice.RegisteredAddress,
- RegisteredPhone: invoice.RegisteredPhone,
- Bank: invoice.Bank,
- BankCardNumber: invoice.BankCardNumber,
- InvoiceType: invoice.InvoiceType,
- }
- return res, nil
- }
- func ConfirmInvoice(ctx context.Context, request *http_model.ConfirmInvoiceRequest) error {
- db := GetReadDB(ctx)
- return db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("billing_id = ?", request.BillingId).Updates(
- gorm_model.YounggeeInvoiceRecord{
- BillingAt: time.Now(),
- InvoiceUrl: request.Url,
- Status: 2,
- }).Error
- }
- func SetInvoiceInfo(ctx context.Context, request *http_model.SetInvoiceInfoRequest) error {
- db := GetReadDB(ctx)
- invoiceInfo := gorm_model.YounggeePlatformInvoiceInfo{
- EnterpriseName: request.EnterpriseName,
- EnterpriseTax: request.EnterpriseTax,
- Phone: request.Phone,
- Address: request.Address,
- BankAccount: request.BankAccount,
- BankName: request.BankName,
- Project: request.Project,
- }
- return db.Create(&invoiceInfo).Error
- }
- func RefuseSupplierInvoice(ctx context.Context, request *http_model.RefuseSupplierInvoiceRequest) error {
- db := GetReadDB(ctx)
- return db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id = ?", request.InvoiceId).Updates(
- gorm_model.YounggeeSupplierInvoice{
- RejectTime: time.Now(),
- InvoiceStatus: 4,
- FailReason: request.Reason,
- }).Error
- }
- func ConfirmSupplierInvoice(ctx context.Context, request *http_model.ConfirmSupplierInvoiceRequest) error {
- db := GetReadDB(ctx)
- return db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id = ?", request.InvoiceId).Updates(
- gorm_model.YounggeeSupplierInvoice{
- AgreeTime: time.Now(),
- InvoiceStatus: 3,
- }).Error
- }
- func ConfirmWithdraw(ctx context.Context, request *http_model.ConfirmWithdrawRequest) error {
- db := GetReadDB(ctx)
- // 获取撤回记录
- var supplierincomeinfo gorm_model.YounggeeSupplierWithdraw
- err := db.Debug().Model(gorm_model.YounggeeSupplierWithdraw{}).
- Where("supplier_withdraw_id = ?", request.InvoiceId).
- First(&supplierincomeinfo).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[finance db] Query YounggeeWithdrawRecord error, err:%+v", err)
- return err
- }
- err = db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_withdraw_id = ?", request.InvoiceId).Updates(
- gorm_model.YounggeeSupplierWithdraw{
- AgreeTime: time.Now(),
- WithdrawStatus: 3,
- }).Error
- if err != nil {
- return err
- }
- if supplierincomeinfo.SupplierType == 2 {
- var InvoiceIDList []string
- InvoiceIDs := strings.Split(supplierincomeinfo.InvoiceIds, ",")
- for _, taskId := range InvoiceIDs {
- InvoiceIDList = append(InvoiceIDList, taskId)
- }
- var invoiceIncome []gorm_model.YounggeeSupplierInvoice
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id IN ?", InvoiceIDList).Find(&invoiceIncome).Error
- if err != nil {
- return err
- }
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id in ?", InvoiceIDList).Updates(
- gorm_model.YounggeeSupplierInvoice{
- WithdrawStatus: 3,
- }).Error
- if err != nil {
- return err
- }
- // 收集所有的 incomeIDs
- var incomelist []string
- for _, invoice := range invoiceIncome {
- IncomeIds := strings.Split(invoice.IncomeIds, ",")
- for _, IncomeId := range IncomeIds {
- incomelist = append(incomelist, IncomeId)
- }
- }
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", incomelist).Updates(gorm_model.YounggeeSupplierIncome{WithdrawStatus: 3}).Error
- if err != nil {
- return err
- }
- } else {
- incomeids := strings.Split(supplierincomeinfo.IncomeIds, ",")
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", incomeids).Updates(gorm_model.YounggeeSupplierIncome{WithdrawStatus: 3}).Error
- if err != nil {
- return err
- }
- }
- return nil
- }
- func RefuseWithdraw(ctx context.Context, request *http_model.RefuseWithdrawRequest) error {
- db := GetReadDB(ctx)
- // 获取撤回记录
- var supplierincomeinfo gorm_model.YounggeeSupplierWithdraw
- err := db.Debug().Model(gorm_model.YounggeeSupplierWithdraw{}).
- Where("supplier_withdraw_id = ?", request.InvoiceId).
- First(&supplierincomeinfo).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[finance db] Query YounggeeWithdrawRecord error, err:%+v", err)
- return err
- }
- err = db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_withdraw_id = ?", request.InvoiceId).Updates(
- gorm_model.YounggeeSupplierWithdraw{
- RejectTime: time.Now(),
- WithdrawStatus: 4,
- FailReson: request.Reason,
- }).Error
- if err != nil {
- return err
- }
- if supplierincomeinfo.SupplierType == 2 {
- var InvoiceIDList []string
- InvoiceIDs := strings.Split(supplierincomeinfo.InvoiceIds, ",")
- for _, taskId := range InvoiceIDs {
- InvoiceIDList = append(InvoiceIDList, taskId)
- }
- var invoiceIncome []gorm_model.YounggeeSupplierInvoice
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id IN ?", InvoiceIDList).Find(&invoiceIncome).Error
- if err != nil {
- return err
- }
- err = db.Model(gorm_model.YounggeeSupplierInvoice{}).Where("invoice_id in ?", InvoiceIDList).Updates(
- gorm_model.YounggeeSupplierInvoice{
- WithdrawStatus: 1,
- }).Error
- if err != nil {
- return err
- }
- // 收集所有的 incomeIDs
- var incomelist []string
- for _, invoice := range invoiceIncome {
- IncomeIds := strings.Split(invoice.IncomeIds, ",")
- for _, IncomeId := range IncomeIds {
- incomelist = append(incomelist, IncomeId)
- }
- }
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", incomelist).Updates(gorm_model.YounggeeSupplierIncome{WithdrawStatus: 1}).Error
- if err != nil {
- return err
- }
- } else {
- incomeids := strings.Split(supplierincomeinfo.IncomeIds, ",")
- err = db.Model(gorm_model.YounggeeSupplierIncome{}).Where("income_id in ?", incomeids).Updates(gorm_model.YounggeeSupplierIncome{WithdrawStatus: 1}).Error
- if err != nil {
- return err
- }
- }
- return nil
- }
- func GetTasknum(taskIds string) int {
- var ids [][]string // 修改为二维字符串切片
- if err := json.Unmarshal([]byte(taskIds), &ids); err != nil {
- return 0
- }
- count := 0
- for _, pair := range ids {
- count += len(pair)
- }
- return count
- }
- func GetOperatorBySubacountID(ctx context.Context, SubaccountID int) (username string) {
- db := GetReadDB(ctx)
- db = db.Model([]gorm_model.YounggeeSubAccount{}).Select("sub_account_name").Where("sub_account_id = ?", SubaccountID).First(&username)
- return username
- }
- func GetEnterprisenameByEnterpriseID(ctx context.Context, EnterpriseID string) (username string) {
- db := GetReadDB(ctx)
- db = db.Model([]gorm_model.Enterprise{}).Select("business_name").Where("enterprise_id = ?", EnterpriseID).First(&username)
- return username
- }
- func GetUsernameByUserID(ctx context.Context, UserID int64) (username string) {
- db := GetReadDB(ctx)
- db = db.Model([]gorm_model.YounggeeUser{}).Select("username").Where("id", UserID).First(&username)
- return username
- }
- func GetRechargeRecords(ctx context.Context, req *http_model.GetRechargeRecordsRequest, condition *common_model.RechargeRecordsCondition) (*http_model.RechargeRecordsData, error) {
- db := GetReadDB(ctx)
- var rechargeRecords []*gorm_model.YounggeeRechargeRecord
- db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("status = ?", req.Status)
- conditionType := reflect.TypeOf(condition).Elem()
- conditionValue := reflect.ValueOf(condition).Elem()
- for i := 0; i < conditionType.NumField(); i++ {
- field := conditionType.Field(i)
- tag := field.Tag.Get("condition")
- value := conditionValue.FieldByName(field.Name)
- if tag == "commit_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("commit_at like '%s%%'", value.Interface()))
- }
- if tag == "confirm_at" && value.Interface() != "" {
- db = db.Where(fmt.Sprintf("confirm_at like '%s%%'", value.Interface()))
- }
- }
- if req.Username != "" {
- UserID := GetUserIDByUsername(ctx, req.Username)
- enterpriseId := GetEnterpriseIDByUserId(ctx, UserID)
- db = db.Where("enterprise_id = ?", enterpriseId)
- }
- if req.UserId != 0 {
- enterpriseId := GetEnterpriseIDByUserId(ctx, req.UserId)
- db = db.Where("enterprise_id = ?", enterpriseId)
- }
- if req.RechargeMethod == 1 {
- db = db.Where("recharge_method = ?", 1)
- } else if req.RechargeMethod == 2 {
- db = db.Where("recharge_method = ?", 2)
- } else if req.RechargeMethod == 3 {
- db = db.Where("recharge_method = ?", 3)
- }
- // 查询总数
- var total int64
- if err := db.Count(&total).Error; err != nil {
- logrus.WithContext(ctx).Errorf("[GetRechargeRecords] error query mysql total, err:%+v", err)
- return nil, err
- }
- if req.Status == 1 {
- db = db.Order("commit_at")
- } else {
- db = db.Order("confirm_at desc")
- }
- // 查询该页数据
- limit := req.PageSize
- offset := req.PageSize * req.PageNum // assert pageNum start with 0
- err := db.Limit(int(limit)).Offset(int(offset)).Find(&rechargeRecords).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[GetRechargeRecords] error query mysql limit, err:%+v", err)
- return nil, err
- }
- var enterpriseIds []string
- for _, rechargeRecord := range rechargeRecords {
- enterpriseIds = append(enterpriseIds, rechargeRecord.EnterpriseID)
- }
- util.RemoveStrRepByMap(enterpriseIds)
- enterpriseIdToUserInfoMap := make(map[string]gorm_model.Enterprise)
- db1 := GetReadDB(ctx)
- for _, v := range enterpriseIds {
- enterpriseInfo := gorm_model.Enterprise{}
- db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", v).Find(&enterpriseInfo)
- enterpriseIdToUserInfoMap[v] = enterpriseInfo
- }
- var RechargeRecords []*http_model.RechargeRecordsPreview
- for _, rechargeRecord := range rechargeRecords {
- RechargeRecord := new(http_model.RechargeRecordsPreview)
- RechargeRecord.RechargeId = rechargeRecord.RechargeID
- RechargeRecord.EnterpriseID = rechargeRecord.EnterpriseID
- RechargeRecord.RechargeAmount = rechargeRecord.RechargeAmount
- RechargeRecord.ConfirmAt = conv.MustString(rechargeRecord.ConfirmAt, "")[:19]
- RechargeRecord.CommitAt = conv.MustString(rechargeRecord.CommitAt, "")[:19]
- RechargeRecord.Phone = rechargeRecord.Phone
- RechargeRecord.TransferVoucher = rechargeRecord.TransferVoucherUrl
- RechargeRecord.RechargeMethod = consts.GetRechargeMethod(rechargeRecord.RechargeMethod)
- RechargeRecord.UserId = rechargeRecord.EnterpriseID
- RechargeRecord.Username = GetUsernameByUserID(ctx, enterpriseIdToUserInfoMap[rechargeRecord.EnterpriseID].UserID)
- RechargeRecord.BusinessName = enterpriseIdToUserInfoMap[rechargeRecord.EnterpriseID].BusinessName
- RechargeRecords = append(RechargeRecords, RechargeRecord)
- }
- var RechargeRecordsData http_model.RechargeRecordsData
- RechargeRecordsData.RechargeRecordsPreview = RechargeRecords
- RechargeRecordsData.Total = conv.MustString(total, "")
- return &RechargeRecordsData, nil
- }
- func OperateRecharge(ctx context.Context, req *http_model.OperateRechargeRequest) error {
- db := GetReadDB(ctx)
- db1 := GetReadDB(ctx)
- err := db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", req.EnterpriseId).Updates(map[string]interface{}{
- "balance": gorm.Expr("balance + ?", req.RechargeAmount),
- "available_balance": gorm.Expr("available_balance + ?", req.RechargeAmount)}).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[OperateRecharge] error Updates balance, err:%+v", err)
- return err
- }
- err1 := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).Updates(gorm_model.YounggeeRechargeRecord{
- Status: 2,
- InvoiceStatus: 2,
- ConfirmAt: time.Now(),
- }).Error
- if err1 != nil {
- logrus.WithContext(ctx).Errorf("[OperateRecharge] error Updates Status, err:%+v", err)
- return err1
- }
- if req.Method == 1 {
- db2 := GetReadDB(ctx)
- db2.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).Updates(gorm_model.YounggeeRechargeRecord{
- RechargeAmount: req.RechargeAmount,
- })
- }
- return nil
- }
- func GetBillTaskList(ctx context.Context, req http_model.GetBillTaskListRequest) (*http_model.BillTaskData, error) {
- db := GetReadDB(ctx)
- // 获取分页参数
- page := req.PageNum
- pageSize := req.PageSize
- if page < 1 {
- page = 1
- }
- if pageSize < 1 {
- pageSize = 10 // 设置默认每页记录数为 10
- }
- var invoice gorm_model.YounggeeInvoiceRecord
- err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Where("billing_id = ?", req.BillingID).First(&invoice).Error
- if err != nil {
- return nil, err
- }
- var ids [][]string // 二维切片用于存储二元组
- if err = json.Unmarshal([]byte(invoice.TaskIds), &ids); err != nil {
- return nil, err // 返回错误信息
- }
- var results []*http_model.BillTaskDataResponse // 用于存储合并后的结果
- // 检查ID组的有效性
- if len(ids) != 3 {
- return nil, fmt.Errorf("task_ids must contain three groups")
- }
- // 第一组ID对应 selection 表
- if len(ids[0]) > 0 {
- var selections []gorm_model.YounggeeSelectionInfo
- if err := db.Where("selection_id IN ?", ids[0]).Find(&selections).Error; err != nil {
- return nil, err
- }
- for _, selection := range selections {
- var productName string
- var productPrice float64
- var mainImage string
- var creater string
- product, err := GetProductByID(ctx, int64(selection.ProductID))
- if err == nil && product != nil {
- productName = product.ProductName
- productPrice = product.ProductPrice
- }
- if selection.SubAccountId == 0 {
- creater = GetEnterprisenameByEnterpriseID(ctx, selection.EnterpriseID)
- } else {
- creater = GetOperatorBySubacountID(ctx, selection.SubAccountId)
- }
- mainImage, err = GetMainPhotoByProductID(ctx, int64(selection.ProductID))
- results = append(results, &http_model.BillTaskDataResponse{
- TaskType: 1,
- TaskForm: selection.TaskMode,
- Platform: selection.Platform,
- ContentType: selection.ContentType,
- SettleAmount: selection.SettlementAmount,
- Operator: creater,
- PhotoUrl: mainImage,
- Price: productPrice,
- ProductName: productName,
- Taskid: selection.SelectionID,
- })
- }
- }
- // 第二组ID对应 project 表
- if len(ids[1]) > 0 {
- var projects []gorm_model.ProjectInfo
- if err := db.Where("project_id IN ?", ids[1]).Find(&projects).Error; err != nil {
- return nil, err
- }
- for _, project := range projects {
- var productName string
- var productPrice float64
- var mainImage string
- var creater string
- product, err := GetProductByID(ctx, project.ProductID)
- if err == nil && product != nil {
- productName = product.ProductName
- productPrice = product.ProductPrice
- }
- if project.SubAccountID == 0 {
- creater = GetEnterprisenameByEnterpriseID(ctx, project.EnterpriseID)
- } else {
- creater = GetOperatorBySubacountID(ctx, int(project.SubAccountID))
- }
- mainImage, err = GetMainPhotoByProductID(ctx, project.ProductID)
- results = append(results, &http_model.BillTaskDataResponse{
- TaskType: 2,
- TaskForm: int(project.ProjectForm),
- ContentType: int(project.ContentType),
- SettleAmount: conv.MustString(project.SettlementAmount, ""),
- Operator: creater,
- PhotoUrl: mainImage,
- Price: productPrice,
- ProductName: productName,
- Taskid: project.ProjectID,
- })
- }
- }
- // 第三组ID对应 llocalife 表
- if len(ids[2]) > 0 {
- var localifes []gorm_model.YounggeeLocalLifeInfo
- if err := db.Where("local_id IN ?", ids[2]).Find(&localifes).Error; err != nil {
- return nil, err
- }
- for _, localife := range localifes {
- var productName string
- var address string
- var mainImage string
- var creater string
- store, err := GetStoreByID(ctx, int64(localife.StoreId))
- if err == nil && store != nil {
- productName = store.StoreName
- address = store.StoreLocation
- }
- if localife.SubAccountId == 0 {
- creater = GetEnterprisenameByEnterpriseID(ctx, localife.EnterpriseId)
- } else {
- creater = GetOperatorBySubacountID(ctx, localife.SubAccountId)
- }
- mainImage, err = GetMainPhotoByStoreID(ctx, int64(localife.StoreId))
- results = append(results, &http_model.BillTaskDataResponse{
- TaskType: 3,
- TaskForm: localife.TaskForm,
- ContentType: localife.ContentType,
- SettleAmount: conv.MustString(localife.SettlementAmount, ""),
- Operator: creater,
- Taskid: localife.LocalId,
- ProductName: productName,
- Address: address,
- PhotoUrl: mainImage,
- })
- }
- }
- // 计算总数
- total := len(results)
- // 分页处理
- start := (page - 1) * pageSize
- if start >= total {
- return &http_model.BillTaskData{InvoiceListinfo: nil, Total: total}, nil // 返回空结果
- }
- end := start + pageSize
- if end > total {
- end = total
- }
- // 返回分页后的结果
- return &http_model.BillTaskData{
- InvoiceListinfo: results[start:end],
- Total: total,
- }, nil
- }
- func GetMainPhotoByStoreID(ctx context.Context, storeID int64) (string, error) {
- db := GetReadDB(ctx)
- var productPhoto gorm_model.YounggeeProductPhoto
- err := db.Where("store_id = ? AND symbol = ?", storeID, 1).First(&productPhoto).Error
- if err != nil {
- return "", err
- }
- return productPhoto.PhotoUrl, nil
- }
- func GetMainPhotoByProductID(ctx context.Context, productId int64) (string, error) {
- db := GetReadDB(ctx)
- var productPhoto gorm_model.YounggeeProductPhoto
- err := db.Where("product_id = ? AND symbol = ?", productId, 1).First(&productPhoto).Error
- if err != nil {
- return "", err
- }
- return productPhoto.PhotoUrl, nil
- }
- func GetStoreByID(ctx context.Context, stroeid int64) (*gorm_model.YounggeeStore, error) {
- db := GetReadDB(ctx)
- store := &gorm_model.YounggeeStore{}
- err := db.First(&store, stroeid).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return store, nil
- }
|