supplier.go 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  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. // UpdateSupplierAccountInfo 更新服务商账号信息
  100. func (l *loginAuth) UpdateSupplierAccountInfo(ctx context.Context, req *http_model.UpdateAccountInfoRequest) (*http_model.UpdateAccountInfoData, int, error) {
  101. var supplierUserInfo *http_model.UpdateAccountInfoData
  102. supplierUserInfo = &http_model.UpdateAccountInfoData{}
  103. supplierUserInfo.SupplierName = req.SupplierName
  104. supplierUserInfo.Avatar = req.Avatar
  105. supplierUserInfo.Phone = req.Phone
  106. supplierUserInfo.SubAccountName = req.SubAccountName
  107. if req.SubAccountId == 0 {
  108. // 服务商主账号
  109. // 1. 若修改绑定手机号
  110. if req.Phone != "" {
  111. // 1.1. 校验验证码
  112. vCode, err := l.getSessionCode(ctx, req.Phone)
  113. if err != nil {
  114. return nil, 0, err
  115. }
  116. if vCode != req.Code {
  117. return nil, 1, nil
  118. }
  119. // 1.2. 手机号是否已经被其他主账号绑定
  120. supplierNum, supplierNumErr := db.CountSupplierUserByPhone(ctx, req.Phone)
  121. if supplierNumErr != nil {
  122. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierNumErr)
  123. return nil, 0, supplierNumErr
  124. }
  125. if supplierNum != 0 {
  126. return nil, 2, nil
  127. }
  128. // 1.3. 手机号是否被子账号绑定
  129. subAccountNum, SubAccountErr := db.CountSubAccountUserByPhone(ctx, req.Phone)
  130. if SubAccountErr != nil {
  131. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", SubAccountErr)
  132. return nil, 0, SubAccountErr
  133. }
  134. if subAccountNum != 0 {
  135. return nil, 3, nil
  136. }
  137. // 1.4. 修改Supplier信息
  138. var supplierInfo *gorm_model.YoungeeSupplier
  139. supplierInfo = &gorm_model.YoungeeSupplier{}
  140. supplierInfo.SupplierId = req.SupplierId
  141. supplierInfo.SupplierName = req.SupplierName
  142. supplierInfo.Avatar = req.Avatar
  143. supplierInfo.PhoneNumber = req.Phone
  144. updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
  145. if updateSupplierErr != nil {
  146. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSupplierErr)
  147. return nil, 0, updateSupplierErr
  148. }
  149. // 1.5. 修改User表信息
  150. supplierInfoQuery, supplierInfoQueryErr := db.GetSupplierById(ctx, supplierInfo.SupplierId)
  151. if supplierInfoQueryErr != nil {
  152. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierInfoQueryErr)
  153. return nil, 0, supplierInfoQueryErr
  154. }
  155. if supplierInfoQuery != nil {
  156. var userInfo *gorm_model.YounggeeUser
  157. userInfo = &gorm_model.YounggeeUser{}
  158. userInfo.ID = supplierInfoQuery.UserId
  159. userInfo.Phone = supplierInfoQuery.PhoneNumber
  160. userInfo.Username = supplierInfoQuery.PhoneNumber
  161. updateUserInfoErr := db.UpdateUserById(ctx, userInfo)
  162. if updateUserInfoErr != nil {
  163. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateUserInfoErr)
  164. return nil, 0, updateUserInfoErr
  165. }
  166. }
  167. } else {
  168. var supplierInfo *gorm_model.YoungeeSupplier
  169. supplierInfo = &gorm_model.YoungeeSupplier{}
  170. supplierInfo.SupplierId = req.SupplierId
  171. supplierInfo.SupplierName = req.SupplierName
  172. supplierInfo.Avatar = req.Avatar
  173. supplierInfo.PhoneNumber = req.Phone
  174. updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
  175. if updateSupplierErr != nil {
  176. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSupplierErr)
  177. return nil, 0, updateSupplierErr
  178. }
  179. }
  180. } else {
  181. // 服务商子账号
  182. var subAccountInfo *gorm_model.YounggeeSubAccount
  183. subAccountInfo = &gorm_model.YounggeeSubAccount{}
  184. subAccountInfo.SubAccountId = req.SubAccountId
  185. subAccountInfo.SubAccountType = 3
  186. subAccountInfo.SupplierId = req.SupplierId
  187. subAccountInfo.SubAccountName = req.SubAccountName
  188. subAccountInfo.Avatar = req.Avatar
  189. subAccountInfo.PhoneNumber = req.Phone
  190. updateSubAccountErr := db.UpdateSubAccount(ctx, subAccountInfo)
  191. if updateSubAccountErr != nil {
  192. log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSubAccountErr)
  193. return nil, 0, updateSubAccountErr
  194. }
  195. }
  196. return supplierUserInfo, 0, nil
  197. }
  198. // GetSupplierReviewInfo 查询服务商认证信息
  199. func (*supplier) GetSupplierReviewInfo(ctx context.Context, req *http_model.GetReviewInfoRequest) (*http_model.GetReviewInfoData, error) {
  200. var supplierUserInfo *http_model.GetReviewInfoData
  201. supplierUserInfo = &http_model.GetReviewInfoData{}
  202. // 1. 服务商信息
  203. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
  204. if supplierInfoErr != nil {
  205. log.Infof("[GetSupplierReviewInfo] fail,err:%+v", supplierInfoErr)
  206. return nil, supplierInfoErr
  207. }
  208. if supplierInfo != nil {
  209. if supplierInfo.ReviewStatus == 1 {
  210. supplierUserInfo.ReviewStatus = 1
  211. } else if supplierInfo.SupplierType == 1 {
  212. supplierUserInfo.ReviewStatus = 2
  213. supplierUserInfo.SupplierType = 1
  214. supplierUserInfo.IdBack = supplierInfo.IdBack
  215. supplierUserInfo.IdFront = supplierInfo.IdFront
  216. supplierUserInfo.IdNumber = supplierInfo.IdNumber
  217. supplierUserInfo.Name = supplierInfo.Name
  218. } else if supplierInfo.SupplierType == 2 {
  219. supplierUserInfo.ReviewStatus = 2
  220. supplierUserInfo.SupplierType = 2
  221. supplierUserInfo.CompanyName = supplierInfo.CompanyName
  222. supplierUserInfo.USCI = supplierInfo.Usci
  223. supplierUserInfo.BusinessLicense = supplierInfo.BusinessLicense
  224. }
  225. }
  226. return supplierUserInfo, nil
  227. }
  228. // GetSupplierContactInfo 查询服务商联系方式
  229. func (*supplier) GetSupplierContactInfo(ctx context.Context, req *http_model.GetContactInfoRequest) (*http_model.GetContactInfoData, error) {
  230. var contactInfo *http_model.GetContactInfoData
  231. contactInfo = &http_model.GetContactInfoData{}
  232. // 1. 服务商主账号
  233. if req.SubAccountId == 0 {
  234. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, req.SupplierId)
  235. if supplierInfoErr != nil {
  236. log.Infof("[GetSupplierContactInfo] fail,err:%+v", supplierInfoErr)
  237. return nil, supplierInfoErr
  238. }
  239. if supplierInfo != nil {
  240. contactInfo.ContactPhone = supplierInfo.ContactPhone
  241. contactInfo.WechatQRCode = supplierInfo.WechatQrCode
  242. contactInfo.WechatNumber = supplierInfo.WechatNumber
  243. }
  244. } else {
  245. // 2. 服务商子账号
  246. subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, req.SubAccountId)
  247. if subAccountInfoErr != nil {
  248. log.Infof("[GetSupplierContactInfo] fail,err:%+v", subAccountInfoErr)
  249. return nil, subAccountInfoErr
  250. }
  251. if subAccountInfo != nil {
  252. contactInfo.ContactPhone = subAccountInfo.ContactPhone
  253. contactInfo.WechatQRCode = subAccountInfo.WechatQRCode
  254. contactInfo.WechatNumber = subAccountInfo.WechatNumber
  255. }
  256. }
  257. return contactInfo, nil
  258. }
  259. // UpdateSupplierContactInfo 更新服务商联系方式
  260. func (l *loginAuth) UpdateSupplierContactInfo(ctx context.Context, req *http_model.UpdateContactInfoRequest) (*http_model.UpdateContactInfoData, bool, error) {
  261. var contactInfo *http_model.UpdateContactInfoData
  262. contactInfo = &http_model.UpdateContactInfoData{}
  263. // 主账号
  264. if req.SubAccountId == 0 {
  265. // 1. 若更新联系电话则需要验证码校验
  266. if req.ContactPhone != "" {
  267. vcode, err := l.getSessionCode(ctx, req.ContactPhone)
  268. if err != nil {
  269. return nil, false, err
  270. }
  271. // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
  272. if vcode != req.Code {
  273. // 验证码错误
  274. return nil, true, err
  275. }
  276. var supplierInfo *gorm_model.YoungeeSupplier
  277. supplierInfo = &gorm_model.YoungeeSupplier{}
  278. supplierInfo.ContactPhone = req.ContactPhone
  279. supplierInfo.SupplierId = req.SupplierId
  280. updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
  281. if updateSupplierErr != nil {
  282. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  283. return nil, false, updateSupplierErr
  284. }
  285. contactInfo.ContactPhone = req.ContactPhone
  286. }
  287. // 2. 微信二维码更新
  288. if req.WechatQRCode != "" {
  289. var supplierInfo *gorm_model.YoungeeSupplier
  290. supplierInfo = &gorm_model.YoungeeSupplier{}
  291. supplierInfo.WechatQrCode = req.WechatQRCode
  292. supplierInfo.SupplierId = req.SupplierId
  293. updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
  294. if updateSupplierErr != nil {
  295. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  296. return nil, false, updateSupplierErr
  297. }
  298. contactInfo.WechatQRCode = req.WechatQRCode
  299. }
  300. // 2. 微信号码更新
  301. if req.WechatNumber != "" {
  302. var supplierInfo *gorm_model.YoungeeSupplier
  303. supplierInfo = &gorm_model.YoungeeSupplier{}
  304. supplierInfo.WechatNumber = req.WechatNumber
  305. supplierInfo.SupplierId = req.SupplierId
  306. updateSupplierErr := db.UpdateSupplier(ctx, supplierInfo)
  307. if updateSupplierErr != nil {
  308. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  309. return nil, false, updateSupplierErr
  310. }
  311. contactInfo.WechatNumber = req.WechatNumber
  312. }
  313. } else {
  314. // 子账号
  315. // 1. 若更新联系电话则需要验证码校验
  316. if req.ContactPhone != "" {
  317. vcode, err := l.getSessionCode(ctx, req.ContactPhone)
  318. if err != nil {
  319. return nil, false, err
  320. }
  321. // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
  322. if vcode != req.Code {
  323. // 验证码错误
  324. return nil, true, err
  325. }
  326. var supplierInfo *gorm_model.YounggeeSubAccount
  327. supplierInfo = &gorm_model.YounggeeSubAccount{}
  328. supplierInfo.ContactPhone = req.ContactPhone
  329. supplierInfo.SubAccountId = req.SubAccountId
  330. updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
  331. if updateSupplierErr != nil {
  332. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  333. return nil, false, updateSupplierErr
  334. }
  335. contactInfo.ContactPhone = req.ContactPhone
  336. }
  337. // 2. 微信二维码更新
  338. if req.WechatQRCode != "" {
  339. var supplierInfo *gorm_model.YounggeeSubAccount
  340. supplierInfo = &gorm_model.YounggeeSubAccount{}
  341. supplierInfo.WechatQRCode = req.WechatQRCode
  342. supplierInfo.SubAccountId = req.SubAccountId
  343. updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
  344. if updateSupplierErr != nil {
  345. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  346. return nil, false, updateSupplierErr
  347. }
  348. contactInfo.WechatQRCode = req.WechatQRCode
  349. }
  350. // 2. 微信号码更新
  351. if req.WechatNumber != "" {
  352. var supplierInfo *gorm_model.YounggeeSubAccount
  353. supplierInfo = &gorm_model.YounggeeSubAccount{}
  354. supplierInfo.WechatNumber = req.WechatNumber
  355. supplierInfo.SubAccountId = req.SubAccountId
  356. updateSupplierErr := db.UpdateSubAccount(ctx, supplierInfo)
  357. if updateSupplierErr != nil {
  358. log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
  359. return nil, false, updateSupplierErr
  360. }
  361. contactInfo.WechatNumber = req.WechatNumber
  362. }
  363. }
  364. return contactInfo, true, nil
  365. }
  366. // SaveSupplierReviewInfo 保存服务商认证信息
  367. func (*supplier) SaveSupplierReviewInfo(ctx context.Context, req *http_model.SaveReviewRequest) error {
  368. var supplierInfo *gorm_model.YoungeeSupplier
  369. supplierInfo = &gorm_model.YoungeeSupplier{}
  370. // 1. 个人服务商
  371. if req.SupplierType == 1 {
  372. supplierInfo.SupplierId = req.SupplierId
  373. supplierInfo.IdFront = req.IdCardUrl
  374. supplierInfo.IdNumber = req.IdNumber
  375. supplierInfo.Name = req.Name
  376. supplierInfo.IdBack = req.IdBack
  377. supplierInfo.SupplierType = req.SupplierType
  378. supplierInfo.ReviewStatus = 2
  379. updateErr := db.UpdateSupplier(ctx, supplierInfo)
  380. if updateErr != nil {
  381. log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
  382. return updateErr
  383. }
  384. } else if req.SupplierType == 2 {
  385. // 2. 企业服务商
  386. supplierInfo.SupplierId = req.SupplierId
  387. supplierInfo.ReviewStatus = 2
  388. supplierInfo.SupplierType = req.SupplierType
  389. supplierInfo.CompanyName = req.CompanyName
  390. supplierInfo.Usci = req.USCI
  391. supplierInfo.BusinessLicense = req.BusinessLicenseUrl
  392. updateErr := db.UpdateSupplier(ctx, supplierInfo)
  393. if updateErr != nil {
  394. log.Infof("[UpdateSupplierReviewInfo] fail,err:%+v", updateErr)
  395. return updateErr
  396. }
  397. }
  398. return nil
  399. }
  400. // GetSupplierIncomeList 查询服务商收入列表
  401. func (*supplier) GetSupplierIncomeList(ctx context.Context, req *http_model.FullSProjectIncomeListRequest) (*http_model.FullSProjectIncomeData, error) {
  402. var sProjectIncomeData *http_model.FullSProjectIncomeData
  403. sProjectIncomeData = &http_model.FullSProjectIncomeData{}
  404. // 1. 查询
  405. supplierIncome, total, err := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.IncomeStatus)
  406. if err != nil {
  407. return nil, nil
  408. }
  409. // 2. 补充种草/本地生活任务信息
  410. if supplierIncome != nil {
  411. sProjectIncomeData.Total = total
  412. for _, income := range supplierIncome {
  413. // 2.1. 种草任务基本信息
  414. if income.IncomeType == 1 {
  415. var sProjectInfo *http_model.FullSProjectIncomeListResponse
  416. sProjectInfo = &http_model.FullSProjectIncomeListResponse{}
  417. sProjectData, sProjectErr := db.GetSProjectDetail(ctx, income.SProjectID)
  418. if sProjectErr != nil {
  419. log.Infof("[GetSProjectDetail] fail,err:%+v", sProjectErr)
  420. return nil, sProjectErr
  421. }
  422. if sProjectData != nil {
  423. sProjectInfo.SProjectId = sProjectData.SProjectId
  424. sProjectInfo.IncomeId = income.IncomeID
  425. sProjectInfo.IncomeType = income.IncomeType
  426. sProjectInfo.SProjectId = sProjectData.SProjectId
  427. sProjectInfo.ProjectName = sProjectData.ProjectName
  428. sProjectInfo.ProjectPlatform = sProjectData.ProjectPlatform
  429. sProjectInfo.ServiceCharge = sProjectData.ServiceCharge
  430. sProjectInfo.ServiceChargeSettle = sProjectData.ServiceChargeSettle
  431. sProjectInfo.RecruitNum = sProjectData.RecruitNum
  432. sProjectInfo.SettleNum = sProjectData.SettleNum
  433. sProjectInfo.FinishTime = conv.MustString(sProjectData.FinishTime)
  434. // 2.2. 商品基本信息
  435. productInfo, productErr := db.GetProductByID(ctx, sProjectData.ProductId)
  436. if productErr != nil {
  437. log.Infof("[GetProductByID] fail,err:%+v", productErr)
  438. return nil, productErr
  439. }
  440. if productInfo != nil {
  441. sProjectInfo.ProductName = productInfo.ProductName
  442. sProjectInfo.ProductPrice = productInfo.ProductPrice
  443. }
  444. // 2.3. 商品图片信息
  445. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProjectData.ProductId)
  446. if productPhotoErr != nil {
  447. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", productPhotoErr)
  448. return nil, productPhotoErr
  449. }
  450. if productPhotoInfo != nil {
  451. for _, photo := range productPhotoInfo {
  452. fmt.Println(photo)
  453. if photo.Symbol == 1 {
  454. sProjectInfo.ProductPhotoSymbol = 1
  455. sProjectInfo.ProductPhotoUrl = photo.PhotoUrl
  456. sProjectInfo.ProductPhotoUid = photo.PhotoUid
  457. }
  458. }
  459. }
  460. // 2.4. 加入商单操作人信息
  461. if sProjectData.SubAccountId == 0 {
  462. sProjectInfo.SOperatorType = 1
  463. sProjectInfo.SOperatorId = sProjectData.SupplierId
  464. supplierInfo, supplierInfoErr := db.GetSupplierById(ctx, sProjectData.SupplierId)
  465. if supplierInfoErr != nil {
  466. log.Infof("[GetSupplierById] fail,err:%+v", supplierInfoErr)
  467. return nil, supplierInfoErr
  468. }
  469. if supplierInfo != nil {
  470. sProjectInfo.SOperatorName = supplierInfo.Name
  471. }
  472. sProjectInfo.SOperatorName = conv.MustString(sProjectData.SupplierId)
  473. } else {
  474. sProjectInfo.SOperatorType = 2
  475. sProjectInfo.SOperatorId = sProjectData.SubAccountId
  476. subAccountInfo, subAccountInfoErr := db.FindSubAccountById(ctx, sProjectData.SubAccountId)
  477. if subAccountInfoErr != nil {
  478. log.Infof("[FindSubAccountById] fail,err:%+v", subAccountInfoErr)
  479. return nil, subAccountInfoErr
  480. }
  481. if subAccountInfo != nil {
  482. sProjectInfo.SOperatorName = subAccountInfo.SubAccountName
  483. }
  484. }
  485. sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sProjectInfo)
  486. }
  487. }
  488. // 2.1. 本地生活任务基本信息
  489. if income.IncomeType == 2 {
  490. var sLocalInfo *http_model.FullSProjectIncomeListResponse
  491. sLocalInfo = &http_model.FullSProjectIncomeListResponse{}
  492. sLocalData, sLocalErr := db.GetSLocalLifeDetail(ctx, income.SLocalID)
  493. if sLocalErr != nil {
  494. log.Infof("[GetSLocalLifeDetail] fail,err:%+v", sLocalErr)
  495. return nil, sLocalErr
  496. }
  497. if sLocalData != nil {
  498. sLocalInfo.IncomeId = income.IncomeID
  499. sLocalInfo.IncomeType = income.IncomeType
  500. sLocalInfo.SLocalId = sLocalData.SLocalId
  501. sLocalInfo.LocalName = sLocalData.LocalName
  502. sLocalInfo.LocalPlatform = sLocalData.LocalPlatform
  503. sLocalInfo.ServiceCharge = sLocalData.ServiceCharge
  504. sLocalInfo.ServiceChargeSettle = sLocalData.ServiceChargeSettle
  505. sLocalInfo.RecruitNum = sLocalData.RecruitNum
  506. sLocalInfo.SettleNum = sLocalData.SettleNum
  507. sLocalInfo.FinishTime = conv.MustString(sLocalData.FinishTime)
  508. // 2.2. 门店基本信息
  509. storeInfo, storeErr := db.FindStoreById(ctx, sLocalData.StoreId)
  510. if storeErr != nil {
  511. log.Infof("[GetProductByID] fail,err:%+v", storeErr)
  512. return nil, storeErr
  513. }
  514. if storeInfo != nil {
  515. sLocalInfo.StoreName = storeInfo.StoreName
  516. }
  517. // 2.3. 门店图片信息
  518. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, sLocalData.StoreId)
  519. if storePhotoErr != nil {
  520. log.Infof("[GetProductPhotoByProductID] fail,err:%+v", storePhotoErr)
  521. return nil, storePhotoErr
  522. }
  523. if storePhotoInfo != nil {
  524. for _, photo := range storePhotoInfo {
  525. fmt.Println(photo)
  526. if photo.Symbol == 1 {
  527. sLocalInfo.StoreMainPhotoSymbol = 1
  528. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  529. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  530. }
  531. }
  532. }
  533. sProjectIncomeData.SupplierIncome = append(sProjectIncomeData.SupplierIncome, sLocalInfo)
  534. }
  535. }
  536. }
  537. } else {
  538. sProjectIncomeData.Total = 0
  539. }
  540. return sProjectIncomeData, nil
  541. }
  542. // CreateSupplierInvoice 创建服务商发票
  543. func (*supplier) CreateSupplierInvoice(ctx context.Context, req *http_model.CreateSupplierInvoiceRequest) error {
  544. // 1. 数据转换
  545. var invoiceData *gorm_model.YounggeeSupplierInvoice
  546. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  547. SupplierId: req.SupplierId,
  548. InvoiceStatus: 1,
  549. IncomeIds: req.IncomeIds,
  550. }
  551. if req.SOperatorType == 1 {
  552. invoiceData.SOperatorType = 1
  553. invoiceData.SOperator = req.SupplierId
  554. } else if req.SOperatorType == 2 {
  555. invoiceData.SOperatorType = 2
  556. invoiceData.SOperator = req.SubAccountId
  557. }
  558. // 2. 插入数据库
  559. err := db.CreateSupplierInvoice(ctx, invoiceData)
  560. if err != nil {
  561. return err
  562. }
  563. return nil
  564. }
  565. // UpdateSupplierInvoice 更新服务商发票
  566. func (*supplier) UpdateSupplierInvoice(ctx context.Context, req *http_model.UpdateSupplierInvoiceRequest) error {
  567. // 1. 数据转换
  568. var invoiceData *gorm_model.YounggeeSupplierInvoice
  569. var currentTime time.Time
  570. currentTime = time.Now()
  571. invoiceData = &gorm_model.YounggeeSupplierInvoice{
  572. InvoiceId: req.InvoiceId,
  573. InvoiceUrl: req.InvoiceUrl,
  574. Company: req.Company,
  575. UploadInvoiceTime: &currentTime,
  576. }
  577. // 2. 更新
  578. err := db.UpdateSupplierInvoice(ctx, invoiceData)
  579. if err != nil {
  580. return err
  581. }
  582. // 3. 更新服务商收入状态
  583. incomeIds, dbErr := db.GetIncomeIdsByInvoiceId(ctx, req.InvoiceId)
  584. if dbErr != nil {
  585. return dbErr
  586. }
  587. if incomeIds == "" {
  588. return nil
  589. }
  590. strSlice := strings.Split(incomeIds, ",")
  591. intSlice := make([]int, len(strSlice))
  592. for i, s := range strSlice {
  593. num, err := strconv.Atoi(s)
  594. if err != nil {
  595. fmt.Println("转换错误:", err)
  596. return err
  597. }
  598. intSlice[i] = num
  599. }
  600. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, 3)
  601. if updateSupplierIncomeErr != nil {
  602. return updateSupplierIncomeErr
  603. }
  604. return nil
  605. }
  606. // UpdateSupplierIncomeStatus 修改服务商收入状态
  607. func (*supplier) UpdateSupplierIncomeStatus(ctx context.Context, incomeIds string, incomeStatus int) error {
  608. // 1. 转换incomeIds为数组
  609. strSlice := strings.Split(incomeIds, ",")
  610. intSlice := make([]int, len(strSlice))
  611. for i, s := range strSlice {
  612. num, err := strconv.Atoi(s)
  613. if err != nil {
  614. fmt.Println("转换错误:", err)
  615. return err
  616. }
  617. intSlice[i] = num
  618. }
  619. // 2. 修改数据库中数据
  620. updateSupplierIncomeErr := db.UpdateSupplierIncomeStatus(ctx, intSlice, incomeStatus)
  621. if updateSupplierIncomeErr != nil {
  622. return updateSupplierIncomeErr
  623. }
  624. return nil
  625. }
  626. // GetSupplierInvoiceList 查找服务商发票列表
  627. func (*supplier) GetSupplierInvoiceList(ctx context.Context, req *http_model.SupplierInvoiceListRequest) (*http_model.SupplierInvoiceListData, error) {
  628. // 1. 查询服务商发票信息
  629. supplierInvoiceList, total, err := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, req.InvoiceStatus, 4, req.PageSize, req.PageNum)
  630. if err != nil {
  631. return nil, err
  632. }
  633. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  634. var supplierInvoiceData *http_model.SupplierInvoiceListData
  635. supplierInvoiceData = &http_model.SupplierInvoiceListData{}
  636. for _, supplierInvoice := range supplierInvoiceList {
  637. var supplierInvoiceInfo *http_model.SupplierInvoiceInfo
  638. supplierInvoiceInfo = &http_model.SupplierInvoiceInfo{}
  639. // 2.1. 基础信息填入
  640. supplierInvoiceInfo.UploadInvoiceTime = supplierInvoice.UploadInvoiceTime
  641. supplierInvoiceInfo.InvoiceUrl = supplierInvoice.InvoiceUrl
  642. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  643. supplierInvoiceInfo.RejectTime = supplierInvoice.RejectTime
  644. supplierInvoiceInfo.Company = supplierInvoice.Company
  645. supplierInvoiceInfo.SOperator = supplierInvoice.SOperator
  646. supplierInvoiceInfo.FailReason = supplierInvoice.FailReason
  647. // 2.2. 任务及其收入信息填入
  648. incomeIds := supplierInvoice.IncomeIds
  649. strSlice := strings.Split(incomeIds, ",")
  650. intSlice := make([]int, len(strSlice))
  651. for i, s := range strSlice {
  652. num, err := strconv.Atoi(s)
  653. if err != nil {
  654. fmt.Println("转换错误:", err)
  655. return nil, err
  656. }
  657. intSlice[i] = num
  658. }
  659. for _, incomeId := range intSlice {
  660. var sTaskInfo *http_model.STaskInfo
  661. sTaskInfo = &http_model.STaskInfo{}
  662. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  663. if incomeErr != nil {
  664. return nil, incomeErr
  665. }
  666. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  667. supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
  668. if currIncome.IncomeType == 1 {
  669. sTaskInfo.Id = currIncome.SProjectID
  670. } else if currIncome.IncomeType == 3 {
  671. sTaskInfo.Id = currIncome.SLocalID
  672. }
  673. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  674. }
  675. supplierInvoiceData.SupplierInvoiceList = append(supplierInvoiceData.SupplierInvoiceList, supplierInvoiceInfo)
  676. }
  677. supplierInvoiceData.Total = total
  678. return supplierInvoiceData, nil
  679. }
  680. // GetSupplierToWithdrawList 服务商待提现列表
  681. func (*supplier) GetSupplierToWithdrawList(ctx context.Context, req *http_model.SupplierToWithdrawListRequest) (*http_model.SupplierToWithdrawListData, error) {
  682. // 1. 判断服务商类型
  683. var supplierInvoiceData *http_model.SupplierToWithdrawListData
  684. supplierInvoiceData = &http_model.SupplierToWithdrawListData{}
  685. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  686. if supplierErr != nil {
  687. return nil, supplierErr
  688. }
  689. if supplierInfo != nil {
  690. // 企业服务商
  691. if supplierInfo.SupplierType == 2 {
  692. // 查询企业服务商发票信息
  693. supplierInvoiceList, total, supplierInvoiceErr := db.GetInvoiceListBySupplierId(ctx, req.SupplierId, 3, 1, req.PageSize, req.PageNum)
  694. if supplierInvoiceErr != nil {
  695. return nil, supplierInvoiceErr
  696. }
  697. if supplierInvoiceList != nil {
  698. for _, supplierInvoice := range supplierInvoiceList {
  699. // 2. 根据发票中的incomeIds去查找任务及其服务费收入
  700. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  701. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  702. // supplierInvoiceInfo.Amount = 0.0
  703. // 2.1. 基础信息填入
  704. supplierInvoiceInfo.AgreeTime = supplierInvoice.AgreeTime
  705. supplierInvoiceInfo.Company = supplierInvoice.Company
  706. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  707. // 2.2. 任务及其收入信息填入
  708. incomeIds := supplierInvoice.IncomeIds
  709. strSlice := strings.Split(incomeIds, ",")
  710. intSlice := make([]int, len(strSlice))
  711. for i, s := range strSlice {
  712. num, err := strconv.Atoi(s)
  713. if err != nil {
  714. fmt.Println("转换错误:", err)
  715. return nil, err
  716. }
  717. intSlice[i] = num
  718. }
  719. for _, incomeId := range intSlice {
  720. var sTaskInfo *http_model.STaskInfo
  721. sTaskInfo = &http_model.STaskInfo{}
  722. currIncome, incomeErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  723. if incomeErr != nil {
  724. return nil, incomeErr
  725. }
  726. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  727. supplierInvoiceInfo.Amount += currIncome.ServiceChargeSettle
  728. if currIncome.IncomeType == 1 {
  729. sTaskInfo.Id = currIncome.SProjectID
  730. } else if currIncome.IncomeType == 3 {
  731. sTaskInfo.Id = currIncome.SLocalID
  732. }
  733. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  734. }
  735. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  736. }
  737. supplierInvoiceData.Total = total
  738. }
  739. } else if supplierInfo.SupplierType == 1 {
  740. // 个人服务商
  741. // 查询个人服务商收入信息
  742. supplierIncomeList, supplierIncomeTotal, supplierIncomeErr := db.GetSupplierIncomeList(ctx, req.PageSize, req.PageNum, req.SupplierId, 5)
  743. if supplierIncomeErr != nil {
  744. return nil, supplierIncomeErr
  745. }
  746. if supplierIncomeList != nil {
  747. supplierInvoiceData.Total = supplierIncomeTotal
  748. for _, supplierIncome := range supplierIncomeList {
  749. var supplierInvoiceInfo *http_model.SupplierToWithdrawInfo
  750. supplierInvoiceInfo = &http_model.SupplierToWithdrawInfo{}
  751. supplierInvoiceInfo.SupplierType = supplierInfo.SupplierType
  752. supplierInvoiceInfo.IncomeId = supplierIncome.IncomeID
  753. supplierInvoiceInfo.Amount = supplierIncome.ServiceChargeSettle
  754. supplierInvoiceInfo.AmountActual = supplierIncome.ServiceChargeSettle * 0.05
  755. var sTaskInfo *http_model.STaskInfo
  756. sTaskInfo = &http_model.STaskInfo{}
  757. sTaskInfo.ServiceCharge = supplierIncome.ServiceChargeSettle
  758. if supplierIncome.IncomeType == 1 {
  759. sTaskInfo.Id = supplierIncome.SProjectID
  760. } else if supplierIncome.IncomeType == 3 {
  761. sTaskInfo.Id = supplierIncome.SLocalID
  762. }
  763. supplierInvoiceInfo.STaskInfo = append(supplierInvoiceInfo.STaskInfo, sTaskInfo)
  764. supplierInvoiceData.ToWithdrawList = append(supplierInvoiceData.ToWithdrawList, supplierInvoiceInfo)
  765. }
  766. }
  767. }
  768. }
  769. return supplierInvoiceData, nil
  770. }
  771. // CreateSupplierWithdraw 创建服务商提现信息
  772. func (*supplier) CreateSupplierWithdraw(ctx context.Context, req *http_model.CreateSupplierWithdrawRequest) error {
  773. var supplierWithdrawInfoList []*gorm_model.YounggeeSupplierWithdraw
  774. // 1. 判断服务商类型
  775. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  776. if supplierErr != nil {
  777. return supplierErr
  778. }
  779. if supplierInfo != nil {
  780. if supplierInfo.SupplierType == 1 {
  781. // 1.1. 个人服务商
  782. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
  783. if supplierPaymentErr != nil {
  784. return supplierPaymentErr
  785. }
  786. if supplierPaymentInfo != nil {
  787. for _, withdrawInfo := range req.IncomeIds {
  788. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  789. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  790. // 1.2.1. 接口传入信息填入
  791. supplierWithdrawInfo.SupplierId = req.SupplierId
  792. supplierWithdrawInfo.WithdrawStatus = 2
  793. supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
  794. supplierWithdrawInfo.BankNumber = supplierPaymentInfo.BankNumber
  795. var currentTime time.Time
  796. currentTime = time.Now()
  797. supplierWithdrawInfo.SupplyTime = &currentTime
  798. supplierWithdrawInfo.WithdrawAmount = 0.0
  799. // 1.2.2. 查找服务商信息填入
  800. supplierWithdrawInfo.Name = supplierInfo.Name
  801. supplierWithdrawInfo.Phone = supplierPaymentInfo.Phone
  802. // 1.2.3. 收入信息填入
  803. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, withdrawInfo)
  804. if incomeInfoErr != nil {
  805. return incomeInfoErr
  806. }
  807. if currIncome != nil {
  808. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  809. }
  810. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  811. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  812. }
  813. }
  814. } else if supplierInfo.SupplierType == 2 {
  815. // 1.2. 机构服务商
  816. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, supplierInfo.SupplierId)
  817. if supplierPaymentErr != nil {
  818. return supplierPaymentErr
  819. }
  820. if supplierPaymentInfo != nil {
  821. for _, withdrawInfo := range req.InvoiceIds {
  822. var supplierWithdrawInfo *gorm_model.YounggeeSupplierWithdraw
  823. supplierWithdrawInfo = &gorm_model.YounggeeSupplierWithdraw{}
  824. // 1.2.1. 接口传入信息填入
  825. supplierWithdrawInfo.SupplierId = req.SupplierId
  826. supplierWithdrawInfo.WithdrawStatus = 2
  827. supplierWithdrawInfo.BankName = supplierPaymentInfo.BankName
  828. supplierWithdrawInfo.BankNumber = supplierPaymentInfo.BankNumber
  829. var currentTime time.Time
  830. currentTime = time.Now()
  831. supplierWithdrawInfo.SupplyTime = &currentTime
  832. supplierWithdrawInfo.WithdrawAmount = 0.0
  833. // 1.2.2. 查找服务商信息填入
  834. supplierWithdrawInfo.Name = supplierInfo.Name
  835. supplierWithdrawInfo.Phone = supplierInfo.PhoneNumber
  836. supplierWithdrawInfo.Company = supplierInfo.CompanyName
  837. // 1.2.3. 收入信息填入
  838. incomeIds, incomeErr := db.GetIncomeIdsByInvoiceId(ctx, withdrawInfo)
  839. if incomeErr != nil {
  840. return incomeErr
  841. }
  842. if incomeIds != "" {
  843. strSlice := strings.Split(incomeIds, ",")
  844. intSlice := make([]int, len(strSlice))
  845. for i, s := range strSlice {
  846. num, err := strconv.Atoi(s)
  847. if err != nil {
  848. fmt.Println("转换错误:", err)
  849. return err
  850. }
  851. intSlice[i] = num
  852. }
  853. for _, incomeId := range intSlice {
  854. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  855. if incomeInfoErr != nil {
  856. return incomeInfoErr
  857. }
  858. if currIncome != nil {
  859. supplierWithdrawInfo.WithdrawAmount += currIncome.ServiceChargeSettle
  860. }
  861. }
  862. supplierWithdrawInfo.AmountPayable = supplierWithdrawInfo.WithdrawAmount
  863. }
  864. supplierWithdrawInfoList = append(supplierWithdrawInfoList, supplierWithdrawInfo)
  865. }
  866. }
  867. }
  868. }
  869. // 2. 数据库插入
  870. err := db.CreateSupplierWithdraw(ctx, supplierWithdrawInfoList)
  871. if err != nil {
  872. return err
  873. }
  874. return nil
  875. }
  876. // GetSupplierWithdrawList 服务商提现列表
  877. func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.SupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
  878. var supplierWithdrawListData *http_model.SupplierWithdrawListData
  879. supplierWithdrawListData = &http_model.SupplierWithdrawListData{}
  880. // 1. 根据服务商ID和提现状态去查找提现信息列表
  881. supplierWithdrawList, total, supplierWithdrawErr := db.GetSupplierWithdrawList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.WithdrawStatus)
  882. if supplierWithdrawErr != nil {
  883. return nil, supplierWithdrawErr
  884. }
  885. if supplierWithdrawList != nil {
  886. supplierWithdrawListData.Total = total
  887. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  888. if supplierErr != nil {
  889. return nil, supplierErr
  890. }
  891. if supplierInfo != nil {
  892. if supplierInfo.SupplierId == 1 {
  893. // 2. 个人服务商
  894. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  895. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  896. for _, withdrawInfo := range supplierWithdrawList {
  897. IncomeId, IncomeIdErr := strconv.Atoi(withdrawInfo.IncomeIds)
  898. if IncomeIdErr != nil {
  899. return nil, IncomeIdErr
  900. }
  901. incomeInfo, incomeErr := db.GetIncomeInfoByIncomeId(ctx, IncomeId)
  902. if incomeErr != nil {
  903. return nil, incomeErr
  904. }
  905. if incomeInfo != nil {
  906. var sTaskInfo *http_model.STaskInfo
  907. sTaskInfo = &http_model.STaskInfo{}
  908. if incomeInfo.IncomeType == 1 {
  909. sTaskInfo.Id = incomeInfo.SProjectID
  910. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  911. } else if incomeInfo.IncomeType == 3 {
  912. sTaskInfo.Id = incomeInfo.SLocalID
  913. sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
  914. }
  915. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  916. }
  917. supplierWithdrawInfo.SupplierType = 1
  918. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  919. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  920. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  921. supplierWithdrawInfo.Name = withdrawInfo.Name
  922. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  923. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  924. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  925. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  926. // supplierWithdrawInfo.Company = withdrawInfo.Company
  927. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  928. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  929. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  930. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  931. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  932. }
  933. } else if supplierInfo.SupplierId == 2 {
  934. // 3. 企业服务商
  935. for _, withdrawInfo := range supplierWithdrawList {
  936. var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
  937. supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
  938. InvoiceId, InvoiceIdErr := strconv.Atoi(withdrawInfo.InvoiceIds)
  939. if InvoiceIdErr != nil {
  940. return nil, InvoiceIdErr
  941. }
  942. incomeIds, incomeIdsErr := db.GetIncomeIdsByInvoiceId(ctx, InvoiceId)
  943. if incomeIdsErr != nil {
  944. return nil, incomeIdsErr
  945. }
  946. if incomeIds != "" {
  947. strSlice := strings.Split(incomeIds, ",")
  948. intSlice := make([]int, len(strSlice))
  949. for i, s := range strSlice {
  950. num, err := strconv.Atoi(s)
  951. if err != nil {
  952. fmt.Println("转换错误:", err)
  953. return nil, err
  954. }
  955. intSlice[i] = num
  956. }
  957. for _, incomeId := range intSlice {
  958. var sTaskInfo *http_model.STaskInfo
  959. sTaskInfo = &http_model.STaskInfo{}
  960. currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
  961. if incomeInfoErr != nil {
  962. return nil, incomeInfoErr
  963. }
  964. if currIncome != nil {
  965. if currIncome.IncomeType == 1 {
  966. sTaskInfo.Id = currIncome.SProjectID
  967. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  968. } else if currIncome.IncomeType == 3 {
  969. sTaskInfo.Id = currIncome.SLocalID
  970. sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
  971. }
  972. supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
  973. }
  974. }
  975. }
  976. supplierWithdrawInfo.SupplierType = 1
  977. supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
  978. supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
  979. supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
  980. supplierWithdrawInfo.Name = withdrawInfo.Name
  981. supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
  982. supplierWithdrawInfo.BankName = withdrawInfo.BankName
  983. supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
  984. supplierWithdrawInfo.Phone = withdrawInfo.Phone
  985. supplierWithdrawInfo.Company = withdrawInfo.Company
  986. supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
  987. supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
  988. supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
  989. supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
  990. supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
  991. }
  992. }
  993. }
  994. }
  995. return supplierWithdrawListData, nil
  996. }
  997. func (*supplier) GetSupplierAmountBillList(ctx context.Context, req *http_model.SupplierAmountBillListRequest) (*http_model.SupplierAmountBillData, error) {
  998. return nil, nil
  999. }
  1000. // GetManageInvoiceInfo 查找后台回票信息
  1001. func (*supplier) GetManageInvoiceInfo(ctx context.Context, req *http_model.ManageInvoiceInfoRequest) (*http_model.ManageInvoiceInfoData, error) {
  1002. var invoiceInfo *http_model.ManageInvoiceInfoData
  1003. invoiceInfo = &http_model.ManageInvoiceInfoData{}
  1004. manageInvoiceInfo, manageInvoiceErr := db.GetManageInvoice(ctx)
  1005. if manageInvoiceErr != nil {
  1006. return nil, manageInvoiceErr
  1007. }
  1008. if manageInvoiceInfo != nil {
  1009. invoiceInfo.InvoiceInfoID = manageInvoiceInfo.InvoiceInfoID
  1010. invoiceInfo.Address = manageInvoiceInfo.Address
  1011. invoiceInfo.Phone = manageInvoiceInfo.Phone
  1012. invoiceInfo.BankNumber = manageInvoiceInfo.BankNumber
  1013. invoiceInfo.EnterpriseName = manageInvoiceInfo.EnterpriseName
  1014. invoiceInfo.ProjectNameToChoose = manageInvoiceInfo.ProjectNameToChoose
  1015. invoiceInfo.BankName = manageInvoiceInfo.BankName
  1016. }
  1017. return invoiceInfo, nil
  1018. }
  1019. // GetWithdrawAmount 查找可提现、提现中、已提现金额
  1020. func (*supplier) GetWithdrawAmount(ctx context.Context, req *http_model.WithdrawAmountRequest) (*http_model.WithdrawAmountData, error) {
  1021. var amountInfo *http_model.WithdrawAmountData
  1022. amountInfo = &http_model.WithdrawAmountData{}
  1023. amountInfo.WithdrawAble = 0.0
  1024. amountInfo.PendingWithdraw = 0.0
  1025. amountInfo.Withdrawn = 0.0
  1026. // 可提现
  1027. platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  1028. if platformConfirmingErr != nil {
  1029. return nil, platformConfirmingErr
  1030. }
  1031. if platformConfirmingIncome != nil {
  1032. for _, income := range platformConfirmingIncome {
  1033. amountInfo.WithdrawAble += income.ServiceChargeSettle
  1034. }
  1035. }
  1036. // 提现中
  1037. pendingWithdrawIncome, pendingWithdrawErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 7)
  1038. if pendingWithdrawErr != nil {
  1039. return nil, pendingWithdrawErr
  1040. }
  1041. if pendingWithdrawIncome != nil {
  1042. for _, income := range pendingWithdrawIncome {
  1043. amountInfo.PendingWithdraw += income.ServiceChargeSettle
  1044. }
  1045. }
  1046. // 已经提现
  1047. withdrawnIncome, withdrawnErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 8)
  1048. if withdrawnErr != nil {
  1049. return nil, withdrawnErr
  1050. }
  1051. if withdrawnIncome != nil {
  1052. for _, income := range withdrawnIncome {
  1053. amountInfo.Withdrawn += income.ServiceChargeSettle
  1054. }
  1055. }
  1056. return amountInfo, nil
  1057. }
  1058. // GetSupplierBillAmount 服务商账单 总余额、可提现金额
  1059. func (*supplier) GetSupplierBillAmount(ctx context.Context, req *http_model.SupplierAmountRequest) (*http_model.SupplierBillAmountData, error) {
  1060. var incomeData *http_model.SupplierBillAmountData
  1061. incomeData = &http_model.SupplierBillAmountData{}
  1062. incomeData.FullAmount = 0.0
  1063. incomeData.Settle = 0.0
  1064. // 1. 个人服务商
  1065. if req.SupplierType == 1 {
  1066. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  1067. if supplierIncomeErr != nil {
  1068. return nil, supplierIncomeErr
  1069. }
  1070. if supplierIncome != nil {
  1071. for _, income := range supplierIncome {
  1072. incomeData.FullAmount += income.ServiceChargeSettle
  1073. }
  1074. incomeData.Settle = incomeData.FullAmount
  1075. }
  1076. } else if req.SupplierType == 2 {
  1077. // 2. 企业服务商
  1078. // 可提现
  1079. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  1080. if supplierIncomeErr != nil {
  1081. return nil, supplierIncomeErr
  1082. }
  1083. if supplierIncome != nil {
  1084. for _, income := range supplierIncome {
  1085. incomeData.Settle += income.ServiceChargeSettle
  1086. }
  1087. incomeData.FullAmount = incomeData.Settle
  1088. }
  1089. // 可回票
  1090. supplierToInvoice, supplierToInvoiceErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
  1091. if supplierToInvoiceErr != nil {
  1092. return nil, supplierToInvoiceErr
  1093. }
  1094. if supplierToInvoice != nil {
  1095. for _, invoice := range supplierToInvoice {
  1096. incomeData.FullAmount += invoice.ServiceChargeSettle
  1097. }
  1098. }
  1099. }
  1100. // fmt.Println(incomeData)
  1101. return incomeData, nil
  1102. }
  1103. // GetWithdrawPaymentInfo 查找提现收款信息
  1104. func (*supplier) GetWithdrawPaymentInfo(ctx context.Context, req *http_model.WithdrawPaymentInfoRequest) (*http_model.WithdrawPaymentInfoData, error) {
  1105. var paymentInfo *http_model.WithdrawPaymentInfoData
  1106. paymentInfo = &http_model.WithdrawPaymentInfoData{}
  1107. // 1. 个人服务商
  1108. if req.SupplierType == 1 {
  1109. // 1.1. 个人认证信息
  1110. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  1111. if supplierErr != nil {
  1112. return nil, supplierErr
  1113. }
  1114. if supplierInfo != nil {
  1115. paymentInfo.Name = supplierInfo.Name
  1116. paymentInfo.IDNumber = supplierInfo.IdNumber
  1117. }
  1118. // 1.2. 提现收款信息查询
  1119. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
  1120. if supplierPaymentErr != nil {
  1121. return nil, supplierPaymentErr
  1122. }
  1123. if supplierPaymentInfo != nil {
  1124. paymentInfo.Tag = 2
  1125. paymentInfo.Phone = supplierPaymentInfo.Phone
  1126. paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
  1127. paymentInfo.BankName = supplierPaymentInfo.BankName
  1128. paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
  1129. } else {
  1130. paymentInfo.Tag = 1
  1131. }
  1132. } else if req.SupplierType == 2 {
  1133. // 2. 机构服务商
  1134. // 2.1. 机构认证信息
  1135. supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
  1136. if supplierErr != nil {
  1137. return nil, supplierErr
  1138. }
  1139. if supplierInfo != nil {
  1140. paymentInfo.Company = supplierInfo.CompanyName
  1141. }
  1142. // 2.2. 提现收款信息查询
  1143. supplierPaymentInfo, supplierPaymentErr := db.GetSupplierPaymentInfoById(ctx, req.SupplierId)
  1144. if supplierPaymentErr != nil {
  1145. return nil, supplierPaymentErr
  1146. }
  1147. if supplierPaymentInfo != nil {
  1148. paymentInfo.Tag = 2
  1149. paymentInfo.PaymentInfoID = supplierPaymentInfo.PaymentInfoID
  1150. paymentInfo.SupplierType = supplierPaymentInfo.SupplierType
  1151. paymentInfo.BankName = supplierPaymentInfo.BankName
  1152. paymentInfo.BankNumber = supplierPaymentInfo.BankNumber
  1153. } else {
  1154. paymentInfo.Tag = 1
  1155. }
  1156. }
  1157. return paymentInfo, nil
  1158. }
  1159. // UpdateWithdrawPaymentInfo 更新提现收款信息
  1160. func (*supplier) UpdateWithdrawPaymentInfo(ctx context.Context, req *http_model.UpdateWithdrawPaymentInfoRequest) error {
  1161. var paymentInfo *gorm_model.SupplierPaymentInfo
  1162. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  1163. paymentInfo.PaymentInfoID = req.PaymentInfoId
  1164. paymentInfo.SupplierID = req.SupplierID
  1165. paymentInfo.Phone = req.Phone
  1166. paymentInfo.BankName = req.BankName
  1167. paymentInfo.BankNumber = req.BankNumber
  1168. paymentInfo.Name = req.Name
  1169. paymentInfo.IDNumber = req.IDNumber
  1170. paymentInfo.Company = req.Company
  1171. updatePaymentInfoErr := db.UpdateSupplierPayment(ctx, paymentInfo)
  1172. if updatePaymentInfoErr != nil {
  1173. return updatePaymentInfoErr
  1174. }
  1175. return nil
  1176. }
  1177. // CreateWithdrawPaymentInfo 创建提现收款信息
  1178. func (*supplier) CreateWithdrawPaymentInfo(ctx context.Context, req *http_model.CreateWithdrawPaymentInfoRequest) error {
  1179. // 1. 个人服务商
  1180. if req.SupplierType == 1 {
  1181. var paymentInfo *gorm_model.SupplierPaymentInfo
  1182. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  1183. paymentInfo.SupplierID = req.SupplierID
  1184. paymentInfo.Phone = req.Phone
  1185. paymentInfo.BankName = req.BankName
  1186. paymentInfo.BankNumber = req.BankNumber
  1187. paymentInfo.Name = req.Name
  1188. paymentInfo.IDNumber = req.IDNumber
  1189. paymentInfo.SupplierType = req.SupplierType
  1190. createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
  1191. if createPaymentInfoErr != nil {
  1192. return createPaymentInfoErr
  1193. }
  1194. } else if req.SupplierType == 2 {
  1195. // 2. 机构服务商
  1196. var paymentInfo *gorm_model.SupplierPaymentInfo
  1197. paymentInfo = &gorm_model.SupplierPaymentInfo{}
  1198. paymentInfo.SupplierType = req.SupplierType
  1199. paymentInfo.SupplierID = req.SupplierID
  1200. paymentInfo.BankName = req.BankName
  1201. paymentInfo.BankNumber = req.BankNumber
  1202. paymentInfo.Name = req.Name
  1203. paymentInfo.IDNumber = req.IDNumber
  1204. paymentInfo.Company = req.Company
  1205. createPaymentInfoErr := db.CreateSupplierPayment(ctx, paymentInfo)
  1206. if createPaymentInfoErr != nil {
  1207. return createPaymentInfoErr
  1208. }
  1209. }
  1210. return nil
  1211. }
  1212. // GetSupplierInvoiceAmount 可回发票、待传发票、平台确认中、已回发票金额
  1213. func (*supplier) GetSupplierInvoiceAmount(ctx context.Context, req *http_model.InvoiceAmountRequest) (*http_model.InvoiceAmountData, error) {
  1214. var invoiceAmount *http_model.InvoiceAmountData
  1215. invoiceAmount = &http_model.InvoiceAmountData{}
  1216. invoiceAmount.InvoiceReturned = 0.0
  1217. invoiceAmount.PendingUpload = 0.0
  1218. invoiceAmount.CanUpload = 0.0
  1219. invoiceAmount.PlatformConfirming = 0.0
  1220. // 可回发票
  1221. supplierIncome, supplierIncomeErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 1)
  1222. if supplierIncomeErr != nil {
  1223. return nil, supplierIncomeErr
  1224. }
  1225. if supplierIncome != nil {
  1226. for _, income := range supplierIncome {
  1227. invoiceAmount.CanUpload += income.ServiceChargeSettle
  1228. }
  1229. }
  1230. // 待传发票
  1231. pendingUploadIncome, pendingUploadErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 2)
  1232. if pendingUploadErr != nil {
  1233. return nil, pendingUploadErr
  1234. }
  1235. if pendingUploadIncome != nil {
  1236. for _, income := range pendingUploadIncome {
  1237. invoiceAmount.PendingUpload += income.ServiceChargeSettle
  1238. }
  1239. }
  1240. // 平台确认中
  1241. platformConfirmingIncome, platformConfirmingErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 3)
  1242. if platformConfirmingErr != nil {
  1243. return nil, platformConfirmingErr
  1244. }
  1245. if platformConfirmingIncome != nil {
  1246. for _, income := range platformConfirmingIncome {
  1247. invoiceAmount.PlatformConfirming += income.ServiceChargeSettle
  1248. }
  1249. }
  1250. // 已回票
  1251. InvoiceReturnedIncome, InvoiceReturnedErr := db.GetFullSupplierIncomeList(ctx, req.SupplierId, 5)
  1252. if InvoiceReturnedErr != nil {
  1253. return nil, InvoiceReturnedErr
  1254. }
  1255. if InvoiceReturnedIncome != nil {
  1256. for _, income := range InvoiceReturnedIncome {
  1257. invoiceAmount.InvoiceReturned += income.ServiceChargeSettle
  1258. }
  1259. }
  1260. return invoiceAmount, nil
  1261. }
  1262. func (*supplier) SendCodeT(ctx context.Context, phone string, code string) error {
  1263. // 1. 创建客户端
  1264. config := &openapi.Config{
  1265. AccessKeyId: tea.String("LTAI5tDfTQeZ2ufN8mhsWQNA"),
  1266. AccessKeySecret: tea.String("DKLd2hGbmJPcNki8p6VlU6mV2HXVvO"),
  1267. Endpoint: tea.String("dysmsapi.aliyuncs.com"),
  1268. }
  1269. client, err := dysmsapi20170525.NewClient(config)
  1270. if err != nil {
  1271. return fmt.Errorf("创建客户端失败: %v", err)
  1272. }
  1273. // 2. 准备请求
  1274. sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
  1275. PhoneNumbers: tea.String(phone),
  1276. SignName: tea.String("北京智子时空科技"),
  1277. TemplateCode: tea.String("SMS_481650308"),
  1278. TemplateParam: tea.String(fmt.Sprintf(`{"code":"%s"}`, code)),
  1279. }
  1280. // 3. 发送请求
  1281. runtime := &util.RuntimeOptions{}
  1282. resp, err := client.SendSmsWithOptions(sendSmsRequest, runtime)
  1283. if err != nil {
  1284. // 错误处理
  1285. if sdkErr, ok := err.(*tea.SDKError); ok {
  1286. var data interface{}
  1287. if err := json.NewDecoder(strings.NewReader(tea.StringValue(sdkErr.Data))).Decode(&data); err == nil {
  1288. if m, ok := data.(map[string]interface{}); ok {
  1289. if recommend, exists := m["Recommend"]; exists {
  1290. return fmt.Errorf("短信发送失败: %s, 建议: %v", tea.StringValue(sdkErr.Message), recommend)
  1291. }
  1292. }
  1293. }
  1294. return fmt.Errorf("短信发送失败: %s", tea.StringValue(sdkErr.Message))
  1295. }
  1296. return fmt.Errorf("短信发送失败: %v", err)
  1297. }
  1298. // 4. 响应
  1299. fmt.Printf("短信发送成功,响应: %v\n", resp)
  1300. return nil
  1301. }