bill_service.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. package service
  2. import (
  3. "errors"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "youngee_b_api/app/dao"
  8. "youngee_b_api/app/entity"
  9. "youngee_b_api/app/vo"
  10. )
  11. type BillService struct{}
  12. // 电商带货账单支付
  13. func (s BillService) PaySelection(param *vo.PayParam) error {
  14. selectionId := param.ObjectId
  15. selectionInfo, err1 := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  16. if err1 != nil {
  17. return err1
  18. }
  19. selectionStatus := selectionInfo.SelectionStatus
  20. if selectionStatus != 4 {
  21. return errors.New("状态异常")
  22. }
  23. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(selectionInfo.EnterpriseID, selectionInfo.EstimatedCost)
  24. if err2 != nil {
  25. return err2
  26. }
  27. err3 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(entity.SelectionInfo{SelectionID: selectionId, SelectionStatus: 6, PayAt: time.Now()})
  28. if err3 != nil {
  29. return err3
  30. }
  31. return nil
  32. }
  33. // 品牌种草账单支付
  34. func (s BillService) PayProject(param *vo.PayParam) error {
  35. projectId := param.ObjectId
  36. projectInfo, err1 := dao.ProjectDAO{}.GetProjectById(projectId)
  37. if err1 != nil {
  38. return err1
  39. }
  40. projectStatus := projectInfo.ProjectStatus
  41. if projectStatus != 6 {
  42. return errors.New("状态异常")
  43. }
  44. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(projectInfo.EnterpriseID, projectInfo.NeedPay)
  45. if err2 != nil {
  46. return err2
  47. }
  48. err3 := dao.ProjectDAO{}.UpdateProject(entity.Project{ProjectId: projectId, ProjectStatus: 8, PayAt: time.Now()})
  49. if err3 != nil {
  50. return err3
  51. }
  52. return nil
  53. }
  54. // 本地生活账单支付
  55. func (s BillService) PayLocalLife(param *vo.PayParam) error {
  56. localId := param.ObjectId
  57. localInfo, err1 := dao.LocalLifeDao{}.GetLocalById(localId)
  58. if err1 != nil {
  59. return err1
  60. }
  61. localStatus := localInfo.TaskStatus
  62. if localStatus != 6 {
  63. return errors.New("状态异常")
  64. }
  65. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(localInfo.EnterpriseID, localInfo.NeedPay)
  66. if err2 != nil {
  67. return err2
  68. }
  69. err3 := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{LocalID: localId, TaskStatus: 8, PayAt: time.Now()})
  70. if err3 != nil {
  71. return err3
  72. }
  73. return nil
  74. }
  75. // 电商带货账单列表
  76. func (s BillService) GetBillSelectionTaskList(param *vo.SelectionSearchParam) (vo.ResultVO, error) {
  77. if param.Page == 0 {
  78. param.Page = 1
  79. }
  80. if param.PageSize == 0 {
  81. param.PageSize = 10
  82. }
  83. var result vo.ResultVO
  84. reBillSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetBillSelectionPreviews(param)
  85. if err != nil {
  86. return result, err
  87. }
  88. for i := range reBillSelectionTaskPreviews {
  89. var creatorName string
  90. var productName string
  91. var productPrice float64
  92. var mainImage string
  93. var reward float64
  94. if reBillSelectionTaskPreviews[i].SubAccountId == 0 {
  95. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillSelectionTaskPreviews[i].EnterpriseId)
  96. if err == nil && enterprise != nil {
  97. creatorName = enterprise.BusinessName
  98. }
  99. } else {
  100. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillSelectionTaskPreviews[i].SubAccountId)
  101. if err == nil && subAccount != nil {
  102. creatorName = subAccount.SubAccountName
  103. }
  104. }
  105. product, err := dao.ProductDAO{}.GetProductByID(reBillSelectionTaskPreviews[i].ProductId)
  106. if err == nil && product != nil {
  107. productName = product.ProductName
  108. productPrice = product.ProductPrice
  109. }
  110. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillSelectionTaskPreviews[i].ProductId)
  111. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(reBillSelectionTaskPreviews[i].SelectionId)
  112. for _, rewardStrategy := range rewardStrategys {
  113. reward += rewardStrategy.Reward
  114. }
  115. reBillSelectionTaskPreviews[i].CreatorName = creatorName
  116. reBillSelectionTaskPreviews[i].ProductName = productName
  117. reBillSelectionTaskPreviews[i].ProductPrice = productPrice
  118. reBillSelectionTaskPreviews[i].MainImage = mainImage
  119. reBillSelectionTaskPreviews[i].Reward = reward
  120. }
  121. result = vo.ResultVO{
  122. Page: param.Page,
  123. PageSize: param.PageSize,
  124. Total: total,
  125. Data: reBillSelectionTaskPreviews,
  126. }
  127. return result, nil
  128. }
  129. // 品牌种草账单列表
  130. func (s BillService) GetBillProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) {
  131. if param.Page == 0 {
  132. param.Page = 1
  133. }
  134. if param.PageSize == 0 {
  135. param.PageSize = 10
  136. }
  137. var result vo.ResultVO
  138. reBillProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetBillProjectPreviews(param)
  139. if err != nil {
  140. return result, err
  141. }
  142. for i := range reBillProjectTaskPreviews {
  143. var creatorName string
  144. var productName string
  145. var productPrice float64
  146. var mainImage string
  147. if reBillProjectTaskPreviews[i].SubAccountId == 0 {
  148. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillProjectTaskPreviews[i].EnterpriseId)
  149. if err == nil && enterprise != nil {
  150. creatorName = enterprise.BusinessName
  151. }
  152. } else {
  153. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillProjectTaskPreviews[i].SubAccountId)
  154. if err == nil && subAccount != nil {
  155. creatorName = subAccount.SubAccountName
  156. }
  157. }
  158. product, err := dao.ProductDAO{}.GetProductByID(reBillProjectTaskPreviews[i].ProductId)
  159. if err == nil && product != nil {
  160. productName = product.ProductName
  161. productPrice = product.ProductPrice
  162. }
  163. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillProjectTaskPreviews[i].ProductId)
  164. reBillProjectTaskPreviews[i].CreatorName = creatorName
  165. reBillProjectTaskPreviews[i].ProductName = productName
  166. reBillProjectTaskPreviews[i].ProductPrice = productPrice
  167. reBillProjectTaskPreviews[i].MainImage = mainImage
  168. }
  169. result = vo.ResultVO{
  170. Page: param.Page,
  171. PageSize: param.PageSize,
  172. Total: total,
  173. Data: reBillProjectTaskPreviews,
  174. }
  175. return result, nil
  176. }
  177. // 品牌种草账单服务商列表
  178. func (s BillService) GetBillProjectSupplierList(param *vo.SearchSupplierBillParam) (vo.ResultVO, error) {
  179. if param.Page == 0 {
  180. param.Page = 1
  181. }
  182. if param.PageSize == 0 {
  183. param.PageSize = 10
  184. }
  185. var result vo.ResultVO
  186. var reBillSuppliers []vo.ReBillSupplier
  187. var status int64
  188. if param.Status == 1 {
  189. status = 8
  190. } else if param.Status == 2 {
  191. status = 10
  192. }
  193. sProjectInfos, total, err := dao.SProjectDao{}.GetSProjectByProjectStatus(param.TaskId, status, param.Page, param.PageSize)
  194. if err != nil {
  195. return result, err
  196. }
  197. project, err01 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  198. if err01 != nil || project == nil {
  199. return result, err01
  200. }
  201. serviceRate := project.ServiceChargeRate
  202. type SumResult struct {
  203. PayAmount float64 `json:"payAmount" gorm:"column:payAmount"`
  204. RealAmount float64 `json:"realAmount" gorm:"column:realAmount"`
  205. Count int `json:"count" gorm:"column:count"`
  206. }
  207. var sumResult SumResult
  208. _ = dao.Db.Debug().
  209. Model(&entity.ProjectTaskInfo{}).
  210. Where("project_id = ? and task_status = ? and supplier_id = ?", param.TaskId, 2, 0).
  211. Select("SUM(real_payment) as payAmount, SUM(real_service_charge) as realAmount, count(1) as count").
  212. Scan(&sumResult).Error
  213. for _, sProjectInfo := range sProjectInfos {
  214. reBillSupplier := vo.ReBillSupplier{
  215. SupplierId: sProjectInfo.SupplierID,
  216. TalentNum: sProjectInfo.RecruitNum,
  217. ChargeActual: sProjectInfo.ServiceChargeActual,
  218. ChargeSettle: sProjectInfo.ServiceChargeSettle,
  219. ServiceRate: serviceRate,
  220. }
  221. supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(sProjectInfo.SupplierID)
  222. if err1 == nil && supplier != nil {
  223. reBillSupplier.SupplierName = supplier.SupplierName
  224. reBillSupplier.Avatar = supplier.Avatar
  225. reBillSupplier.SupplierName = supplier.SupplierName
  226. reBillSupplier.CompanyName = supplier.CompanyName
  227. reBillSupplier.SupplierType = supplier.SupplierType
  228. }
  229. if sProjectInfo.BOperatorType == 1 {
  230. // 商家主账号
  231. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(sProjectInfo.BOperator)
  232. if err == nil && enterprise != nil {
  233. reBillSupplier.Inviter = enterprise.BusinessName
  234. }
  235. } else {
  236. // 商家子账号
  237. subId, err2 := strconv.ParseInt(sProjectInfo.BOperator, 10, 64)
  238. if err2 != nil {
  239. fmt.Println("子账号转换错误:", err)
  240. subId = 0
  241. }
  242. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subId)
  243. if err == nil && subAccount != nil {
  244. reBillSupplier.Inviter = subAccount.SubAccountName
  245. }
  246. }
  247. reBillSuppliers = append(reBillSuppliers, reBillSupplier)
  248. }
  249. resMap := make(map[string]interface{})
  250. resMap["talentNum"] = sumResult.Count
  251. resMap["payAmount"] = sumResult.PayAmount
  252. resMap["realAmount"] = sumResult.RealAmount
  253. resMap["reBillSuppliers"] = reBillSuppliers
  254. result = vo.ResultVO{
  255. Page: param.Page,
  256. PageSize: param.PageSize,
  257. Total: total,
  258. Data: resMap,
  259. }
  260. return result, nil
  261. }
  262. // 本地生活账单服务商列表
  263. func (s BillService) GetBillLocalSupplierList(param *vo.SearchSupplierBillParam) (vo.ResultVO, error) {
  264. if param.Page == 0 {
  265. param.Page = 1
  266. }
  267. if param.PageSize == 0 {
  268. param.PageSize = 10
  269. }
  270. var result vo.ResultVO
  271. var reBillSuppliers []vo.ReBillSupplier
  272. var status int64
  273. if param.Status == 1 {
  274. status = 8
  275. } else if param.Status == 2 {
  276. status = 10
  277. }
  278. sLocalInfos, total, err := dao.SLocalLifeDao{}.GetSLocalByLocalStatus(param.TaskId, status, param.Page, param.PageSize)
  279. if err != nil {
  280. return result, err
  281. }
  282. local, err01 := dao.LocalLifeDao{}.GetLocalById(param.TaskId)
  283. if err01 != nil || local == nil {
  284. return result, err01
  285. }
  286. serviceRate := local.ServiceChargeRate
  287. type SumResult struct {
  288. PayAmount float64 `json:"payAmount" gorm:"column:payAmount"`
  289. RealAmount float64 `json:"realAmount" gorm:"column:realAmount"`
  290. Count int `json:"count" gorm:"column:count"`
  291. }
  292. var sumResult SumResult
  293. _ = dao.Db.Debug().
  294. Model(&entity.LocalLifeTaskInfo{}).
  295. Where("local_id = ? and task_status = ? and supplier_id = ?", param.TaskId, 2, 0).
  296. Select("SUM(real_payment) as payAmount, SUM(real_service_charge) as realAmount, count(1) as count").
  297. Scan(&sumResult).Error
  298. for _, sLocalInfo := range sLocalInfos {
  299. reBillSupplier := vo.ReBillSupplier{
  300. SupplierId: sLocalInfo.SupplierID,
  301. TalentNum: sLocalInfo.RecruitNum,
  302. ChargeActual: sLocalInfo.ServiceChargeActual,
  303. ChargeSettle: sLocalInfo.ServiceChargeSettle,
  304. ServiceRate: serviceRate,
  305. }
  306. supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(sLocalInfo.SupplierID)
  307. if err1 == nil && supplier != nil {
  308. reBillSupplier.SupplierName = supplier.SupplierName
  309. reBillSupplier.Avatar = supplier.Avatar
  310. reBillSupplier.SupplierName = supplier.SupplierName
  311. reBillSupplier.CompanyName = supplier.CompanyName
  312. reBillSupplier.SupplierType = supplier.SupplierType
  313. }
  314. if sLocalInfo.BOperatorType == 1 {
  315. // 商家主账号
  316. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(sLocalInfo.BOperator)
  317. if err == nil && enterprise != nil {
  318. reBillSupplier.Inviter = enterprise.BusinessName
  319. }
  320. } else {
  321. // 商家子账号
  322. subId, err2 := strconv.ParseInt(sLocalInfo.BOperator, 10, 64)
  323. if err2 != nil {
  324. fmt.Println("子账号转换错误:", err)
  325. subId = 0
  326. }
  327. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subId)
  328. if err == nil && subAccount != nil {
  329. reBillSupplier.Inviter = subAccount.SubAccountName
  330. }
  331. }
  332. reBillSuppliers = append(reBillSuppliers, reBillSupplier)
  333. }
  334. resMap := make(map[string]interface{})
  335. resMap["talentNum"] = sumResult.Count
  336. resMap["payAmount"] = sumResult.PayAmount
  337. resMap["realAmount"] = sumResult.RealAmount
  338. resMap["reBillSuppliers"] = reBillSuppliers
  339. result = vo.ResultVO{
  340. Page: param.Page,
  341. PageSize: param.PageSize,
  342. Total: total,
  343. Data: resMap,
  344. }
  345. return result, nil
  346. }
  347. // 本地生活账单列表
  348. func (s BillService) GetBillLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  349. if param.Page == 0 {
  350. param.Page = 1
  351. }
  352. if param.PageSize == 0 {
  353. param.PageSize = 10
  354. }
  355. var result vo.ResultVO
  356. reBillLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetBillLocalPreviews(param)
  357. if err != nil {
  358. return result, err
  359. }
  360. for i := range reBillLocalTaskPreviews {
  361. var creatorName string
  362. var storeName string
  363. var storeLocation string
  364. var mainImage string
  365. if reBillLocalTaskPreviews[i].SubAccountId == 0 {
  366. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillLocalTaskPreviews[i].EnterpriseId)
  367. if err == nil && enterprise != nil {
  368. creatorName = enterprise.BusinessName
  369. }
  370. } else {
  371. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillLocalTaskPreviews[i].SubAccountId)
  372. if err == nil && subAccount != nil {
  373. creatorName = subAccount.SubAccountName
  374. }
  375. }
  376. store, err := dao.StoreDao{}.GetStoreByID(reBillLocalTaskPreviews[i].StoreId)
  377. if err == nil && store != nil {
  378. storeName = store.StoreName
  379. storeLocation = store.StoreLocation
  380. }
  381. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reBillLocalTaskPreviews[i].StoreId)
  382. reBillLocalTaskPreviews[i].CreatorName = creatorName
  383. reBillLocalTaskPreviews[i].StoreName = storeName
  384. reBillLocalTaskPreviews[i].StoreLocation = storeLocation
  385. reBillLocalTaskPreviews[i].MainImage = mainImage
  386. }
  387. result = vo.ResultVO{
  388. Page: param.Page,
  389. PageSize: param.PageSize,
  390. Total: total,
  391. Data: reBillLocalTaskPreviews,
  392. }
  393. return result, nil
  394. }