supplier.go 40 KB

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