123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- package service
- import (
- "context"
- "fmt"
- "github.com/issue9/conv"
- log "github.com/sirupsen/logrus"
- "strconv"
- "strings"
- "time"
- "youngee_b_api/db"
- "youngee_b_api/model/gorm_model"
- "youngee_b_api/model/http_model"
- )
- var Supplier *supplier
- type supplier struct {
- }
- // CreateSupplier 创建younggee平台用户账号与服务商用户信息
- func (*supplier) CreateSupplier(ctx context.Context, phone string) (*http_model.RegisterData, error) {
- // 1. 创建YG平台用户
- userInfo := gorm_model.YounggeeUser{
- Phone: phone,
- User: "1003",
- Username: phone,
- Password: "1003",
- RealName: "",
- Role: "6",
- Email: "",
- LastLoginTime: time.Now().UTC().Local(),
- }
- userId, createUserErr := db.CreateUser(ctx, userInfo)
- if createUserErr != nil {
- log.Infof("[CreateSupplierUser] fail,err:%+v", createUserErr)
- return nil, createUserErr
- } else {
- // 2. 创建服务商信息
- supplierInfo := &gorm_model.YoungeeSupplier{
- SupplierName: phone,
- PhoneNumber: phone,
- UserId: *userId,
- }
- supplierId, createSupplierErr := db.CreateSupplier(ctx, *supplierInfo)
- fmt.Println(supplierId)
- if createSupplierErr != nil {
- log.Infof("[CreateSupplierUser] fail,err:%+v", createSupplierErr)
- return nil, createSupplierErr
- }
- res := &http_model.RegisterData{
- UserID: *userId,
- }
- return res, nil
- }
- }
- // GetSupplierIncomeList 查询服务商收入列表
- func (*supplier) GetSupplierIncomeList(ctx context.Context, req *http_model.FullSProjectIncomeListRequest) (*http_model.FullSProjectIncomeData, error) {
- var sProjectIncomeData *http_model.FullSProjectIncomeData
- sProjectIncomeData = &http_model.FullSProjectIncomeData{}
- // 1. 查询
- supplierIncome, total, err := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.IncomeStatus)
- if err != nil {
- return nil, nil
- }
- // 2. 补充种草/本地生活任务信息
- if supplierIncome != nil {
- sProjectIncomeData.Total = total
- for _, income := range supplierIncome {
- // 2.1. 种草任务基本信息
- if income.IncomeType == 1 {
- var sProjectInfo *http_model.FullSProjectIncomeListResponse
- sProjectInfo = &http_model.FullSProjectIncomeListResponse{}
- sProjectData, sProjectErr := db.GetSProjectDetail(ctx, income.SProjectID)
- if sProjectErr != nil {
- log.Infof("[GetSProjectDetail] fail,err:%+v", sProjectErr)
- return nil, sProjectErr
- }
- if sProjectData != nil {
- sProjectInfo.SProjectId = sProjectData.SProjectId
- sProjectInfo.IncomeId = income.IncomeID
- sProjectInfo.IncomeType = income.IncomeType
- sProjectInfo.SProjectId = sProjectData.SProjectId
- sProjectInfo.ProjectName = sProjectData.ProjectName
- sProjectInfo.ProjectPlatform = sProjectData.ProjectPlatform
- sProjectInfo.ServiceCharge = sProjectData.ServiceCharge
- sProjectInfo.ServiceChargeSettle = sProjectData.ServiceChargeSettle
- sProjectInfo.FinishTime = conv.MustString(sProjectData.FinishTime)
- // 2.2. 商品基本信息
- productInfo, productErr := db.GetProductByID(ctx, sProjectData.ProductId)
- if productErr != nil {
- log.Infof("[GetProductByID] fail,err:%+v", productErr)
- return nil, productErr
- }
- if productInfo != nil {
- sProjectInfo.ProductName = productInfo.ProductName
- sProjectInfo.ProductPrice = productInfo.ProductPrice
- }
- // 2.3. 商品图片信息
- productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProjectData.ProductId)
- if productPhotoErr != nil {
- log.Infof("[GetProductPhotoByProductID] fail,err:%+v", productPhotoErr)
- return nil, productPhotoErr
- }
- if productPhotoInfo != nil {
- for _, photo := range productPhotoInfo {
- fmt.Println(photo)
- if photo.Symbol == 1 {
- sProjectInfo.ProductPhotoSymbol = 1
- sProjectInfo.ProductPhotoUrl = photo.PhotoUrl
- sProjectInfo.ProductPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- }
- // 2.1. 本地生活任务基本信息
- if income.IncomeType == 2 {
- var sLocalInfo *http_model.FullSProjectIncomeListResponse
- sLocalInfo = &http_model.FullSProjectIncomeListResponse{}
- sLocalData, sLocalErr := db.GetSLocalLifeDetail(ctx, income.SLocalID)
- if sLocalErr != nil {
- log.Infof("[GetSLocalLifeDetail] fail,err:%+v", sLocalErr)
- return nil, sLocalErr
- }
- if sLocalData != nil {
- sLocalInfo.IncomeId = income.IncomeID
- sLocalInfo.IncomeType = income.IncomeType
- sLocalInfo.SLocalId = sLocalData.SLocalId
- sLocalInfo.LocalName = sLocalData.LocalName
- sLocalInfo.LocalPlatform = sLocalData.LocalPlatform
- sLocalInfo.ServiceCharge = sLocalData.ServiceCharge
- sLocalInfo.ServiceChargeSettle = sLocalData.ServiceChargeSettle
- sLocalInfo.FinishTime = conv.MustString(sLocalData.FinishTime)
- // 2.2. 门店基本信息
- storeInfo, storeErr := db.FindStoreById(ctx, sLocalData.StoreId)
- if storeErr != nil {
- log.Infof("[GetProductByID] fail,err:%+v", storeErr)
- return nil, storeErr
- }
- if storeInfo != nil {
- sLocalInfo.StoreName = storeInfo.StoreName
- }
- // 2.3. 门店图片信息
- storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, sLocalData.StoreId)
- if storePhotoErr != nil {
- log.Infof("[GetProductPhotoByProductID] fail,err:%+v", storePhotoErr)
- return nil, storePhotoErr
- }
- if storePhotoInfo != nil {
- for _, photo := range storePhotoInfo {
- fmt.Println(photo)
- if photo.Symbol == 1 {
- sLocalInfo.StoreMainPhotoSymbol = 1
- sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
- sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- }
- }
- } else {
- sProjectIncomeData.Total = 0
- }
- return sProjectIncomeData, nil
- }
- // CreateSupplierInvoice 创建服务商发票
- func (*supplier) CreateSupplierInvoice(ctx context.Context, req *http_model.CreateSupplierInvoiceRequest) error {
- // 1. 数据转换
- var invoiceData *gorm_model.YounggeeSupplierInvoice
- invoiceData = &gorm_model.YounggeeSupplierInvoice{
- SupplierId: req.SupplierId,
- InvoiceStatus: 1,
- IncomeIds: req.IncomeIds,
- }
- if req.SOperatorType == 1 {
- invoiceData.SOperatorType = 1
- invoiceData.SOperator = req.SupplierId
- } else if req.SOperatorType == 2 {
- invoiceData.SOperatorType = 2
- invoiceData.SOperator = req.SubAccountId
- }
- // 2. 插入数据库
- err := db.CreateSupplierInvoice(ctx, invoiceData)
- if err != nil {
- return err
- }
- return nil
- }
- // UpdateSupplierInvoice 更新服务商发票
- func (*supplier) UpdateSupplierInvoice(ctx context.Context, req *http_model.UpdateSupplierInvoiceRequest) error {
- // 1. 数据转换
- var invoiceData *gorm_model.YounggeeSupplierInvoice
- var currentTime time.Time
- currentTime = time.Now()
- invoiceData = &gorm_model.YounggeeSupplierInvoice{
- InvoiceId: req.InvoiceId,
- InvoiceUrl: req.InvoiceUrl,
- Company: req.Company,
- UploadInvoiceTime: ¤tTime,
- }
- // 2. 更新
- err := db.UpdateSupplierInvoice(ctx, invoiceData)
- if err != nil {
- return err
- }
- // 3. 更新服务商收入状态
- incomeIds, dbErr := db.GetIncomeIdsByInvoiceId(ctx, req.InvoiceId)
- if dbErr != nil {
- return dbErr
- }
- if incomeIds == "" {
- return nil
- }
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return err
- }
- intSlice[i] = num
- }
- updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, 3)
- if updateSupplierIncomeErr != nil {
- return updateSupplierIncomeErr
- }
- return nil
- }
- // UpdateSupplierIncomeStatus 修改服务商收入状态
- func (*supplier) UpdateSupplierIncomeStatus(ctx context.Context, incomeIds string, incomeStatus int) error {
- // 1. 转换incomeIds为数组
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return err
- }
- intSlice[i] = num
- }
- // 2. 修改数据库中数据
- updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, incomeStatus)
- if updateSupplierIncomeErr != nil {
- return updateSupplierIncomeErr
- }
- return nil
- }
- // GetSupplierInvoiceList 查找服务商发票列表
- func (*supplier) GetSupplierInvoiceList(ctx context.Context, req *http_model.SupplierInvoiceListRequest) (*http_model.SupplierInvoiceListData, error) {
- // 1. 查询服务商发票信息
- supplierInvoiceList, total, err := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, req.InvoiceStatus, 4, req.PageSize, req.PageNum)
- if err != nil {
- return nil, err
- }
- // 2. 根据发票中的incomeIds去查找任务及其服务费收入
- var supplierInvoiceData *http_model.SupplierInvoiceListData
- supplierInvoiceData = &http_model.SupplierInvoiceListData{}
- for _, supplierInvoice := range supplierInvoiceList {
- var supplierInvoiceInfo *http_model.SupplierInvoiceInfo
- supplierInvoiceInfo = &http_model.SupplierInvoiceInfo{}
- // 2.1. 基础信息填入
- supplierInvoiceInfo.UploadInvoiceTime = supplierInvoice.UploadInvoiceTime
- supplierInvoiceInfo.InvoiceUrl = supplierInvoice.InvoiceUrl
- supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
- supplierInvoiceInfo.RejectTime = supplierInvoice.RejectTime
- supplierInvoiceInfo.Company = supplierInvoice.Company
- supplierInvoiceInfo.SOperator = supplierInvoice.SOperator
- supplierInvoiceInfo.FailReason = supplierInvoice.FailReason
- // 2.2. 任务及其收入信息填入
- incomeIds := supplierInvoice.IncomeIds
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return nil, err
- }
- intSlice[i] = num
- }
- for _, incomeId := range intSlice {
- var sTaskInfo *http_model.STaskInfo
- sTaskInfo = &http_model.STaskInfo{}
- currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
- if incomeErr != nil {
- return nil, incomeErr
- }
- sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
- if currIncome.IncomeType == 1 {
- sTaskInfo.Id = currIncome.SProjectID
- } else if currIncome.IncomeType == 3 {
- sTaskInfo.Id = currIncome.SLocalID
- }
- supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
- }
- supplierInvoiceData.SupplierInvoiceList = append(supplierInvoiceData.SupplierInvoiceList, supplierInvoiceInfo)
- }
- supplierInvoiceData.Total = total
- return supplierInvoiceData, nil
- }
- // GetSupplierToWithdrawList 服务商待提现列表
- func (*supplier) GetSupplierToWithdrawList(ctx context.Context, req *http_model.SupplierToWithdrawListRequest) (*http_model.SupplierToWithdrawListData, error) {
- // 1. 判断服务商类型
- var supplierInvoiceData *http_model.SupplierToWithdrawListData
- supplierInvoiceData = &http_model.SupplierToWithdrawListData{}
- supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierErr != nil {
- return nil, supplierErr
- }
- if supplierInfo != nil {
- // 企业服务商
- if supplierInfo.SupplierType == 2 {
- // 查询企业服务商发票信息
- supplierInvoiceList, total, supplierInvoiceErr := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, 3, 1, req.PageSize, req.PageNum)
- if supplierInvoiceErr != nil {
- return nil, supplierInvoiceErr
- }
- if supplierInvoiceList != nil {
- for _, supplierInvoice := range supplierInvoiceList {
- // 2. 根据发票中的incomeIds去查找任务及其服务费收入
- var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
- supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
- // 2.1. 基础信息填入
- supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
- supplierInvoiceInfo.Company = supplierInvoice.Company
- supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
- // 2.2. 任务及其收入信息填入
- incomeIds := supplierInvoice.IncomeIds
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return nil, err
- }
- intSlice[i] = num
- }
- for _, incomeId := range intSlice {
- var sTaskInfo *http_model.STaskInfo
- sTaskInfo = &http_model.STaskInfo{}
- currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
- if incomeErr != nil {
- return nil, incomeErr
- }
- sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
- supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
- if currIncome.IncomeType == 1 {
- sTaskInfo.Id = currIncome.SProjectID
- } else if currIncome.IncomeType == 3 {
- sTaskInfo.Id = currIncome.SLocalID
- }
- supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
- }
- supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
- }
- supplierInvoiceData.Total = total
- }
- } else if supplierInfo.SupplierType == 1 {
- // 个人服务商
- // 查询个人服务商收入信息
- supplierIncomeList, supplierIncomeTotal, supplierIncomeErr := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, 5)
- if supplierIncomeErr != nil {
- return nil, supplierIncomeErr
- }
- if supplierIncomeList != nil {
- supplierInvoiceData.Total = supplierIncomeTotal
- for _, supplierIncome := range supplierIncomeList {
- var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
- supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
- supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
- supplierInvoiceInfo.IncomeId = supplierIncome.IncomeID
- supplierInvoiceInfo.Amount = supplierIncome.ServiceChargeSettle
- supplierInvoiceInfo.AmountActual = supplierIncome.ServiceChargeSettle * 0.05
- var sTaskInfo *http_model.STaskInfo
- sTaskInfo = &http_model.STaskInfo{}
- sTaskInfo.ServiceCharge = supplierIncome.ServiceChargeSettle
- if supplierIncome.IncomeType == 1 {
- sTaskInfo.Id = supplierIncome.SProjectID
- } else if supplierIncome.IncomeType == 3 {
- sTaskInfo.Id = supplierIncome.SLocalID
- }
- supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
- supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
- }
- }
- }
- }
- return supplierInvoiceData, nil
- }
- // CreateSupplierWithdraw 创建服务商提现信息
- func (*supplier) CreateSupplierWithdraw(ctx context.Context, req *http_model.CreateSupplierWithdrawRequest) error {
- var supplierWithdrawInfoList []*gorm_model.YounggeeSupplierWithdraw
- // 1. 判断服务商类型
- supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierErr != nil {
- return supplierErr
- }
- if supplierInfo != nil {
- if supplierInfo.SupplierType == 1 {
- // 1.1. 个人服务商
- for _, withdrawInfo := range req.CreatePersonSupplierWithdraw {
- var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
- supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
- // 1.2.1. 接口传入信息填入
- supplierWithdrawInfo.SupplierId = req.SupplierId
- supplierWithdrawInfo.WithdrawStatus = 2
- supplierWithdrawInfo.BankName = withdrawInfo.BankName
- supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
- var currentTime time.Time
- currentTime = time.Now()
- supplierWithdrawInfo.SupplyTime = ¤tTime
- supplierWithdrawInfo.WithdrawAmount = 0.0
- // 1.2.2. 查找服务商信息填入
- supplierWithdrawInfo.Name = supplierInfo.Name
- supplierWithdrawInfo.Phone = withdrawInfo.Phone
- // 1.2.3. 收入信息填入
- currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, withdrawInfo.IncomeId)
- if incomeInfoErr != nil {
- return incomeInfoErr
- }
- if currIncome != nil {
- supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
- }
- supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
- supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
- }
- } else if supplierInfo.SupplierType == 2 {
- // 1.2. 机构服务商
- for _, withdrawInfo := range req.CreateCompanySupplierWithdraw {
- var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
- supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
- // 1.2.1. 接口传入信息填入
- supplierWithdrawInfo.SupplierId = req.SupplierId
- supplierWithdrawInfo.WithdrawStatus = 2
- supplierWithdrawInfo.BankName = withdrawInfo.BankName
- supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
- var currentTime time.Time
- currentTime = time.Now()
- supplierWithdrawInfo.SupplyTime = ¤tTime
- supplierWithdrawInfo.WithdrawAmount = 0.0
- // 1.2.2. 查找服务商信息填入
- supplierWithdrawInfo.Name = supplierInfo.Name
- supplierWithdrawInfo.Phone = supplierInfo.PhoneNumber
- supplierWithdrawInfo.Company = supplierInfo.CompanyName
- // 1.2.3. 收入信息填入
- incomeIds, incomeErr := db.GetIncomeIdsByInvoiceId(ctx, withdrawInfo.InvoiceId)
- if incomeErr != nil {
- return incomeErr
- }
- if incomeIds != "" {
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return err
- }
- intSlice[i] = num
- }
- for _, incomeId := range intSlice {
- currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
- if incomeInfoErr != nil {
- return incomeInfoErr
- }
- if currIncome != nil {
- supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
- }
- }
- supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
- }
- supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
- }
- }
- }
- // 2. 数据库插入
- err := db.CreateSupplierWithdraw(ctx, supplierWithdrawInfoList)
- if err != nil {
- return err
- }
- return nil
- }
- // GetSupplierWithdrawList 服务商提现列表
- func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.SupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
- var supplierWithdrawListData *http_model.SupplierWithdrawListData
- supplierWithdrawListData = &http_model.SupplierWithdrawListData{}
- // 1. 根据服务商ID和提现状态去查找提现信息列表
- supplierWithdrawList, total, supplierWithdrawErr := db.GetSupplierWithdrawList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.WithdrawStatus)
- if supplierWithdrawErr != nil {
- return nil, supplierWithdrawErr
- }
- if supplierWithdrawList != nil {
- supplierWithdrawListData.Total = total
- supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierErr != nil {
- return nil, supplierErr
- }
- if supplierInfo != nil {
- if supplierInfo.SupplierId == 1 {
- // 2. 个人服务商
- var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
- supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
- for _, withdrawInfo := range supplierWithdrawList {
- IncomeId, IncomeIdErr := strconv.Atoi(withdrawInfo.IncomeIds)
- if IncomeIdErr != nil {
- return nil, IncomeIdErr
- }
- incomeInfo, incomeErr := db.GetIncomeInfoByIncomeId(ctx, IncomeId)
- if incomeErr != nil {
- return nil, incomeErr
- }
- if incomeInfo != nil {
- var sTaskInfo *http_model.STaskInfo
- sTaskInfo = &http_model.STaskInfo{}
- if incomeInfo.IncomeType == 1 {
- sTaskInfo.Id = incomeInfo.SProjectID
- sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
- } else if incomeInfo.IncomeType == 3 {
- sTaskInfo.Id = incomeInfo.SLocalID
- sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
- }
- supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
- }
- supplierWithdrawInfo.SupplierType = 1
- supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
- supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
- supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
- supplierWithdrawInfo.Name = withdrawInfo.Name
- supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
- supplierWithdrawInfo.BankName = withdrawInfo.BankName
- supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
- supplierWithdrawInfo.Phone = withdrawInfo.Phone
- // supplierWithdrawInfo.Company = withdrawInfo.Company
- supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
- supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
- supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
- supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
- supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
- }
- } else if supplierInfo.SupplierId == 2 {
- // 3. 企业服务商
- for _, withdrawInfo := range supplierWithdrawList {
- var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
- supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
- InvoiceId, InvoiceIdErr := strconv.Atoi(withdrawInfo.InvoiceIds)
- if InvoiceIdErr != nil {
- return nil, InvoiceIdErr
- }
- incomeIds, incomeIdsErr := db.GetIncomeIdsByInvoiceId(ctx, InvoiceId)
- if incomeIdsErr != nil {
- return nil, incomeIdsErr
- }
- if incomeIds != "" {
- strSlice := strings.Split(incomeIds, ",")
- intSlice := make([]int, len(strSlice))
- for i, s := range strSlice {
- num, err := strconv.Atoi(s)
- if err != nil {
- fmt.Println("转换错误:", err)
- return nil, err
- }
- intSlice[i] = num
- }
- for _, incomeId := range intSlice {
- var sTaskInfo *http_model.STaskInfo
- sTaskInfo = &http_model.STaskInfo{}
- currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
- if incomeInfoErr != nil {
- return nil, incomeInfoErr
- }
- if currIncome != nil {
- if currIncome.IncomeType == 1 {
- sTaskInfo.Id = currIncome.SProjectID
- sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
- } else if currIncome.IncomeType == 3 {
- sTaskInfo.Id = currIncome.SLocalID
- sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
- }
- supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
- }
- }
- }
- supplierWithdrawInfo.SupplierType = 1
- supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
- supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
- supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
- supplierWithdrawInfo.Name = withdrawInfo.Name
- supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
- supplierWithdrawInfo.BankName = withdrawInfo.BankName
- supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
- supplierWithdrawInfo.Phone = withdrawInfo.Phone
- supplierWithdrawInfo.Company = withdrawInfo.Company
- supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
- supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
- supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
- supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
- supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
- }
- }
- }
- }
- return supplierWithdrawListData, nil
- }
|