123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131 |
- 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
- }
- }
- // GetSupplierAccountInfo 查询服务商账号信息
- func (*supplier) GetSupplierAccountInfo(ctx context.Context, req *http_model.GetAccountInfoRequest) (*http_model.GetAccountInfoData, error) {
- var supplierUserInfo *http_model.GetAccountInfoData
- supplierUserInfo = &http_model.GetAccountInfoData{}
- if req.SubAccountId == 0 {
- // 1. 服务商主账号
- supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierInfoErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierInfoErr)
- return nil, supplierInfoErr
- }
- if supplierInfo != nil {
- supplierUserInfo.SupplierName = supplierInfo.SupplierName
- supplierUserInfo.Type = 1
- supplierUserInfo.Avatar = supplierInfo.Avatar
- supplierUserInfo.Phone = supplierInfo.PhoneNumber
- }
- } else {
- // 2. 服务商子账号
- subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, req.SubAccountId)
- if subAccountInfoErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", subAccountInfoErr)
- return nil, subAccountInfoErr
- }
- if subAccountInfo != nil {
- supplierUserInfo.SubAccountName = subAccountInfo.SubAccountName
- supplierUserInfo.Type = 2
- supplierUserInfo.Avatar = subAccountInfo.Avatar
- supplierUserInfo.Phone = subAccountInfo.PhoneNumber
- jobInfo, jobInfoErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
- if jobInfoErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", jobInfoErr)
- return nil, subAccountInfoErr
- }
- if jobInfo != nil {
- supplierUserInfo.JobName = jobInfo.JobName
- }
- }
- }
- return supplierUserInfo, nil
- }
- // GetSupplierReviewInfo 查询服务商认证信息
- func (*supplier) GetSupplierReviewInfo(ctx context.Context, req *http_model.GetReviewInfoRequest) (*http_model.GetReviewInfoData, error) {
- var supplierUserInfo *http_model.GetReviewInfoData
- supplierUserInfo = &http_model.GetReviewInfoData{}
- // 1. 服务商信息
- supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierInfoErr != nil {
- log.Infof("[GetSupplierReviewInfo] fail,err:%+v", supplierInfoErr)
- return nil, supplierInfoErr
- }
- if supplierInfo != nil {
- if supplierInfo.ReviewStatus == 1 {
- supplierUserInfo.ReviewStatus = 1
- } else if supplierInfo.SupplierType == 1 {
- supplierUserInfo.ReviewStatus = 2
- supplierUserInfo.SupplierType = 1
- supplierUserInfo.IdBack = supplierInfo.IdBack
- supplierUserInfo.IdFront = supplierInfo.IdFront
- supplierUserInfo.IdNumber = supplierInfo.IdNumber
- supplierUserInfo.Name = supplierInfo.Name
- } else if supplierInfo.SupplierType == 2 {
- supplierUserInfo.ReviewStatus = 2
- supplierUserInfo.SupplierType = 2
- supplierUserInfo.CompanyName = supplierInfo.CompanyName
- supplierUserInfo.USCI = supplierInfo.Usci
- supplierUserInfo.BusinessLicense = supplierInfo.BusinessLicense
- }
- }
- return supplierUserInfo, nil
- }
- // GetSupplierContactInfo 查询服务商联系方式
- func (*supplier) GetSupplierContactInfo(ctx context.Context, req *http_model.GetContactInfoRequest) (*http_model.GetContactInfoData, error) {
- var contactInfo *http_model.GetContactInfoData
- contactInfo = &http_model.GetContactInfoData{}
- // 1. 服务商主账号
- if req.SubAccountId == 0 {
- supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierInfoErr != nil {
- log.Infof("[GetSupplierContactInfo] fail,err:%+v", supplierInfoErr)
- return nil, supplierInfoErr
- }
- if supplierInfo != nil {
- contactInfo.ContactPhone = supplierInfo.ContactPhone
- contactInfo.WechatQRCode = supplierInfo.WechatQrCode
- contactInfo.WechatNumber = supplierInfo.WechatNumber
- }
- } else {
- // 2. 服务商子账号
- subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, req.SubAccountId)
- if subAccountInfoErr != nil {
- log.Infof("[GetSupplierContactInfo] fail,err:%+v", subAccountInfoErr)
- return nil, subAccountInfoErr
- }
- if subAccountInfo != nil {
- contactInfo.ContactPhone = subAccountInfo.ContactPhone
- contactInfo.WechatQRCode = subAccountInfo.WechatQRCode
- contactInfo.WechatNumber = subAccountInfo.WechatNumber
- }
- }
- return contactInfo, nil
- }
- // SaveSupplierReviewInfo 保存服务商联系方式
- func (*supplier) SaveSupplierReviewInfo(ctx context.Context, req *http_model.SaveReviewRequest) error {
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- // 1. 个人服务商
- if req.SupplierType == 1 {
- supplierInfo.SupplierId = req.SupplierId
- supplierInfo.IdFront = req.IdCardUrl
- supplierInfo.IdNumber = req.IdNumber
- supplierInfo.Name = req.Name
- supplierInfo.IdBack = req.IdBack
- supplierInfo.SupplierType = req.SupplierType
- supplierInfo.ReviewStatus = 2
- updateErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateErr != nil {
- log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
- return updateErr
- }
- } else if req.SupplierType == 2 {
- // 2. 企业服务商
- supplierInfo.SupplierId = req.SupplierId
- supplierInfo.ReviewStatus = 2
- supplierInfo.SupplierType = req.SupplierType
- supplierInfo.CompanyName = req.CompanyName
- supplierInfo.Usci = req.USCI
- supplierInfo.BusinessLicense = req.BusinessLicenseUrl
- updateErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateErr != nil {
- log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
- return updateErr
- }
- }
- return 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.RecruitNum = sProjectData.RecruitNum
- sProjectInfo.SettleNum = sProjectData.SettleNum
- 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.4. 加入商单操作人信息
- if sProjectData.SubAccountId == 0 {
- sProjectInfo.SOperatorType = 1
- sProjectInfo.SOperatorId = sProjectData.SupplierId
- supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, sProjectData.SupplierId)
- if supplierInfoErr != nil {
- log.Infof("[GetSupplierById] fail,err:%+v", supplierInfoErr)
- return nil, supplierInfoErr
- }
- if supplierInfo != nil {
- sProjectInfo.SOperatorName = supplierInfo.Name
- }
- sProjectInfo.SOperatorName = conv.MustString(sProjectData.SupplierId)
- } else {
- sProjectInfo.SOperatorType = 2
- sProjectInfo.SOperatorId = sProjectData.SubAccountId
- subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, sProjectData.SubAccountId)
- if subAccountInfoErr != nil {
- log.Infof("[FindSubAccountById] fail,err:%+v", subAccountInfoErr)
- return nil, subAccountInfoErr
- }
- if subAccountInfo != nil {
- sProjectInfo.SOperatorName = subAccountInfo.SubAccountName
- }
- }
- sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sProjectInfo)
- }
- }
- // 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.RecruitNum = sLocalData.RecruitNum
- sLocalInfo.SettleNum = sLocalData.SettleNum
- 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
- }
- }
- }
- sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sLocalInfo)
- }
- }
- }
- } 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
- 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.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{}
- // supplierInvoiceInfo.Amount = 0.0
- // 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. 个人服务商
- supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
- if supplierPaymentErr != nil {
- return supplierPaymentErr
- }
- if supplierPaymentInfo != nil {
- for _, withdrawInfo := range req.IncomeIds {
- var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
- supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
- // 1.2.1. 接口传入信息填入
- supplierWithdrawInfo.SupplierId = req.SupplierId
- supplierWithdrawInfo.WithdrawStatus = 2
- supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
- supplierWithdrawInfo.BankNumber = supplierPaymentInfo.BankNumber
- var currentTime time.Time
- currentTime = time.Now()
- supplierWithdrawInfo.SupplyTime = ¤tTime
- supplierWithdrawInfo.WithdrawAmount = 0.0
- // 1.2.2. 查找服务商信息填入
- supplierWithdrawInfo.Name = supplierInfo.Name
- supplierWithdrawInfo.Phone = supplierPaymentInfo.Phone
- // 1.2.3. 收入信息填入
- currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, withdrawInfo)
- 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. 机构服务商
- supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
- if supplierPaymentErr != nil {
- return supplierPaymentErr
- }
- if supplierPaymentInfo != nil {
- for _, withdrawInfo := range req.InvoiceIds {
- var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
- supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
- // 1.2.1. 接口传入信息填入
- supplierWithdrawInfo.SupplierId = req.SupplierId
- supplierWithdrawInfo.WithdrawStatus = 2
- supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
- supplierWithdrawInfo.BankNumber = supplierPaymentInfo.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)
- 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
- }
- func (*supplier) GetSupplierAmountBillList(ctx context.Context, req *http_model.SupplierAmountBillListRequest) (*http_model.SupplierAmountBillData, error) {
- return nil, nil
- }
- // GetManageInvoiceInfo 查找后台回票信息
- func (*supplier) GetManageInvoiceInfo(ctx context.Context, req *http_model.ManageInvoiceInfoRequest) (*http_model.ManageInvoiceInfoData, error) {
- var invoiceInfo *http_model.ManageInvoiceInfoData
- invoiceInfo = &http_model.ManageInvoiceInfoData{}
- manageInvoiceInfo, manageInvoiceErr := db.GetManageInvoice(ctx)
- if manageInvoiceErr != nil {
- return nil, manageInvoiceErr
- }
- if manageInvoiceInfo != nil {
- invoiceInfo.InvoiceInfoID = manageInvoiceInfo.InvoiceInfoID
- invoiceInfo.Address = manageInvoiceInfo.Address
- invoiceInfo.Phone = manageInvoiceInfo.Phone
- invoiceInfo.BankNumber = manageInvoiceInfo.BankNumber
- invoiceInfo.EnterpriseName = manageInvoiceInfo.EnterpriseName
- invoiceInfo.ProjectNameToChoose = manageInvoiceInfo.ProjectNameToChoose
- invoiceInfo.BankName = manageInvoiceInfo.BankName
- }
- return invoiceInfo, nil
- }
- // GetWithdrawAmount 查找可提现、提现中、已提现金额
- func (*supplier) GetWithdrawAmount(ctx context.Context, req *http_model.WithdrawAmountRequest) (*http_model.WithdrawAmountData, error) {
- var amountInfo *http_model.WithdrawAmountData
- amountInfo = &http_model.WithdrawAmountData{}
- amountInfo.WithdrawAble = 0.0
- amountInfo.PendingWithdraw = 0.0
- amountInfo.Withdrawn = 0.0
- // 可提现
- platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
- if platformConfirmingErr != nil {
- return nil, platformConfirmingErr
- }
- if platformConfirmingIncome != nil {
- for _, income := range platformConfirmingIncome {
- amountInfo.WithdrawAble += income.ServiceChargeSettle
- }
- }
- // 提现中
- pendingWithdrawIncome, pendingWithdrawErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 7)
- if pendingWithdrawErr != nil {
- return nil, pendingWithdrawErr
- }
- if pendingWithdrawIncome != nil {
- for _, income := range pendingWithdrawIncome {
- amountInfo.PendingWithdraw += income.ServiceChargeSettle
- }
- }
- // 已经提现
- withdrawnIncome, withdrawnErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 8)
- if withdrawnErr != nil {
- return nil, withdrawnErr
- }
- if withdrawnIncome != nil {
- for _, income := range withdrawnIncome {
- amountInfo.Withdrawn += income.ServiceChargeSettle
- }
- }
- return amountInfo, nil
- }
- // GetSupplierBillAmount 服务商账单 总余额、可提现金额
- func (*supplier) GetSupplierBillAmount(ctx context.Context, req *http_model.SupplierAmountRequest) (*http_model.SupplierBillAmountData, error) {
- var incomeData *http_model.SupplierBillAmountData
- incomeData = &http_model.SupplierBillAmountData{}
- incomeData.FullAmount = 0.0
- incomeData.Settle = 0.0
- // 1. 个人服务商
- if req.SupplierType == 1 {
- supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
- if supplierIncomeErr != nil {
- return nil, supplierIncomeErr
- }
- if supplierIncome != nil {
- for _, income := range supplierIncome {
- incomeData.FullAmount += income.ServiceChargeSettle
- }
- incomeData.Settle = incomeData.FullAmount
- }
- } else if req.SupplierType == 2 {
- // 2. 企业服务商
- // 可提现
- supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
- if supplierIncomeErr != nil {
- return nil, supplierIncomeErr
- }
- if supplierIncome != nil {
- for _, income := range supplierIncome {
- incomeData.Settle += income.ServiceChargeSettle
- }
- incomeData.FullAmount = incomeData.Settle
- }
- // 可回票
- supplierToInvoice, supplierToInvoiceErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
- if supplierToInvoiceErr != nil {
- return nil, supplierToInvoiceErr
- }
- if supplierToInvoice != nil {
- for _, invoice := range supplierToInvoice {
- incomeData.FullAmount += invoice.ServiceChargeSettle
- }
- }
- }
- // fmt.Println(incomeData)
- return incomeData, nil
- }
- // GetWithdrawPaymentInfo 查找提现收款信息
- func (*supplier) GetWithdrawPaymentInfo(ctx context.Context, req *http_model.WithdrawPaymentInfoRequest) (*http_model.WithdrawPaymentInfoData, error) {
- var paymentInfo *http_model.WithdrawPaymentInfoData
- paymentInfo = &http_model.WithdrawPaymentInfoData{}
- // 1. 个人服务商
- if req.SupplierType == 1 {
- // 1.1. 个人认证信息
- supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierErr != nil {
- return nil, supplierErr
- }
- if supplierInfo != nil {
- paymentInfo.Name = supplierInfo.Name
- paymentInfo.IDNumber = supplierInfo.IdNumber
- }
- // 1.2. 提现收款信息查询
- supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
- if supplierPaymentErr != nil {
- return nil, supplierPaymentErr
- }
- if supplierPaymentInfo != nil {
- paymentInfo.Tag = 2
- paymentInfo.Phone = supplierPaymentInfo.Phone
- paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
- paymentInfo.BankName = supplierPaymentInfo.BankName
- paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
- } else {
- paymentInfo.Tag = 1
- }
- } else if req.SupplierType == 2 {
- // 2. 机构服务商
- // 2.1. 机构认证信息
- supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
- if supplierErr != nil {
- return nil, supplierErr
- }
- if supplierInfo != nil {
- paymentInfo.Company = supplierInfo.CompanyName
- }
- // 2.2. 提现收款信息查询
- supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
- if supplierPaymentErr != nil {
- return nil, supplierPaymentErr
- }
- if supplierPaymentInfo != nil {
- paymentInfo.Tag = 2
- paymentInfo.PaymentInfoID = supplierPaymentInfo.PaymentInfoID
- paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
- paymentInfo.BankName = supplierPaymentInfo.BankName
- paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
- } else {
- paymentInfo.Tag = 1
- }
- }
- return paymentInfo, nil
- }
- // UpdateWithdrawPaymentInfo 更新提现收款信息
- func (*supplier) UpdateWithdrawPaymentInfo(ctx context.Context, req *http_model.UpdateWithdrawPaymentInfoRequest) error {
- var paymentInfo *gorm_model.SupplierPaymentInfo
- paymentInfo = &gorm_model.SupplierPaymentInfo{}
- paymentInfo.PaymentInfoID = req.PaymentInfoId
- paymentInfo.SupplierID = req.SupplierID
- paymentInfo.Phone = req.Phone
- paymentInfo.BankName = req.BankName
- paymentInfo.BankNumber = req.BankNumber
- paymentInfo.Name = req.Name
- paymentInfo.IDNumber = req.IDNumber
- paymentInfo.Company = req.Company
- updatePaymentInfoErr := db.UpdateSupplierPayment(ctx, paymentInfo)
- if updatePaymentInfoErr != nil {
- return updatePaymentInfoErr
- }
- return nil
- }
- // CreateWithdrawPaymentInfo 创建提现收款信息
- func (*supplier) CreateWithdrawPaymentInfo(ctx context.Context, req *http_model.CreateWithdrawPaymentInfoRequest) error {
- // 1. 个人服务商
- if req.SupplierType == 1 {
- var paymentInfo *gorm_model.SupplierPaymentInfo
- paymentInfo = &gorm_model.SupplierPaymentInfo{}
- paymentInfo.SupplierID = req.SupplierID
- paymentInfo.Phone = req.Phone
- paymentInfo.BankName = req.BankName
- paymentInfo.BankNumber = req.BankNumber
- paymentInfo.Name = req.Name
- paymentInfo.IDNumber = req.IDNumber
- paymentInfo.SupplierType = req.SupplierType
- createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
- if createPaymentInfoErr != nil {
- return createPaymentInfoErr
- }
- } else if req.SupplierType == 2 {
- // 2. 机构服务商
- var paymentInfo *gorm_model.SupplierPaymentInfo
- paymentInfo = &gorm_model.SupplierPaymentInfo{}
- paymentInfo.SupplierType = req.SupplierType
- paymentInfo.SupplierID = req.SupplierID
- paymentInfo.BankName = req.BankName
- paymentInfo.BankNumber = req.BankNumber
- paymentInfo.Name = req.Name
- paymentInfo.IDNumber = req.IDNumber
- paymentInfo.Company = req.Company
- createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
- if createPaymentInfoErr != nil {
- return createPaymentInfoErr
- }
- }
- return nil
- }
- // GetSupplierInvoiceAmount 可回发票、待传发票、平台确认中、已回发票金额
- func (*supplier) GetSupplierInvoiceAmount(ctx context.Context, req *http_model.InvoiceAmountRequest) (*http_model.InvoiceAmountData, error) {
- var invoiceAmount *http_model.InvoiceAmountData
- invoiceAmount = &http_model.InvoiceAmountData{}
- invoiceAmount.InvoiceReturned = 0.0
- invoiceAmount.PendingUpload = 0.0
- invoiceAmount.CanUpload = 0.0
- invoiceAmount.PlatformConfirming = 0.0
- // 可回发票
- supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
- if supplierIncomeErr != nil {
- return nil, supplierIncomeErr
- }
- if supplierIncome != nil {
- for _, income := range supplierIncome {
- invoiceAmount.CanUpload += income.ServiceChargeSettle
- }
- }
- // 待传发票
- pendingUploadIncome, pendingUploadErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 2)
- if pendingUploadErr != nil {
- return nil, pendingUploadErr
- }
- if pendingUploadIncome != nil {
- for _, income := range pendingUploadIncome {
- invoiceAmount.PendingUpload += income.ServiceChargeSettle
- }
- }
- // 平台确认中
- platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 3)
- if platformConfirmingErr != nil {
- return nil, platformConfirmingErr
- }
- if platformConfirmingIncome != nil {
- for _, income := range platformConfirmingIncome {
- invoiceAmount.PlatformConfirming += income.ServiceChargeSettle
- }
- }
- // 已回票
- InvoiceReturnedIncome, InvoiceReturnedErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
- if InvoiceReturnedErr != nil {
- return nil, InvoiceReturnedErr
- }
- if InvoiceReturnedIncome != nil {
- for _, income := range InvoiceReturnedIncome {
- invoiceAmount.InvoiceReturned += income.ServiceChargeSettle
- }
- }
- return invoiceAmount, nil
- }
|