1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- 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
- }
- // UpdateSupplierAccountInfo 更新服务商账号信息
- func (l *loginAuth) UpdateSupplierAccountInfo(ctx context.Context, req *http_model.UpdateAccountInfoRequest) (*http_model.UpdateAccountInfoData, int, error) {
- var supplierUserInfo *http_model.UpdateAccountInfoData
- supplierUserInfo = &http_model.UpdateAccountInfoData{}
- supplierUserInfo.SupplierName = req.SupplierName
- supplierUserInfo.Avatar = req.Avatar
- supplierUserInfo.Phone = req.Phone
- supplierUserInfo.SubAccountName = req.SubAccountName
- if req.SubAccountId == 0 {
- // 服务商主账号
- // 1. 若修改绑定手机号
- if req.Phone != "" {
- // 1.1. 校验验证码
- vCode, err := l.getSessionCode(ctx, req.Phone)
- if err != nil {
- return nil, 0, err
- }
- if vCode != req.Code {
- return nil, 1, nil
- }
- // 1.2. 手机号是否已经被其他主账号绑定
- supplierNum, supplierNumErr := db.CountSupplierUserByPhone(ctx, req.Phone)
- if supplierNumErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierNumErr)
- return nil, 0, supplierNumErr
- }
- if supplierNum != 0 {
- return nil, 2, nil
- }
- // 1.3. 手机号是否被子账号绑定
- subAccountNum, SubAccountErr := db.CountSubAccountUserByPhone(ctx, req.Phone)
- if SubAccountErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", SubAccountErr)
- return nil, 0, SubAccountErr
- }
- if subAccountNum != 0 {
- return nil, 3, nil
- }
- // 1.4. 修改Supplier信息
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- supplierInfo.SupplierId = req.SupplierId
- supplierInfo.SupplierName = req.SupplierName
- supplierInfo.Avatar = req.Avatar
- supplierInfo.PhoneNumber = req.Phone
- updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSupplierErr)
- return nil, 0, updateSupplierErr
- }
- // 1.5. 修改User表信息
- supplierInfoQuery, supplierInfoQueryErr := db.GetSupplierById(ctx, supplierInfo.SupplierId)
- if supplierInfoQueryErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierInfoQueryErr)
- return nil, 0, supplierInfoQueryErr
- }
- if supplierInfoQuery != nil {
- var userInfo *gorm_model.YounggeeUser
- userInfo = &gorm_model.YounggeeUser{}
- userInfo.ID = supplierInfoQuery.UserId
- userInfo.Phone = supplierInfoQuery.PhoneNumber
- userInfo.Username = supplierInfoQuery.PhoneNumber
- updateUserInfoErr := db.UpdateUserById(ctx, userInfo)
- if updateUserInfoErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateUserInfoErr)
- return nil, 0, updateUserInfoErr
- }
- }
- } else {
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- supplierInfo.SupplierId = req.SupplierId
- supplierInfo.SupplierName = req.SupplierName
- supplierInfo.Avatar = req.Avatar
- supplierInfo.PhoneNumber = req.Phone
- updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSupplierErr)
- return nil, 0, updateSupplierErr
- }
- }
- } else {
- // 服务商子账号
- var subAccountInfo *gorm_model.YounggeeSubAccount
- subAccountInfo = &gorm_model.YounggeeSubAccount{}
- subAccountInfo.SubAccountId = req.SubAccountId
- subAccountInfo.SubAccountType = 3
- subAccountInfo.SupplierId = req.SupplierId
- subAccountInfo.SubAccountName = req.SubAccountName
- subAccountInfo.Avatar = req.Avatar
- subAccountInfo.PhoneNumber = req.Phone
- updateSubAccountErr := db.UpdateSubAccount(ctx, subAccountInfo)
- if updateSubAccountErr != nil {
- log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSubAccountErr)
- return nil, 0, updateSubAccountErr
- }
- }
- return supplierUserInfo, 0, 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
- }
- // UpdateSupplierContactInfo 更新服务商联系方式
- func (l *loginAuth) UpdateSupplierContactInfo(ctx context.Context, req *http_model.UpdateContactInfoRequest) (*http_model.UpdateContactInfoData, bool, error) {
- var contactInfo *http_model.UpdateContactInfoData
- contactInfo = &http_model.UpdateContactInfoData{}
- // 主账号
- if req.SubAccountId == 0 {
- // 1. 若更新联系电话则需要验证码校验
- if req.ContactPhone != "" {
- vcode, err := l.getSessionCode(ctx, req.ContactPhone)
- if err != nil {
- return nil, false, err
- }
- // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
- if vcode != req.Code {
- // 验证码错误
- return nil, true, err
- }
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- supplierInfo.ContactPhone = req.ContactPhone
- supplierInfo.SupplierId = req.SupplierId
- updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.ContactPhone = req.ContactPhone
- }
- // 2. 微信二维码更新
- if req.WechatQRCode != "" {
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- supplierInfo.WechatQrCode = req.WechatQRCode
- supplierInfo.SupplierId = req.SupplierId
- updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.WechatQRCode = req.WechatQRCode
- }
- // 2. 微信号码更新
- if req.WechatNumber != "" {
- var supplierInfo *gorm_model.YoungeeSupplier
- supplierInfo = &gorm_model.YoungeeSupplier{}
- supplierInfo.WechatNumber = req.WechatNumber
- supplierInfo.SupplierId = req.SupplierId
- updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.WechatNumber = req.WechatNumber
- }
- } else {
- // 子账号
- // 1. 若更新联系电话则需要验证码校验
- if req.ContactPhone != "" {
- vcode, err := l.getSessionCode(ctx, req.ContactPhone)
- if err != nil {
- return nil, false, err
- }
- // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
- if vcode != req.Code {
- // 验证码错误
- return nil, true, err
- }
- var supplierInfo *gorm_model.YounggeeSubAccount
- supplierInfo = &gorm_model.YounggeeSubAccount{}
- supplierInfo.ContactPhone = req.ContactPhone
- supplierInfo.SubAccountId = req.SubAccountId
- updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.ContactPhone = req.ContactPhone
- }
- // 2. 微信二维码更新
- if req.WechatQRCode != "" {
- var supplierInfo *gorm_model.YounggeeSubAccount
- supplierInfo = &gorm_model.YounggeeSubAccount{}
- supplierInfo.WechatQRCode = req.WechatQRCode
- supplierInfo.SubAccountId = req.SubAccountId
- updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.WechatQRCode = req.WechatQRCode
- }
- // 2. 微信号码更新
- if req.WechatNumber != "" {
- var supplierInfo *gorm_model.YounggeeSubAccount
- supplierInfo = &gorm_model.YounggeeSubAccount{}
- supplierInfo.WechatNumber = req.WechatNumber
- supplierInfo.SubAccountId = req.SubAccountId
- updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
- if updateSupplierErr != nil {
- log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
- return nil, false, updateSupplierErr
- }
- contactInfo.WechatNumber = req.WechatNumber
- }
- }
- return contactInfo, true, 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
- }
|