12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- package service
- import (
- "context"
- "encoding/json"
- "fmt"
- openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
- dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v4/client"
- util "github.com/alibabacloud-go/tea-utils/v2/service"
- "github.com/alibabacloud-go/tea/tea"
- "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
- }
- func (*supplier) SendCodeT(ctx context.Context, phone string, code string) error {
- // 1. 创建客户端
- config := &openapi.Config{
- AccessKeyId: tea.String("LTAI5tDfTQeZ2ufN8mhsWQNA"),
- AccessKeySecret: tea.String("DKLd2hGbmJPcNki8p6VlU6mV2HXVvO"),
- Endpoint: tea.String("dysmsapi.aliyuncs.com"),
- }
- client, err := dysmsapi20170525.NewClient(config)
- if err != nil {
- return fmt.Errorf("创建客户端失败: %v", err)
- }
- // 2. 准备请求
- sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
- PhoneNumbers: tea.String(phone),
- SignName: tea.String("北京智子时空科技"),
- TemplateCode: tea.String("SMS_481650308"),
- TemplateParam: tea.String(fmt.Sprintf(`{"code":"%s"}`, code)),
- }
- // 3. 发送请求
- runtime := &util.RuntimeOptions{}
- resp, err := client.SendSmsWithOptions(sendSmsRequest, runtime)
- if err != nil {
- // 错误处理
- if sdkErr, ok := err.(*tea.SDKError); ok {
- var data interface{}
- if err := json.NewDecoder(strings.NewReader(tea.StringValue(sdkErr.Data))).Decode(&data); err == nil {
- if m, ok := data.(map[string]interface{}); ok {
- if recommend, exists := m["Recommend"]; exists {
- return fmt.Errorf("短信发送失败: %s, 建议: %v", tea.StringValue(sdkErr.Message), recommend)
- }
- }
- }
- return fmt.Errorf("短信发送失败: %s", tea.StringValue(sdkErr.Message))
- }
- return fmt.Errorf("短信发送失败: %v", err)
- }
- // 4. 响应
- fmt.Printf("短信发送成功,响应: %v\n", resp)
- return nil
- }
|