supplier.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  7. dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v4/client"
  8. util "github.com/alibabacloud-go/tea-utils/v2/service"
  9. "github.com/alibabacloud-go/tea/tea"
  10. "github.com/issue9/conv"
  11. log "github.com/sirupsen/logrus"
  12. "strconv"
  13. "strings"
  14. "time"
  15. "youngee_b_api/db"
  16. "youngee_b_api/model/gorm_model"
  17. "youngee_b_api/model/http_model"
  18. )
  19. var Supplier *supplier
  20. type supplier struct {
  21. }
  22. // CreateSupplier 创建younggee平台用户账号与服务商用户信息
  23. func (*supplier) CreateSupplier(ctx context.Context, phone string) (*http_model.RegisterData, error) {
  24. // 1. 创建YG平台用户
  25. userInfo := gorm_model.YounggeeUser{
  26. Phone: phone,
  27. User: "1003",
  28. Username: phone,
  29. Password: "1003",
  30. RealName: "",
  31. Role: "6",
  32. Email: "",
  33. LastLoginTime: time.Now().UTC().Local(),
  34. }
  35. userId, createUserErr := db.CreateUser(ctx, userInfo)
  36. if createUserErr != nil {
  37. log.Infof("[CreateSupplierUser] fail,err:%+v", createUserErr)
  38. return nil, createUserErr
  39. } else {
  40. // 2. 创建服务商信息
  41. supplierInfo := &gorm_model.YoungeeSupplier{
  42. SupplierName: phone,
  43. PhoneNumber: phone,
  44. UserId: *userId,
  45. }
  46. supplierId, createSupplierErr := db.CreateSupplier(ctx, *supplierInfo)
  47. fmt.Println(supplierId)
  48. if createSupplierErr != nil {
  49. log.Infof("[CreateSupplierUser] fail,err:%+v", createSupplierErr)
  50. return nil, createSupplierErr
  51. }
  52. res := &http_model.RegisterData{
  53. UserID: *userId,
  54. }
  55. return res, nil
  56. }
  57. }
  58. // GetSupplierAccountInfo 查询服务商账号信息
  59. func (*supplier) GetSupplierAccountInfo(ctx context.Context, req *http_model.GetAccountInfoRequest) (*http_model.GetAccountInfoData, error) {
  60. var supplierUserInfo *http_model.GetAccountInfoData
  61. supplierUserInfo = &http_model.GetAccountInfoData{}
  62. if req.SubAccountId == 0 {
  63. // 1. 服务商主账号
  64. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
  65. if supplierInfoErr != nil {
  66. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierInfoErr)
  67. return nil, supplierInfoErr
  68. }
  69. if supplierInfo != nil {
  70. supplierUserInfo.SupplierName = supplierInfo.SupplierName
  71. supplierUserInfo.Type = 1
  72. supplierUserInfo.Avatar = supplierInfo.Avatar
  73. supplierUserInfo.Phone = supplierInfo.PhoneNumber
  74. }
  75. } else {
  76. // 2. 服务商子账号
  77. subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, req.SubAccountId)
  78. if subAccountInfoErr != nil {
  79. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", subAccountInfoErr)
  80. return nil, subAccountInfoErr
  81. }
  82. if subAccountInfo != nil {
  83. supplierUserInfo.SubAccountName = subAccountInfo.SubAccountName
  84. supplierUserInfo.Type = 2
  85. supplierUserInfo.Avatar = subAccountInfo.Avatar
  86. supplierUserInfo.Phone = subAccountInfo.PhoneNumber
  87. jobInfo, jobInfoErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
  88. if jobInfoErr != nil {
  89. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", jobInfoErr)
  90. return nil, subAccountInfoErr
  91. }
  92. if jobInfo != nil {
  93. supplierUserInfo.JobName = jobInfo.JobName
  94. }
  95. }
  96. }
  97. return supplierUserInfo, nil
  98. }
  99. // GetSupplierReviewInfo 查询服务商认证信息
  100. func (*supplier) GetSupplierReviewInfo(ctx context.Context, req *http_model.GetReviewInfoRequest) (*http_model.GetReviewInfoData, error) {
  101. var supplierUserInfo *http_model.GetReviewInfoData
  102. supplierUserInfo = &http_model.GetReviewInfoData{}
  103. // 1. 服务商信息
  104. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
  105. if supplierInfoErr != nil {
  106. log.Infof("[GetSupplierReviewInfo] fail,err:%+v", supplierInfoErr)
  107. return nil, supplierInfoErr
  108. }
  109. if supplierInfo != nil {
  110. if supplierInfo.ReviewStatus == 1 {
  111. supplierUserInfo.ReviewStatus = 1
  112. } else if supplierInfo.SupplierType == 1 {
  113. supplierUserInfo.ReviewStatus = 2
  114. supplierUserInfo.SupplierType = 1
  115. supplierUserInfo.IdBack = supplierInfo.IdBack
  116. supplierUserInfo.IdFront = supplierInfo.IdFront
  117. supplierUserInfo.IdNumber = supplierInfo.IdNumber
  118. supplierUserInfo.Name = supplierInfo.Name
  119. } else if supplierInfo.SupplierType == 2 {
  120. supplierUserInfo.ReviewStatus = 2
  121. supplierUserInfo.SupplierType = 2
  122. supplierUserInfo.CompanyName = supplierInfo.CompanyName
  123. supplierUserInfo.USCI = supplierInfo.Usci
  124. supplierUserInfo.BusinessLicense = supplierInfo.BusinessLicense
  125. }
  126. }
  127. return supplierUserInfo, nil
  128. }
  129. // GetSupplierContactInfo 查询服务商联系方式
  130. func (*supplier) GetSupplierContactInfo(ctx context.Context, req *http_model.GetContactInfoRequest) (*http_model.GetContactInfoData, error) {
  131. var contactInfo *http_model.GetContactInfoData
  132. contactInfo = &http_model.GetContactInfoData{}
  133. // 1. 服务商主账号
  134. if req.SubAccountId == 0 {
  135. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
  136. if supplierInfoErr != nil {
  137. log.Infof("[GetSupplierContactInfo] fail,err:%+v", supplierInfoErr)
  138. return nil, supplierInfoErr
  139. }
  140. if supplierInfo != nil {
  141. contactInfo.ContactPhone = supplierInfo.ContactPhone
  142. contactInfo.WechatQRCode = supplierInfo.WechatQrCode
  143. contactInfo.WechatNumber = supplierInfo.WechatNumber
  144. }
  145. } else {
  146. // 2. 服务商子账号
  147. subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, req.SubAccountId)
  148. if subAccountInfoErr != nil {
  149. log.Infof("[GetSupplierContactInfo] fail,err:%+v", subAccountInfoErr)
  150. return nil, subAccountInfoErr
  151. }
  152. if subAccountInfo != nil {
  153. contactInfo.ContactPhone = subAccountInfo.ContactPhone
  154. contactInfo.WechatQRCode = subAccountInfo.WechatQRCode
  155. contactInfo.WechatNumber = subAccountInfo.WechatNumber
  156. }
  157. }
  158. return contactInfo, nil
  159. }
  160. // SaveSupplierReviewInfo 保存服务商联系方式
  161. func (*supplier) SaveSupplierReviewInfo(ctx context.Context, req *http_model.SaveReviewRequest) error {
  162. var supplierInfo *gorm_model.YoungeeSupplier
  163. supplierInfo = &gorm_model.YoungeeSupplier{}
  164. // 1. 个人服务商
  165. if req.SupplierType == 1 {
  166. supplierInfo.SupplierId = req.SupplierId
  167. supplierInfo.IdFront = req.IdCardUrl
  168. supplierInfo.IdNumber = req.IdNumber
  169. supplierInfo.Name = req.Name
  170. supplierInfo.IdBack = req.IdBack
  171. supplierInfo.SupplierType = req.SupplierType
  172. supplierInfo.ReviewStatus = 2
  173. updateErr := db.UpdateSupplier(ctx, supplierInfo)
  174. if updateErr != nil {
  175. log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
  176. return updateErr
  177. }
  178. } else if req.SupplierType == 2 {
  179. // 2. 企业服务商
  180. supplierInfo.SupplierId = req.SupplierId
  181. supplierInfo.ReviewStatus = 2
  182. supplierInfo.SupplierType = req.SupplierType
  183. supplierInfo.CompanyName = req.CompanyName
  184. supplierInfo.Usci = req.USCI
  185. supplierInfo.BusinessLicense = req.BusinessLicenseUrl
  186. updateErr := db.UpdateSupplier(ctx, supplierInfo)
  187. if updateErr != nil {
  188. log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
  189. return updateErr
  190. }
  191. }
  192. return nil
  193. }
  194. // GetSupplierIncomeList 查询服务商收入列表
  195. func (*supplier) GetSupplierIncomeList(ctx context.Context, req *http_model.FullSProjectIncomeListRequest) (*http_model.FullSProjectIncomeData, error) {
  196. var sProjectIncomeData *http_model.FullSProjectIncomeData
  197. sProjectIncomeData = &http_model.FullSProjectIncomeData{}
  198. // 1. 查询
  199. supplierIncome, total, err := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.IncomeStatus)
  200. if err != nil {
  201. return nil, nil
  202. }
  203. // 2. 补充种草/本地生活任务信息
  204. if supplierIncome != nil {
  205. sProjectIncomeData.Total = total
  206. for _, income := range supplierIncome {
  207. // 2.1. 种草任务基本信息
  208. if income.IncomeType == 1 {
  209. var sProjectInfo *http_model.FullSProjectIncomeListResponse
  210. sProjectInfo = &http_model.FullSProjectIncomeListResponse{}
  211. sProjectData, sProjectErr := db.GetSProjectDetail(ctx, income.SProjectID)
  212. if sProjectErr != nil {
  213. log.Infof("[GetSProjectDetail] fail,err:%+v", sProjectErr)
  214. return nil, sProjectErr
  215. }
  216. if sProjectData != nil {
  217. sProjectInfo.SProjectId = sProjectData.SProjectId
  218. sProjectInfo.IncomeId = income.IncomeID
  219. sProjectInfo.IncomeType = income.IncomeType
  220. sProjectInfo.SProjectId = sProjectData.SProjectId
  221. sProjectInfo.ProjectName = sProjectData.ProjectName
  222. sProjectInfo.ProjectPlatform = sProjectData.ProjectPlatform
  223. sProjectInfo.ServiceCharge = sProjectData.ServiceCharge
  224. sProjectInfo.ServiceChargeSettle = sProjectData.ServiceChargeSettle
  225. sProjectInfo.RecruitNum = sProjectData.RecruitNum
  226. sProjectInfo.SettleNum = sProjectData.SettleNum
  227. sProjectInfo.FinishTime = conv.MustString(sProjectData.FinishTime)
  228. // 2.2. 商品基本信息
  229. productInfo, productErr := db.GetProductByID(ctx, sProjectData.ProductId)
  230. if productErr != nil {
  231. log.Infof("[GetProductByID] fail,err:%+v", productErr)
  232. return nil, productErr
  233. }
  234. if productInfo != nil {
  235. sProjectInfo.ProductName = productInfo.ProductName
  236. sProjectInfo.ProductPrice = productInfo.ProductPrice
  237. }
  238. // 2.3. 商品图片信息
  239. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProjectData.ProductId)
  240. if productPhotoErr != nil {
  241. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", productPhotoErr)
  242. return nil, productPhotoErr
  243. }
  244. if productPhotoInfo != nil {
  245. for _, photo := range productPhotoInfo {
  246. fmt.Println(photo)
  247. if photo.Symbol == 1 {
  248. sProjectInfo.ProductPhotoSymbol = 1
  249. sProjectInfo.ProductPhotoUrl = photo.PhotoUrl
  250. sProjectInfo.ProductPhotoUid = photo.PhotoUid
  251. }
  252. }
  253. }
  254. // 2.4. 加入商单操作人信息
  255. if sProjectData.SubAccountId == 0 {
  256. sProjectInfo.SOperatorType = 1
  257. sProjectInfo.SOperatorId = sProjectData.SupplierId
  258. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, sProjectData.SupplierId)
  259. if supplierInfoErr != nil {
  260. log.Infof("[GetSupplierById] fail,err:%+v", supplierInfoErr)
  261. return nil, supplierInfoErr
  262. }
  263. if supplierInfo != nil {
  264. sProjectInfo.SOperatorName = supplierInfo.Name
  265. }
  266. sProjectInfo.SOperatorName = conv.MustString(sProjectData.SupplierId)
  267. } else {
  268. sProjectInfo.SOperatorType = 2
  269. sProjectInfo.SOperatorId = sProjectData.SubAccountId
  270. subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, sProjectData.SubAccountId)
  271. if subAccountInfoErr != nil {
  272. log.Infof("[FindSubAccountById] fail,err:%+v", subAccountInfoErr)
  273. return nil, subAccountInfoErr
  274. }
  275. if subAccountInfo != nil {
  276. sProjectInfo.SOperatorName = subAccountInfo.SubAccountName
  277. }
  278. }
  279. sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sProjectInfo)
  280. }
  281. }
  282. // 2.1. 本地生活任务基本信息
  283. if income.IncomeType == 2 {
  284. var sLocalInfo *http_model.FullSProjectIncomeListResponse
  285. sLocalInfo = &http_model.FullSProjectIncomeListResponse{}
  286. sLocalData, sLocalErr := db.GetSLocalLifeDetail(ctx, income.SLocalID)
  287. if sLocalErr != nil {
  288. log.Infof("[GetSLocalLifeDetail] fail,err:%+v", sLocalErr)
  289. return nil, sLocalErr
  290. }
  291. if sLocalData != nil {
  292. sLocalInfo.IncomeId = income.IncomeID
  293. sLocalInfo.IncomeType = income.IncomeType
  294. sLocalInfo.SLocalId = sLocalData.SLocalId
  295. sLocalInfo.LocalName = sLocalData.LocalName
  296. sLocalInfo.LocalPlatform = sLocalData.LocalPlatform
  297. sLocalInfo.ServiceCharge = sLocalData.ServiceCharge
  298. sLocalInfo.ServiceChargeSettle = sLocalData.ServiceChargeSettle
  299. sLocalInfo.RecruitNum = sLocalData.RecruitNum
  300. sLocalInfo.SettleNum = sLocalData.SettleNum
  301. sLocalInfo.FinishTime = conv.MustString(sLocalData.FinishTime)
  302. // 2.2. 门店基本信息
  303. storeInfo, storeErr := db.FindStoreById(ctx, sLocalData.StoreId)
  304. if storeErr != nil {
  305. log.Infof("[GetProductByID] fail,err:%+v", storeErr)
  306. return nil, storeErr
  307. }
  308. if storeInfo != nil {
  309. sLocalInfo.StoreName = storeInfo.StoreName
  310. }
  311. // 2.3. 门店图片信息
  312. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, sLocalData.StoreId)
  313. if storePhotoErr != nil {
  314. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", storePhotoErr)
  315. return nil, storePhotoErr
  316. }
  317. if storePhotoInfo != nil {
  318. for _, photo := range storePhotoInfo {
  319. fmt.Println(photo)
  320. if photo.Symbol == 1 {
  321. sLocalInfo.StoreMainPhotoSymbol = 1
  322. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  323. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  324. }
  325. }
  326. }
  327. sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sLocalInfo)
  328. }
  329. }
  330. }
  331. } else {
  332. sProjectIncomeData.Total = 0
  333. }
  334. return sProjectIncomeData, nil
  335. }
  336. // CreateSupplierInvoice 创建服务商发票
  337. func (*supplier) CreateSupplierInvoice(ctx context.Context, req *http_model.CreateSupplierInvoiceRequest) error {
  338. // 1. 数据转换
  339. var invoiceData *gorm_model.YounggeeSupplierInvoice
  340. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  341. SupplierId: req.SupplierId,
  342. InvoiceStatus: 1,
  343. IncomeIds: req.IncomeIds,
  344. }
  345. if req.SOperatorType == 1 {
  346. invoiceData.SOperatorType = 1
  347. invoiceData.SOperator = req.SupplierId
  348. } else if req.SOperatorType == 2 {
  349. invoiceData.SOperatorType = 2
  350. invoiceData.SOperator = req.SubAccountId
  351. }
  352. // 2. 插入数据库
  353. err := db.CreateSupplierInvoice(ctx, invoiceData)
  354. if err != nil {
  355. return err
  356. }
  357. return nil
  358. }
  359. // UpdateSupplierInvoice 更新服务商发票
  360. func (*supplier) UpdateSupplierInvoice(ctx context.Context, req *http_model.UpdateSupplierInvoiceRequest) error {
  361. // 1. 数据转换
  362. var invoiceData *gorm_model.YounggeeSupplierInvoice
  363. var currentTime time.Time
  364. currentTime = time.Now()
  365. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  366. InvoiceId: req.InvoiceId,
  367. InvoiceUrl: req.InvoiceUrl,
  368. Company: req.Company,
  369. UploadInvoiceTime: &currentTime,
  370. }
  371. // 2. 更新
  372. err := db.UpdateSupplierInvoice(ctx, invoiceData)
  373. if err != nil {
  374. return err
  375. }
  376. // 3. 更新服务商收入状态
  377. incomeIds, dbErr := db.GetIncomeIdsByInvoiceId(ctx, req.InvoiceId)
  378. if dbErr != nil {
  379. return dbErr
  380. }
  381. if incomeIds == "" {
  382. return nil
  383. }
  384. strSlice := strings.Split(incomeIds, ",")
  385. intSlice := make([]int, len(strSlice))
  386. for i, s := range strSlice {
  387. num, err := strconv.Atoi(s)
  388. if err != nil {
  389. fmt.Println("转换错误:", err)
  390. return err
  391. }
  392. intSlice[i] = num
  393. }
  394. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, 3)
  395. if updateSupplierIncomeErr != nil {
  396. return updateSupplierIncomeErr
  397. }
  398. return nil
  399. }
  400. // UpdateSupplierIncomeStatus 修改服务商收入状态
  401. func (*supplier) UpdateSupplierIncomeStatus(ctx context.Context, incomeIds string, incomeStatus int) error {
  402. // 1. 转换incomeIds为数组
  403. strSlice := strings.Split(incomeIds, ",")
  404. intSlice := make([]int, len(strSlice))
  405. for i, s := range strSlice {
  406. num, err := strconv.Atoi(s)
  407. if err != nil {
  408. fmt.Println("转换错误:", err)
  409. return err
  410. }
  411. intSlice[i] = num
  412. }
  413. // 2. 修改数据库中数据
  414. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, incomeStatus)
  415. if updateSupplierIncomeErr != nil {
  416. return updateSupplierIncomeErr
  417. }
  418. return nil
  419. }
  420. // GetSupplierInvoiceList 查找服务商发票列表
  421. func (*supplier) GetSupplierInvoiceList(ctx context.Context, req *http_model.SupplierInvoiceListRequest) (*http_model.SupplierInvoiceListData, error) {
  422. // 1. 查询服务商发票信息
  423. supplierInvoiceList, total, err := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, req.InvoiceStatus, 4, req.PageSize, req.PageNum)
  424. if err != nil {
  425. return nil, err
  426. }
  427. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  428. var supplierInvoiceData *http_model.SupplierInvoiceListData
  429. supplierInvoiceData = &http_model.SupplierInvoiceListData{}
  430. for _, supplierInvoice := range supplierInvoiceList {
  431. var supplierInvoiceInfo *http_model.SupplierInvoiceInfo
  432. supplierInvoiceInfo = &http_model.SupplierInvoiceInfo{}
  433. // 2.1. 基础信息填入
  434. supplierInvoiceInfo.UploadInvoiceTime = supplierInvoice.UploadInvoiceTime
  435. supplierInvoiceInfo.InvoiceUrl = supplierInvoice.InvoiceUrl
  436. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  437. supplierInvoiceInfo.RejectTime = supplierInvoice.RejectTime
  438. supplierInvoiceInfo.Company = supplierInvoice.Company
  439. supplierInvoiceInfo.SOperator = supplierInvoice.SOperator
  440. supplierInvoiceInfo.FailReason = supplierInvoice.FailReason
  441. // 2.2. 任务及其收入信息填入
  442. incomeIds := supplierInvoice.IncomeIds
  443. strSlice := strings.Split(incomeIds, ",")
  444. intSlice := make([]int, len(strSlice))
  445. for i, s := range strSlice {
  446. num, err := strconv.Atoi(s)
  447. if err != nil {
  448. fmt.Println("转换错误:", err)
  449. return nil, err
  450. }
  451. intSlice[i] = num
  452. }
  453. for _, incomeId := range intSlice {
  454. var sTaskInfo *http_model.STaskInfo
  455. sTaskInfo = &http_model.STaskInfo{}
  456. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  457. if incomeErr != nil {
  458. return nil, incomeErr
  459. }
  460. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  461. supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
  462. if currIncome.IncomeType == 1 {
  463. sTaskInfo.Id = currIncome.SProjectID
  464. } else if currIncome.IncomeType == 3 {
  465. sTaskInfo.Id = currIncome.SLocalID
  466. }
  467. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  468. }
  469. supplierInvoiceData.SupplierInvoiceList = append(supplierInvoiceData.SupplierInvoiceList, supplierInvoiceInfo)
  470. }
  471. supplierInvoiceData.Total = total
  472. return supplierInvoiceData, nil
  473. }
  474. // GetSupplierToWithdrawList 服务商待提现列表
  475. func (*supplier) GetSupplierToWithdrawList(ctx context.Context, req *http_model.SupplierToWithdrawListRequest) (*http_model.SupplierToWithdrawListData, error) {
  476. // 1. 判断服务商类型
  477. var supplierInvoiceData *http_model.SupplierToWithdrawListData
  478. supplierInvoiceData = &http_model.SupplierToWithdrawListData{}
  479. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  480. if supplierErr != nil {
  481. return nil, supplierErr
  482. }
  483. if supplierInfo != nil {
  484. // 企业服务商
  485. if supplierInfo.SupplierType == 2 {
  486. // 查询企业服务商发票信息
  487. supplierInvoiceList, total, supplierInvoiceErr := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, 3, 1, req.PageSize, req.PageNum)
  488. if supplierInvoiceErr != nil {
  489. return nil, supplierInvoiceErr
  490. }
  491. if supplierInvoiceList != nil {
  492. for _, supplierInvoice := range supplierInvoiceList {
  493. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  494. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  495. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  496. // supplierInvoiceInfo.Amount = 0.0
  497. // 2.1. 基础信息填入
  498. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  499. supplierInvoiceInfo.Company = supplierInvoice.Company
  500. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  501. // 2.2. 任务及其收入信息填入
  502. incomeIds := supplierInvoice.IncomeIds
  503. strSlice := strings.Split(incomeIds, ",")
  504. intSlice := make([]int, len(strSlice))
  505. for i, s := range strSlice {
  506. num, err := strconv.Atoi(s)
  507. if err != nil {
  508. fmt.Println("转换错误:", err)
  509. return nil, err
  510. }
  511. intSlice[i] = num
  512. }
  513. for _, incomeId := range intSlice {
  514. var sTaskInfo *http_model.STaskInfo
  515. sTaskInfo = &http_model.STaskInfo{}
  516. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  517. if incomeErr != nil {
  518. return nil, incomeErr
  519. }
  520. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  521. supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
  522. if currIncome.IncomeType == 1 {
  523. sTaskInfo.Id = currIncome.SProjectID
  524. } else if currIncome.IncomeType == 3 {
  525. sTaskInfo.Id = currIncome.SLocalID
  526. }
  527. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  528. }
  529. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  530. }
  531. supplierInvoiceData.Total = total
  532. }
  533. } else if supplierInfo.SupplierType == 1 {
  534. // 个人服务商
  535. // 查询个人服务商收入信息
  536. supplierIncomeList, supplierIncomeTotal, supplierIncomeErr := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, 5)
  537. if supplierIncomeErr != nil {
  538. return nil, supplierIncomeErr
  539. }
  540. if supplierIncomeList != nil {
  541. supplierInvoiceData.Total = supplierIncomeTotal
  542. for _, supplierIncome := range supplierIncomeList {
  543. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  544. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  545. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  546. supplierInvoiceInfo.IncomeId = supplierIncome.IncomeID
  547. supplierInvoiceInfo.Amount = supplierIncome.ServiceChargeSettle
  548. supplierInvoiceInfo.AmountActual = supplierIncome.ServiceChargeSettle * 0.05
  549. var sTaskInfo *http_model.STaskInfo
  550. sTaskInfo = &http_model.STaskInfo{}
  551. sTaskInfo.ServiceCharge = supplierIncome.ServiceChargeSettle
  552. if supplierIncome.IncomeType == 1 {
  553. sTaskInfo.Id = supplierIncome.SProjectID
  554. } else if supplierIncome.IncomeType == 3 {
  555. sTaskInfo.Id = supplierIncome.SLocalID
  556. }
  557. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  558. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  559. }
  560. }
  561. }
  562. }
  563. return supplierInvoiceData, nil
  564. }
  565. // CreateSupplierWithdraw 创建服务商提现信息
  566. func (*supplier) CreateSupplierWithdraw(ctx context.Context, req *http_model.CreateSupplierWithdrawRequest) error {
  567. var supplierWithdrawInfoList []*gorm_model.YounggeeSupplierWithdraw
  568. // 1. 判断服务商类型
  569. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  570. if supplierErr != nil {
  571. return supplierErr
  572. }
  573. if supplierInfo != nil {
  574. if supplierInfo.SupplierType == 1 {
  575. // 1.1. 个人服务商
  576. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
  577. if supplierPaymentErr != nil {
  578. return supplierPaymentErr
  579. }
  580. if supplierPaymentInfo != nil {
  581. for _, withdrawInfo := range req.IncomeIds {
  582. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  583. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  584. // 1.2.1. 接口传入信息填入
  585. supplierWithdrawInfo.SupplierId = req.SupplierId
  586. supplierWithdrawInfo.WithdrawStatus = 2
  587. supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
  588. supplierWithdrawInfo.BankNumber = supplierPaymentInfo.BankNumber
  589. var currentTime time.Time
  590. currentTime = time.Now()
  591. supplierWithdrawInfo.SupplyTime = &currentTime
  592. supplierWithdrawInfo.WithdrawAmount = 0.0
  593. // 1.2.2. 查找服务商信息填入
  594. supplierWithdrawInfo.Name = supplierInfo.Name
  595. supplierWithdrawInfo.Phone = supplierPaymentInfo.Phone
  596. // 1.2.3. 收入信息填入
  597. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, withdrawInfo)
  598. if incomeInfoErr != nil {
  599. return incomeInfoErr
  600. }
  601. if currIncome != nil {
  602. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  603. }
  604. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  605. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  606. }
  607. }
  608. } else if supplierInfo.SupplierType == 2 {
  609. // 1.2. 机构服务商
  610. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
  611. if supplierPaymentErr != nil {
  612. return supplierPaymentErr
  613. }
  614. if supplierPaymentInfo != nil {
  615. for _, withdrawInfo := range req.InvoiceIds {
  616. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  617. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  618. // 1.2.1. 接口传入信息填入
  619. supplierWithdrawInfo.SupplierId = req.SupplierId
  620. supplierWithdrawInfo.WithdrawStatus = 2
  621. supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
  622. supplierWithdrawInfo.BankNumber = supplierPaymentInfo.BankNumber
  623. var currentTime time.Time
  624. currentTime = time.Now()
  625. supplierWithdrawInfo.SupplyTime = &currentTime
  626. supplierWithdrawInfo.WithdrawAmount = 0.0
  627. // 1.2.2. 查找服务商信息填入
  628. supplierWithdrawInfo.Name = supplierInfo.Name
  629. supplierWithdrawInfo.Phone = supplierInfo.PhoneNumber
  630. supplierWithdrawInfo.Company = supplierInfo.CompanyName
  631. // 1.2.3. 收入信息填入
  632. incomeIds, incomeErr := db.GetIncomeIdsByInvoiceId(ctx, withdrawInfo)
  633. if incomeErr != nil {
  634. return incomeErr
  635. }
  636. if incomeIds != "" {
  637. strSlice := strings.Split(incomeIds, ",")
  638. intSlice := make([]int, len(strSlice))
  639. for i, s := range strSlice {
  640. num, err := strconv.Atoi(s)
  641. if err != nil {
  642. fmt.Println("转换错误:", err)
  643. return err
  644. }
  645. intSlice[i] = num
  646. }
  647. for _, incomeId := range intSlice {
  648. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  649. if incomeInfoErr != nil {
  650. return incomeInfoErr
  651. }
  652. if currIncome != nil {
  653. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  654. }
  655. }
  656. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  657. }
  658. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  659. }
  660. }
  661. }
  662. }
  663. // 2. 数据库插入
  664. err := db.CreateSupplierWithdraw(ctx, supplierWithdrawInfoList)
  665. if err != nil {
  666. return err
  667. }
  668. return nil
  669. }
  670. // GetSupplierWithdrawList 服务商提现列表
  671. func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.SupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
  672. var supplierWithdrawListData *http_model.SupplierWithdrawListData
  673. supplierWithdrawListData = &http_model.SupplierWithdrawListData{}
  674. // 1. 根据服务商ID和提现状态去查找提现信息列表
  675. supplierWithdrawList, total, supplierWithdrawErr := db.GetSupplierWithdrawList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.WithdrawStatus)
  676. if supplierWithdrawErr != nil {
  677. return nil, supplierWithdrawErr
  678. }
  679. if supplierWithdrawList != nil {
  680. supplierWithdrawListData.Total = total
  681. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  682. if supplierErr != nil {
  683. return nil, supplierErr
  684. }
  685. if supplierInfo != nil {
  686. if supplierInfo.SupplierId == 1 {
  687. // 2. 个人服务商
  688. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  689. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  690. for _, withdrawInfo := range supplierWithdrawList {
  691. IncomeId, IncomeIdErr := strconv.Atoi(withdrawInfo.IncomeIds)
  692. if IncomeIdErr != nil {
  693. return nil, IncomeIdErr
  694. }
  695. incomeInfo, incomeErr := db.GetIncomeInfoByIncomeId(ctx, IncomeId)
  696. if incomeErr != nil {
  697. return nil, incomeErr
  698. }
  699. if incomeInfo != nil {
  700. var sTaskInfo *http_model.STaskInfo
  701. sTaskInfo = &http_model.STaskInfo{}
  702. if incomeInfo.IncomeType == 1 {
  703. sTaskInfo.Id = incomeInfo.SProjectID
  704. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  705. } else if incomeInfo.IncomeType == 3 {
  706. sTaskInfo.Id = incomeInfo.SLocalID
  707. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  708. }
  709. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  710. }
  711. supplierWithdrawInfo.SupplierType = 1
  712. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  713. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  714. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  715. supplierWithdrawInfo.Name = withdrawInfo.Name
  716. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  717. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  718. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  719. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  720. // supplierWithdrawInfo.Company = withdrawInfo.Company
  721. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  722. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  723. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  724. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  725. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  726. }
  727. } else if supplierInfo.SupplierId == 2 {
  728. // 3. 企业服务商
  729. for _, withdrawInfo := range supplierWithdrawList {
  730. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  731. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  732. InvoiceId, InvoiceIdErr := strconv.Atoi(withdrawInfo.InvoiceIds)
  733. if InvoiceIdErr != nil {
  734. return nil, InvoiceIdErr
  735. }
  736. incomeIds, incomeIdsErr := db.GetIncomeIdsByInvoiceId(ctx, InvoiceId)
  737. if incomeIdsErr != nil {
  738. return nil, incomeIdsErr
  739. }
  740. if incomeIds != "" {
  741. strSlice := strings.Split(incomeIds, ",")
  742. intSlice := make([]int, len(strSlice))
  743. for i, s := range strSlice {
  744. num, err := strconv.Atoi(s)
  745. if err != nil {
  746. fmt.Println("转换错误:", err)
  747. return nil, err
  748. }
  749. intSlice[i] = num
  750. }
  751. for _, incomeId := range intSlice {
  752. var sTaskInfo *http_model.STaskInfo
  753. sTaskInfo = &http_model.STaskInfo{}
  754. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  755. if incomeInfoErr != nil {
  756. return nil, incomeInfoErr
  757. }
  758. if currIncome != nil {
  759. if currIncome.IncomeType == 1 {
  760. sTaskInfo.Id = currIncome.SProjectID
  761. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  762. } else if currIncome.IncomeType == 3 {
  763. sTaskInfo.Id = currIncome.SLocalID
  764. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  765. }
  766. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  767. }
  768. }
  769. }
  770. supplierWithdrawInfo.SupplierType = 1
  771. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  772. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  773. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  774. supplierWithdrawInfo.Name = withdrawInfo.Name
  775. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  776. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  777. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  778. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  779. supplierWithdrawInfo.Company = withdrawInfo.Company
  780. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  781. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  782. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  783. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  784. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  785. }
  786. }
  787. }
  788. }
  789. return supplierWithdrawListData, nil
  790. }
  791. func (*supplier) GetSupplierAmountBillList(ctx context.Context, req *http_model.SupplierAmountBillListRequest) (*http_model.SupplierAmountBillData, error) {
  792. return nil, nil
  793. }
  794. // GetManageInvoiceInfo 查找后台回票信息
  795. func (*supplier) GetManageInvoiceInfo(ctx context.Context, req *http_model.ManageInvoiceInfoRequest) (*http_model.ManageInvoiceInfoData, error) {
  796. var invoiceInfo *http_model.ManageInvoiceInfoData
  797. invoiceInfo = &http_model.ManageInvoiceInfoData{}
  798. manageInvoiceInfo, manageInvoiceErr := db.GetManageInvoice(ctx)
  799. if manageInvoiceErr != nil {
  800. return nil, manageInvoiceErr
  801. }
  802. if manageInvoiceInfo != nil {
  803. invoiceInfo.InvoiceInfoID = manageInvoiceInfo.InvoiceInfoID
  804. invoiceInfo.Address = manageInvoiceInfo.Address
  805. invoiceInfo.Phone = manageInvoiceInfo.Phone
  806. invoiceInfo.BankNumber = manageInvoiceInfo.BankNumber
  807. invoiceInfo.EnterpriseName = manageInvoiceInfo.EnterpriseName
  808. invoiceInfo.ProjectNameToChoose = manageInvoiceInfo.ProjectNameToChoose
  809. invoiceInfo.BankName = manageInvoiceInfo.BankName
  810. }
  811. return invoiceInfo, nil
  812. }
  813. // GetWithdrawAmount 查找可提现、提现中、已提现金额
  814. func (*supplier) GetWithdrawAmount(ctx context.Context, req *http_model.WithdrawAmountRequest) (*http_model.WithdrawAmountData, error) {
  815. var amountInfo *http_model.WithdrawAmountData
  816. amountInfo = &http_model.WithdrawAmountData{}
  817. amountInfo.WithdrawAble = 0.0
  818. amountInfo.PendingWithdraw = 0.0
  819. amountInfo.Withdrawn = 0.0
  820. // 可提现
  821. platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  822. if platformConfirmingErr != nil {
  823. return nil, platformConfirmingErr
  824. }
  825. if platformConfirmingIncome != nil {
  826. for _, income := range platformConfirmingIncome {
  827. amountInfo.WithdrawAble += income.ServiceChargeSettle
  828. }
  829. }
  830. // 提现中
  831. pendingWithdrawIncome, pendingWithdrawErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 7)
  832. if pendingWithdrawErr != nil {
  833. return nil, pendingWithdrawErr
  834. }
  835. if pendingWithdrawIncome != nil {
  836. for _, income := range pendingWithdrawIncome {
  837. amountInfo.PendingWithdraw += income.ServiceChargeSettle
  838. }
  839. }
  840. // 已经提现
  841. withdrawnIncome, withdrawnErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 8)
  842. if withdrawnErr != nil {
  843. return nil, withdrawnErr
  844. }
  845. if withdrawnIncome != nil {
  846. for _, income := range withdrawnIncome {
  847. amountInfo.Withdrawn += income.ServiceChargeSettle
  848. }
  849. }
  850. return amountInfo, nil
  851. }
  852. // GetSupplierBillAmount 服务商账单 总余额、可提现金额
  853. func (*supplier) GetSupplierBillAmount(ctx context.Context, req *http_model.SupplierAmountRequest) (*http_model.SupplierBillAmountData, error) {
  854. var incomeData *http_model.SupplierBillAmountData
  855. incomeData = &http_model.SupplierBillAmountData{}
  856. incomeData.FullAmount = 0.0
  857. incomeData.Settle = 0.0
  858. // 1. 个人服务商
  859. if req.SupplierType == 1 {
  860. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  861. if supplierIncomeErr != nil {
  862. return nil, supplierIncomeErr
  863. }
  864. if supplierIncome != nil {
  865. for _, income := range supplierIncome {
  866. incomeData.FullAmount += income.ServiceChargeSettle
  867. }
  868. incomeData.Settle = incomeData.FullAmount
  869. }
  870. } else if req.SupplierType == 2 {
  871. // 2. 企业服务商
  872. // 可提现
  873. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  874. if supplierIncomeErr != nil {
  875. return nil, supplierIncomeErr
  876. }
  877. if supplierIncome != nil {
  878. for _, income := range supplierIncome {
  879. incomeData.Settle += income.ServiceChargeSettle
  880. }
  881. incomeData.FullAmount = incomeData.Settle
  882. }
  883. // 可回票
  884. supplierToInvoice, supplierToInvoiceErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
  885. if supplierToInvoiceErr != nil {
  886. return nil, supplierToInvoiceErr
  887. }
  888. if supplierToInvoice != nil {
  889. for _, invoice := range supplierToInvoice {
  890. incomeData.FullAmount += invoice.ServiceChargeSettle
  891. }
  892. }
  893. }
  894. // fmt.Println(incomeData)
  895. return incomeData, nil
  896. }
  897. // GetWithdrawPaymentInfo 查找提现收款信息
  898. func (*supplier) GetWithdrawPaymentInfo(ctx context.Context, req *http_model.WithdrawPaymentInfoRequest) (*http_model.WithdrawPaymentInfoData, error) {
  899. var paymentInfo *http_model.WithdrawPaymentInfoData
  900. paymentInfo = &http_model.WithdrawPaymentInfoData{}
  901. // 1. 个人服务商
  902. if req.SupplierType == 1 {
  903. // 1.1. 个人认证信息
  904. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  905. if supplierErr != nil {
  906. return nil, supplierErr
  907. }
  908. if supplierInfo != nil {
  909. paymentInfo.Name = supplierInfo.Name
  910. paymentInfo.IDNumber = supplierInfo.IdNumber
  911. }
  912. // 1.2. 提现收款信息查询
  913. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
  914. if supplierPaymentErr != nil {
  915. return nil, supplierPaymentErr
  916. }
  917. if supplierPaymentInfo != nil {
  918. paymentInfo.Tag = 2
  919. paymentInfo.Phone = supplierPaymentInfo.Phone
  920. paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
  921. paymentInfo.BankName = supplierPaymentInfo.BankName
  922. paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
  923. } else {
  924. paymentInfo.Tag = 1
  925. }
  926. } else if req.SupplierType == 2 {
  927. // 2. 机构服务商
  928. // 2.1. 机构认证信息
  929. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  930. if supplierErr != nil {
  931. return nil, supplierErr
  932. }
  933. if supplierInfo != nil {
  934. paymentInfo.Company = supplierInfo.CompanyName
  935. }
  936. // 2.2. 提现收款信息查询
  937. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
  938. if supplierPaymentErr != nil {
  939. return nil, supplierPaymentErr
  940. }
  941. if supplierPaymentInfo != nil {
  942. paymentInfo.Tag = 2
  943. paymentInfo.PaymentInfoID = supplierPaymentInfo.PaymentInfoID
  944. paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
  945. paymentInfo.BankName = supplierPaymentInfo.BankName
  946. paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
  947. } else {
  948. paymentInfo.Tag = 1
  949. }
  950. }
  951. return paymentInfo, nil
  952. }
  953. // UpdateWithdrawPaymentInfo 更新提现收款信息
  954. func (*supplier) UpdateWithdrawPaymentInfo(ctx context.Context, req *http_model.UpdateWithdrawPaymentInfoRequest) error {
  955. var paymentInfo *gorm_model.SupplierPaymentInfo
  956. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  957. paymentInfo.PaymentInfoID = req.PaymentInfoId
  958. paymentInfo.SupplierID = req.SupplierID
  959. paymentInfo.Phone = req.Phone
  960. paymentInfo.BankName = req.BankName
  961. paymentInfo.BankNumber = req.BankNumber
  962. paymentInfo.Name = req.Name
  963. paymentInfo.IDNumber = req.IDNumber
  964. paymentInfo.Company = req.Company
  965. updatePaymentInfoErr := db.UpdateSupplierPayment(ctx, paymentInfo)
  966. if updatePaymentInfoErr != nil {
  967. return updatePaymentInfoErr
  968. }
  969. return nil
  970. }
  971. // CreateWithdrawPaymentInfo 创建提现收款信息
  972. func (*supplier) CreateWithdrawPaymentInfo(ctx context.Context, req *http_model.CreateWithdrawPaymentInfoRequest) error {
  973. // 1. 个人服务商
  974. if req.SupplierType == 1 {
  975. var paymentInfo *gorm_model.SupplierPaymentInfo
  976. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  977. paymentInfo.SupplierID = req.SupplierID
  978. paymentInfo.Phone = req.Phone
  979. paymentInfo.BankName = req.BankName
  980. paymentInfo.BankNumber = req.BankNumber
  981. paymentInfo.Name = req.Name
  982. paymentInfo.IDNumber = req.IDNumber
  983. paymentInfo.SupplierType = req.SupplierType
  984. createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
  985. if createPaymentInfoErr != nil {
  986. return createPaymentInfoErr
  987. }
  988. } else if req.SupplierType == 2 {
  989. // 2. 机构服务商
  990. var paymentInfo *gorm_model.SupplierPaymentInfo
  991. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  992. paymentInfo.SupplierType = req.SupplierType
  993. paymentInfo.SupplierID = req.SupplierID
  994. paymentInfo.BankName = req.BankName
  995. paymentInfo.BankNumber = req.BankNumber
  996. paymentInfo.Name = req.Name
  997. paymentInfo.IDNumber = req.IDNumber
  998. paymentInfo.Company = req.Company
  999. createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
  1000. if createPaymentInfoErr != nil {
  1001. return createPaymentInfoErr
  1002. }
  1003. }
  1004. return nil
  1005. }
  1006. // GetSupplierInvoiceAmount 可回发票、待传发票、平台确认中、已回发票金额
  1007. func (*supplier) GetSupplierInvoiceAmount(ctx context.Context, req *http_model.InvoiceAmountRequest) (*http_model.InvoiceAmountData, error) {
  1008. var invoiceAmount *http_model.InvoiceAmountData
  1009. invoiceAmount = &http_model.InvoiceAmountData{}
  1010. invoiceAmount.InvoiceReturned = 0.0
  1011. invoiceAmount.PendingUpload = 0.0
  1012. invoiceAmount.CanUpload = 0.0
  1013. invoiceAmount.PlatformConfirming = 0.0
  1014. // 可回发票
  1015. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
  1016. if supplierIncomeErr != nil {
  1017. return nil, supplierIncomeErr
  1018. }
  1019. if supplierIncome != nil {
  1020. for _, income := range supplierIncome {
  1021. invoiceAmount.CanUpload += income.ServiceChargeSettle
  1022. }
  1023. }
  1024. // 待传发票
  1025. pendingUploadIncome, pendingUploadErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 2)
  1026. if pendingUploadErr != nil {
  1027. return nil, pendingUploadErr
  1028. }
  1029. if pendingUploadIncome != nil {
  1030. for _, income := range pendingUploadIncome {
  1031. invoiceAmount.PendingUpload += income.ServiceChargeSettle
  1032. }
  1033. }
  1034. // 平台确认中
  1035. platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 3)
  1036. if platformConfirmingErr != nil {
  1037. return nil, platformConfirmingErr
  1038. }
  1039. if platformConfirmingIncome != nil {
  1040. for _, income := range platformConfirmingIncome {
  1041. invoiceAmount.PlatformConfirming += income.ServiceChargeSettle
  1042. }
  1043. }
  1044. // 已回票
  1045. InvoiceReturnedIncome, InvoiceReturnedErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  1046. if InvoiceReturnedErr != nil {
  1047. return nil, InvoiceReturnedErr
  1048. }
  1049. if InvoiceReturnedIncome != nil {
  1050. for _, income := range InvoiceReturnedIncome {
  1051. invoiceAmount.InvoiceReturned += income.ServiceChargeSettle
  1052. }
  1053. }
  1054. return invoiceAmount, nil
  1055. }
  1056. func (*supplier) SendCodeT(ctx context.Context, phone string, code string) error {
  1057. // 1. 创建客户端
  1058. config := &openapi.Config{
  1059. AccessKeyId: tea.String("LTAI5tDfTQeZ2ufN8mhsWQNA"),
  1060. AccessKeySecret: tea.String("DKLd2hGbmJPcNki8p6VlU6mV2HXVvO"),
  1061. Endpoint: tea.String("dysmsapi.aliyuncs.com"),
  1062. }
  1063. client, err := dysmsapi20170525.NewClient(config)
  1064. if err != nil {
  1065. return fmt.Errorf("创建客户端失败: %v", err)
  1066. }
  1067. // 2. 准备请求
  1068. sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
  1069. PhoneNumbers: tea.String(phone),
  1070. SignName: tea.String("北京智子时空科技"),
  1071. TemplateCode: tea.String("SMS_481650308"),
  1072. TemplateParam: tea.String(fmt.Sprintf(`{"code":"%s"}`, code)),
  1073. }
  1074. // 3. 发送请求
  1075. runtime := &util.RuntimeOptions{}
  1076. resp, err := client.SendSmsWithOptions(sendSmsRequest, runtime)
  1077. if err != nil {
  1078. // 错误处理
  1079. if sdkErr, ok := err.(*tea.SDKError); ok {
  1080. var data interface{}
  1081. if err := json.NewDecoder(strings.NewReader(tea.StringValue(sdkErr.Data))).Decode(&data); err == nil {
  1082. if m, ok := data.(map[string]interface{}); ok {
  1083. if recommend, exists := m["Recommend"]; exists {
  1084. return fmt.Errorf("短信发送失败: %s, 建议: %v", tea.StringValue(sdkErr.Message), recommend)
  1085. }
  1086. }
  1087. }
  1088. return fmt.Errorf("短信发送失败: %s", tea.StringValue(sdkErr.Message))
  1089. }
  1090. return fmt.Errorf("短信发送失败: %v", err)
  1091. }
  1092. // 4. 响应
  1093. fmt.Printf("短信发送成功,响应: %v\n", resp)
  1094. return nil
  1095. }