supplier.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. log "github.com/sirupsen/logrus"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "youngee_b_api/db"
  11. "youngee_b_api/model/gorm_model"
  12. "youngee_b_api/model/http_model"
  13. )
  14. var Supplier *supplier
  15. type supplier struct {
  16. }
  17. // CreateSupplier 创建younggee平台用户账号与服务商用户信息
  18. func (*supplier) CreateSupplier(ctx context.Context, phone string) (*http_model.RegisterData, error) {
  19. // 1. 创建YG平台用户
  20. userInfo := gorm_model.YounggeeUser{
  21. Phone: phone,
  22. User: "1003",
  23. Username: phone,
  24. Password: "1003",
  25. RealName: "",
  26. Role: "6",
  27. Email: "",
  28. LastLoginTime: time.Now().UTC().Local(),
  29. }
  30. userId, createUserErr := db.CreateUser(ctx, userInfo)
  31. if createUserErr != nil {
  32. log.Infof("[CreateSupplierUser] fail,err:%+v", createUserErr)
  33. return nil, createUserErr
  34. } else {
  35. // 2. 创建服务商信息
  36. supplierInfo := &gorm_model.YoungeeSupplier{
  37. SupplierName: phone,
  38. PhoneNumber: phone,
  39. UserId: *userId,
  40. }
  41. supplierId, createSupplierErr := db.CreateSupplier(ctx, *supplierInfo)
  42. fmt.Println(supplierId)
  43. if createSupplierErr != nil {
  44. log.Infof("[CreateSupplierUser] fail,err:%+v", createSupplierErr)
  45. return nil, createSupplierErr
  46. }
  47. res := &http_model.RegisterData{
  48. UserID: *userId,
  49. }
  50. return res, nil
  51. }
  52. }
  53. // GetSupplierIncomeList 查询服务商收入列表
  54. func (*supplier) GetSupplierIncomeList(ctx context.Context, req *http_model.FullSProjectIncomeListRequest) (*http_model.FullSProjectIncomeData, error) {
  55. var sProjectIncomeData *http_model.FullSProjectIncomeData
  56. sProjectIncomeData = &http_model.FullSProjectIncomeData{}
  57. // 1. 查询
  58. supplierIncome, total, err := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.IncomeStatus)
  59. if err != nil {
  60. return nil, nil
  61. }
  62. // 2. 补充种草/本地生活任务信息
  63. if supplierIncome != nil {
  64. sProjectIncomeData.Total = total
  65. for _, income := range supplierIncome {
  66. // 2.1. 种草任务基本信息
  67. if income.IncomeType == 1 {
  68. var sProjectInfo *http_model.FullSProjectIncomeListResponse
  69. sProjectInfo = &http_model.FullSProjectIncomeListResponse{}
  70. sProjectData, sProjectErr := db.GetSProjectDetail(ctx, income.SProjectID)
  71. if sProjectErr != nil {
  72. log.Infof("[GetSProjectDetail] fail,err:%+v", sProjectErr)
  73. return nil, sProjectErr
  74. }
  75. if sProjectData != nil {
  76. sProjectInfo.SProjectId = sProjectData.SProjectId
  77. sProjectInfo.IncomeId = income.IncomeID
  78. sProjectInfo.IncomeType = income.IncomeType
  79. sProjectInfo.SProjectId = sProjectData.SProjectId
  80. sProjectInfo.ProjectName = sProjectData.ProjectName
  81. sProjectInfo.ProjectPlatform = sProjectData.ProjectPlatform
  82. sProjectInfo.ServiceCharge = sProjectData.ServiceCharge
  83. sProjectInfo.ServiceChargeSettle = sProjectData.ServiceChargeSettle
  84. sProjectInfo.FinishTime = conv.MustString(sProjectData.FinishTime)
  85. // 2.2. 商品基本信息
  86. productInfo, productErr := db.GetProductByID(ctx, sProjectData.ProductId)
  87. if productErr != nil {
  88. log.Infof("[GetProductByID] fail,err:%+v", productErr)
  89. return nil, productErr
  90. }
  91. if productInfo != nil {
  92. sProjectInfo.ProductName = productInfo.ProductName
  93. sProjectInfo.ProductPrice = productInfo.ProductPrice
  94. }
  95. // 2.3. 商品图片信息
  96. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProjectData.ProductId)
  97. if productPhotoErr != nil {
  98. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", productPhotoErr)
  99. return nil, productPhotoErr
  100. }
  101. if productPhotoInfo != nil {
  102. for _, photo := range productPhotoInfo {
  103. fmt.Println(photo)
  104. if photo.Symbol == 1 {
  105. sProjectInfo.ProductPhotoSymbol = 1
  106. sProjectInfo.ProductPhotoUrl = photo.PhotoUrl
  107. sProjectInfo.ProductPhotoUid = photo.PhotoUid
  108. }
  109. }
  110. }
  111. }
  112. }
  113. // 2.1. 本地生活任务基本信息
  114. if income.IncomeType == 2 {
  115. var sLocalInfo *http_model.FullSProjectIncomeListResponse
  116. sLocalInfo = &http_model.FullSProjectIncomeListResponse{}
  117. sLocalData, sLocalErr := db.GetSLocalLifeDetail(ctx, income.SLocalID)
  118. if sLocalErr != nil {
  119. log.Infof("[GetSLocalLifeDetail] fail,err:%+v", sLocalErr)
  120. return nil, sLocalErr
  121. }
  122. if sLocalData != nil {
  123. sLocalInfo.IncomeId = income.IncomeID
  124. sLocalInfo.IncomeType = income.IncomeType
  125. sLocalInfo.SLocalId = sLocalData.SLocalId
  126. sLocalInfo.LocalName = sLocalData.LocalName
  127. sLocalInfo.LocalPlatform = sLocalData.LocalPlatform
  128. sLocalInfo.ServiceCharge = sLocalData.ServiceCharge
  129. sLocalInfo.ServiceChargeSettle = sLocalData.ServiceChargeSettle
  130. sLocalInfo.FinishTime = conv.MustString(sLocalData.FinishTime)
  131. // 2.2. 门店基本信息
  132. storeInfo, storeErr := db.FindStoreById(ctx, sLocalData.StoreId)
  133. if storeErr != nil {
  134. log.Infof("[GetProductByID] fail,err:%+v", storeErr)
  135. return nil, storeErr
  136. }
  137. if storeInfo != nil {
  138. sLocalInfo.StoreName = storeInfo.StoreName
  139. }
  140. // 2.3. 门店图片信息
  141. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, sLocalData.StoreId)
  142. if storePhotoErr != nil {
  143. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", storePhotoErr)
  144. return nil, storePhotoErr
  145. }
  146. if storePhotoInfo != nil {
  147. for _, photo := range storePhotoInfo {
  148. fmt.Println(photo)
  149. if photo.Symbol == 1 {
  150. sLocalInfo.StoreMainPhotoSymbol = 1
  151. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  152. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. } else {
  160. sProjectIncomeData.Total = 0
  161. }
  162. return sProjectIncomeData, nil
  163. }
  164. // CreateSupplierInvoice 创建服务商发票
  165. func (*supplier) CreateSupplierInvoice(ctx context.Context, req *http_model.CreateSupplierInvoiceRequest) error {
  166. // 1. 数据转换
  167. var invoiceData *gorm_model.YounggeeSupplierInvoice
  168. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  169. SupplierId: req.SupplierId,
  170. InvoiceStatus: 1,
  171. IncomeIds: req.IncomeIds,
  172. }
  173. if req.SOperatorType == 1 {
  174. invoiceData.SOperatorType = 1
  175. invoiceData.SOperator = req.SupplierId
  176. } else if req.SOperatorType == 2 {
  177. invoiceData.SOperatorType = 2
  178. invoiceData.SOperator = req.SubAccountId
  179. }
  180. // 2. 插入数据库
  181. err := db.CreateSupplierInvoice(ctx, invoiceData)
  182. if err != nil {
  183. return err
  184. }
  185. return nil
  186. }
  187. // UpdateSupplierInvoice 更新服务商发票
  188. func (*supplier) UpdateSupplierInvoice(ctx context.Context, req *http_model.UpdateSupplierInvoiceRequest) error {
  189. // 1. 数据转换
  190. var invoiceData *gorm_model.YounggeeSupplierInvoice
  191. var currentTime time.Time
  192. currentTime = time.Now()
  193. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  194. InvoiceId: req.InvoiceId,
  195. InvoiceUrl: req.InvoiceUrl,
  196. Company: req.Company,
  197. UploadInvoiceTime: &currentTime,
  198. }
  199. // 2. 更新
  200. err := db.UpdateSupplierInvoice(ctx, invoiceData)
  201. if err != nil {
  202. return err
  203. }
  204. // 3. 更新服务商收入状态
  205. incomeIds, dbErr := db.GetIncomeIdsByInvoiceId(ctx, req.InvoiceId)
  206. if dbErr != nil {
  207. return dbErr
  208. }
  209. if incomeIds == "" {
  210. return nil
  211. }
  212. strSlice := strings.Split(incomeIds, ",")
  213. intSlice := make([]int, len(strSlice))
  214. for i, s := range strSlice {
  215. num, err := strconv.Atoi(s)
  216. if err != nil {
  217. fmt.Println("转换错误:", err)
  218. return err
  219. }
  220. intSlice[i] = num
  221. }
  222. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, 3)
  223. if updateSupplierIncomeErr != nil {
  224. return updateSupplierIncomeErr
  225. }
  226. return nil
  227. }
  228. // UpdateSupplierIncomeStatus 修改服务商收入状态
  229. func (*supplier) UpdateSupplierIncomeStatus(ctx context.Context, incomeIds string, incomeStatus int) error {
  230. // 1. 转换incomeIds为数组
  231. strSlice := strings.Split(incomeIds, ",")
  232. intSlice := make([]int, len(strSlice))
  233. for i, s := range strSlice {
  234. num, err := strconv.Atoi(s)
  235. if err != nil {
  236. fmt.Println("转换错误:", err)
  237. return err
  238. }
  239. intSlice[i] = num
  240. }
  241. // 2. 修改数据库中数据
  242. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, incomeStatus)
  243. if updateSupplierIncomeErr != nil {
  244. return updateSupplierIncomeErr
  245. }
  246. return nil
  247. }
  248. // GetSupplierInvoiceList 查找服务商发票列表
  249. func (*supplier) GetSupplierInvoiceList(ctx context.Context, req *http_model.SupplierInvoiceListRequest) (*http_model.SupplierInvoiceListData, error) {
  250. // 1. 查询服务商发票信息
  251. supplierInvoiceList, total, err := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, req.InvoiceStatus, 4, req.PageSize, req.PageNum)
  252. if err != nil {
  253. return nil, err
  254. }
  255. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  256. var supplierInvoiceData *http_model.SupplierInvoiceListData
  257. supplierInvoiceData = &http_model.SupplierInvoiceListData{}
  258. for _, supplierInvoice := range supplierInvoiceList {
  259. var supplierInvoiceInfo *http_model.SupplierInvoiceInfo
  260. supplierInvoiceInfo = &http_model.SupplierInvoiceInfo{}
  261. // 2.1. 基础信息填入
  262. supplierInvoiceInfo.UploadInvoiceTime = supplierInvoice.UploadInvoiceTime
  263. supplierInvoiceInfo.InvoiceUrl = supplierInvoice.InvoiceUrl
  264. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  265. supplierInvoiceInfo.RejectTime = supplierInvoice.RejectTime
  266. supplierInvoiceInfo.Company = supplierInvoice.Company
  267. supplierInvoiceInfo.SOperator = supplierInvoice.SOperator
  268. supplierInvoiceInfo.FailReason = supplierInvoice.FailReason
  269. // 2.2. 任务及其收入信息填入
  270. incomeIds := supplierInvoice.IncomeIds
  271. strSlice := strings.Split(incomeIds, ",")
  272. intSlice := make([]int, len(strSlice))
  273. for i, s := range strSlice {
  274. num, err := strconv.Atoi(s)
  275. if err != nil {
  276. fmt.Println("转换错误:", err)
  277. return nil, err
  278. }
  279. intSlice[i] = num
  280. }
  281. for _, incomeId := range intSlice {
  282. var sTaskInfo *http_model.STaskInfo
  283. sTaskInfo = &http_model.STaskInfo{}
  284. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  285. if incomeErr != nil {
  286. return nil, incomeErr
  287. }
  288. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  289. if currIncome.IncomeType == 1 {
  290. sTaskInfo.Id = currIncome.SProjectID
  291. } else if currIncome.IncomeType == 3 {
  292. sTaskInfo.Id = currIncome.SLocalID
  293. }
  294. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  295. }
  296. supplierInvoiceData.SupplierInvoiceList = append(supplierInvoiceData.SupplierInvoiceList, supplierInvoiceInfo)
  297. }
  298. supplierInvoiceData.Total = total
  299. return supplierInvoiceData, nil
  300. }
  301. // GetSupplierToWithdrawList 服务商待提现列表
  302. func (*supplier) GetSupplierToWithdrawList(ctx context.Context, req *http_model.SupplierToWithdrawListRequest) (*http_model.SupplierToWithdrawListData, error) {
  303. // 1. 判断服务商类型
  304. var supplierInvoiceData *http_model.SupplierToWithdrawListData
  305. supplierInvoiceData = &http_model.SupplierToWithdrawListData{}
  306. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  307. if supplierErr != nil {
  308. return nil, supplierErr
  309. }
  310. if supplierInfo != nil {
  311. // 企业服务商
  312. if supplierInfo.SupplierType == 2 {
  313. // 查询企业服务商发票信息
  314. supplierInvoiceList, total, supplierInvoiceErr := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, 3, 1, req.PageSize, req.PageNum)
  315. if supplierInvoiceErr != nil {
  316. return nil, supplierInvoiceErr
  317. }
  318. if supplierInvoiceList != nil {
  319. for _, supplierInvoice := range supplierInvoiceList {
  320. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  321. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  322. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  323. // 2.1. 基础信息填入
  324. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  325. supplierInvoiceInfo.Company = supplierInvoice.Company
  326. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  327. // 2.2. 任务及其收入信息填入
  328. incomeIds := supplierInvoice.IncomeIds
  329. strSlice := strings.Split(incomeIds, ",")
  330. intSlice := make([]int, len(strSlice))
  331. for i, s := range strSlice {
  332. num, err := strconv.Atoi(s)
  333. if err != nil {
  334. fmt.Println("转换错误:", err)
  335. return nil, err
  336. }
  337. intSlice[i] = num
  338. }
  339. for _, incomeId := range intSlice {
  340. var sTaskInfo *http_model.STaskInfo
  341. sTaskInfo = &http_model.STaskInfo{}
  342. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  343. if incomeErr != nil {
  344. return nil, incomeErr
  345. }
  346. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  347. supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
  348. if currIncome.IncomeType == 1 {
  349. sTaskInfo.Id = currIncome.SProjectID
  350. } else if currIncome.IncomeType == 3 {
  351. sTaskInfo.Id = currIncome.SLocalID
  352. }
  353. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  354. }
  355. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  356. }
  357. supplierInvoiceData.Total = total
  358. }
  359. } else if supplierInfo.SupplierType == 1 {
  360. // 个人服务商
  361. // 查询个人服务商收入信息
  362. supplierIncomeList, supplierIncomeTotal, supplierIncomeErr := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, 5)
  363. if supplierIncomeErr != nil {
  364. return nil, supplierIncomeErr
  365. }
  366. if supplierIncomeList != nil {
  367. supplierInvoiceData.Total = supplierIncomeTotal
  368. for _, supplierIncome := range supplierIncomeList {
  369. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  370. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  371. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  372. supplierInvoiceInfo.IncomeId = supplierIncome.IncomeID
  373. supplierInvoiceInfo.Amount = supplierIncome.ServiceChargeSettle
  374. supplierInvoiceInfo.AmountActual = supplierIncome.ServiceChargeSettle * 0.05
  375. var sTaskInfo *http_model.STaskInfo
  376. sTaskInfo = &http_model.STaskInfo{}
  377. sTaskInfo.ServiceCharge = supplierIncome.ServiceChargeSettle
  378. if supplierIncome.IncomeType == 1 {
  379. sTaskInfo.Id = supplierIncome.SProjectID
  380. } else if supplierIncome.IncomeType == 3 {
  381. sTaskInfo.Id = supplierIncome.SLocalID
  382. }
  383. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  384. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  385. }
  386. }
  387. }
  388. }
  389. return supplierInvoiceData, nil
  390. }
  391. // CreateSupplierWithdraw 创建服务商提现信息
  392. func (*supplier) CreateSupplierWithdraw(ctx context.Context, req *http_model.CreateSupplierWithdrawRequest) error {
  393. var supplierWithdrawInfoList []*gorm_model.YounggeeSupplierWithdraw
  394. // 1. 判断服务商类型
  395. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  396. if supplierErr != nil {
  397. return supplierErr
  398. }
  399. if supplierInfo != nil {
  400. if supplierInfo.SupplierType == 1 {
  401. // 1.1. 个人服务商
  402. for _, withdrawInfo := range req.CreatePersonSupplierWithdraw {
  403. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  404. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  405. // 1.2.1. 接口传入信息填入
  406. supplierWithdrawInfo.SupplierId = req.SupplierId
  407. supplierWithdrawInfo.WithdrawStatus = 2
  408. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  409. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  410. var currentTime time.Time
  411. currentTime = time.Now()
  412. supplierWithdrawInfo.SupplyTime = &currentTime
  413. supplierWithdrawInfo.WithdrawAmount = 0.0
  414. // 1.2.2. 查找服务商信息填入
  415. supplierWithdrawInfo.Name = supplierInfo.Name
  416. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  417. // 1.2.3. 收入信息填入
  418. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, withdrawInfo.IncomeId)
  419. if incomeInfoErr != nil {
  420. return incomeInfoErr
  421. }
  422. if currIncome != nil {
  423. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  424. }
  425. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  426. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  427. }
  428. } else if supplierInfo.SupplierType == 2 {
  429. // 1.2. 机构服务商
  430. for _, withdrawInfo := range req.CreateCompanySupplierWithdraw {
  431. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  432. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  433. // 1.2.1. 接口传入信息填入
  434. supplierWithdrawInfo.SupplierId = req.SupplierId
  435. supplierWithdrawInfo.WithdrawStatus = 2
  436. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  437. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  438. var currentTime time.Time
  439. currentTime = time.Now()
  440. supplierWithdrawInfo.SupplyTime = &currentTime
  441. supplierWithdrawInfo.WithdrawAmount = 0.0
  442. // 1.2.2. 查找服务商信息填入
  443. supplierWithdrawInfo.Name = supplierInfo.Name
  444. supplierWithdrawInfo.Phone = supplierInfo.PhoneNumber
  445. supplierWithdrawInfo.Company = supplierInfo.CompanyName
  446. // 1.2.3. 收入信息填入
  447. incomeIds, incomeErr := db.GetIncomeIdsByInvoiceId(ctx, withdrawInfo.InvoiceId)
  448. if incomeErr != nil {
  449. return incomeErr
  450. }
  451. if incomeIds != "" {
  452. strSlice := strings.Split(incomeIds, ",")
  453. intSlice := make([]int, len(strSlice))
  454. for i, s := range strSlice {
  455. num, err := strconv.Atoi(s)
  456. if err != nil {
  457. fmt.Println("转换错误:", err)
  458. return err
  459. }
  460. intSlice[i] = num
  461. }
  462. for _, incomeId := range intSlice {
  463. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  464. if incomeInfoErr != nil {
  465. return incomeInfoErr
  466. }
  467. if currIncome != nil {
  468. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  469. }
  470. }
  471. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  472. }
  473. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  474. }
  475. }
  476. }
  477. // 2. 数据库插入
  478. err := db.CreateSupplierWithdraw(ctx, supplierWithdrawInfoList)
  479. if err != nil {
  480. return err
  481. }
  482. return nil
  483. }
  484. // GetSupplierWithdrawList 服务商提现列表
  485. func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.SupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
  486. var supplierWithdrawListData *http_model.SupplierWithdrawListData
  487. supplierWithdrawListData = &http_model.SupplierWithdrawListData{}
  488. // 1. 根据服务商ID和提现状态去查找提现信息列表
  489. supplierWithdrawList, total, supplierWithdrawErr := db.GetSupplierWithdrawList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.WithdrawStatus)
  490. if supplierWithdrawErr != nil {
  491. return nil, supplierWithdrawErr
  492. }
  493. if supplierWithdrawList != nil {
  494. supplierWithdrawListData.Total = total
  495. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  496. if supplierErr != nil {
  497. return nil, supplierErr
  498. }
  499. if supplierInfo != nil {
  500. if supplierInfo.SupplierId == 1 {
  501. // 2. 个人服务商
  502. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  503. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  504. for _, withdrawInfo := range supplierWithdrawList {
  505. IncomeId, IncomeIdErr := strconv.Atoi(withdrawInfo.IncomeIds)
  506. if IncomeIdErr != nil {
  507. return nil, IncomeIdErr
  508. }
  509. incomeInfo, incomeErr := db.GetIncomeInfoByIncomeId(ctx, IncomeId)
  510. if incomeErr != nil {
  511. return nil, incomeErr
  512. }
  513. if incomeInfo != nil {
  514. var sTaskInfo *http_model.STaskInfo
  515. sTaskInfo = &http_model.STaskInfo{}
  516. if incomeInfo.IncomeType == 1 {
  517. sTaskInfo.Id = incomeInfo.SProjectID
  518. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  519. } else if incomeInfo.IncomeType == 3 {
  520. sTaskInfo.Id = incomeInfo.SLocalID
  521. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  522. }
  523. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  524. }
  525. supplierWithdrawInfo.SupplierType = 1
  526. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  527. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  528. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  529. supplierWithdrawInfo.Name = withdrawInfo.Name
  530. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  531. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  532. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  533. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  534. // supplierWithdrawInfo.Company = withdrawInfo.Company
  535. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  536. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  537. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  538. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  539. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  540. }
  541. } else if supplierInfo.SupplierId == 2 {
  542. // 3. 企业服务商
  543. for _, withdrawInfo := range supplierWithdrawList {
  544. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  545. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  546. InvoiceId, InvoiceIdErr := strconv.Atoi(withdrawInfo.InvoiceIds)
  547. if InvoiceIdErr != nil {
  548. return nil, InvoiceIdErr
  549. }
  550. incomeIds, incomeIdsErr := db.GetIncomeIdsByInvoiceId(ctx, InvoiceId)
  551. if incomeIdsErr != nil {
  552. return nil, incomeIdsErr
  553. }
  554. if incomeIds != "" {
  555. strSlice := strings.Split(incomeIds, ",")
  556. intSlice := make([]int, len(strSlice))
  557. for i, s := range strSlice {
  558. num, err := strconv.Atoi(s)
  559. if err != nil {
  560. fmt.Println("转换错误:", err)
  561. return nil, err
  562. }
  563. intSlice[i] = num
  564. }
  565. for _, incomeId := range intSlice {
  566. var sTaskInfo *http_model.STaskInfo
  567. sTaskInfo = &http_model.STaskInfo{}
  568. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  569. if incomeInfoErr != nil {
  570. return nil, incomeInfoErr
  571. }
  572. if currIncome != nil {
  573. if currIncome.IncomeType == 1 {
  574. sTaskInfo.Id = currIncome.SProjectID
  575. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  576. } else if currIncome.IncomeType == 3 {
  577. sTaskInfo.Id = currIncome.SLocalID
  578. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  579. }
  580. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  581. }
  582. }
  583. }
  584. supplierWithdrawInfo.SupplierType = 1
  585. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  586. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  587. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  588. supplierWithdrawInfo.Name = withdrawInfo.Name
  589. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  590. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  591. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  592. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  593. supplierWithdrawInfo.Company = withdrawInfo.Company
  594. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  595. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  596. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  597. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  598. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  599. }
  600. }
  601. }
  602. }
  603. return supplierWithdrawListData, nil
  604. }