bill_service.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package service
  2. import (
  3. "errors"
  4. "youngee_b_api/app/dao"
  5. "youngee_b_api/app/entity"
  6. "youngee_b_api/app/vo"
  7. )
  8. type BillService struct{}
  9. // 电商带货账单支付
  10. func (s BillService) PaySelection(param *vo.PayParam) error {
  11. selectionId := param.ObjectId
  12. selectionInfo, err1 := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  13. if err1 != nil {
  14. return err1
  15. }
  16. selectionStatus := selectionInfo.SelectionStatus
  17. if selectionStatus != 4 {
  18. return errors.New("状态异常")
  19. }
  20. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(selectionInfo.EnterpriseID, selectionInfo.EstimatedCost)
  21. if err2 != nil {
  22. return err2
  23. }
  24. err3 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(entity.SelectionInfo{SelectionID: selectionId, SelectionStatus: 6})
  25. if err3 != nil {
  26. return err3
  27. }
  28. return nil
  29. }
  30. // 品牌种草账单支付
  31. func (s BillService) PayProject(param *vo.PayParam) error {
  32. projectId := param.ObjectId
  33. projectInfo, err1 := dao.ProjectDAO{}.GetProjectById(projectId)
  34. if err1 != nil {
  35. return err1
  36. }
  37. projectStatus := projectInfo.ProjectStatus
  38. if projectStatus != 6 {
  39. return errors.New("状态异常")
  40. }
  41. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(projectInfo.EnterpriseID, projectInfo.PaymentAmount)
  42. if err2 != nil {
  43. return err2
  44. }
  45. err3 := dao.ProjectDAO{}.UpdateProject(entity.Project{ProjectId: projectId, ProjectStatus: 8})
  46. if err3 != nil {
  47. return err3
  48. }
  49. return nil
  50. }
  51. // 本地生活账单支付
  52. func (s BillService) PayLocalLife(param *vo.PayParam) error {
  53. localId := param.ObjectId
  54. localInfo, err1 := dao.LocalLifeDao{}.GetLocalById(localId)
  55. if err1 != nil {
  56. return err1
  57. }
  58. localStatus := localInfo.TaskStatus
  59. if localStatus != 6 {
  60. return errors.New("状态异常")
  61. }
  62. _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(localInfo.EnterpriseID, localInfo.PaymentAmount)
  63. if err2 != nil {
  64. return err2
  65. }
  66. err3 := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{LocalID: localId, TaskStatus: 8})
  67. if err3 != nil {
  68. return err3
  69. }
  70. return nil
  71. }
  72. // 电商带货账单列表
  73. func (s BillService) GetBillSelectionTaskList(param *vo.SelectionSearchParam) (vo.ResultVO, error) {
  74. if param.Page == 0 {
  75. param.Page = 1
  76. }
  77. if param.PageSize == 0 {
  78. param.PageSize = 10
  79. }
  80. var result vo.ResultVO
  81. reBillSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetBillSelectionPreviews(param)
  82. if err != nil {
  83. return result, err
  84. }
  85. for i := range reBillSelectionTaskPreviews {
  86. var creatorName string
  87. var productName string
  88. var productPrice float64
  89. var mainImage string
  90. var reward float64
  91. if reBillSelectionTaskPreviews[i].SubAccountId == 0 {
  92. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillSelectionTaskPreviews[i].EnterpriseId)
  93. if err == nil && enterprise != nil {
  94. creatorName = enterprise.BusinessName
  95. }
  96. } else {
  97. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillSelectionTaskPreviews[i].SubAccountId)
  98. if err == nil && subAccount != nil {
  99. creatorName = subAccount.SubAccountName
  100. }
  101. }
  102. product, err := dao.ProductDAO{}.GetProductByID(reBillSelectionTaskPreviews[i].ProductId)
  103. if err == nil && product != nil {
  104. productName = product.ProductName
  105. productPrice = product.ProductPrice
  106. }
  107. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillSelectionTaskPreviews[i].ProductId)
  108. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(reBillSelectionTaskPreviews[i].SelectionId)
  109. for _, rewardStrategy := range rewardStrategys {
  110. reward += rewardStrategy.Reward
  111. }
  112. reBillSelectionTaskPreviews[i].CreatorName = creatorName
  113. reBillSelectionTaskPreviews[i].ProductName = productName
  114. reBillSelectionTaskPreviews[i].ProductPrice = productPrice
  115. reBillSelectionTaskPreviews[i].MainImage = mainImage
  116. reBillSelectionTaskPreviews[i].Reward = reward
  117. }
  118. result = vo.ResultVO{
  119. Page: param.Page,
  120. PageSize: param.PageSize,
  121. Total: total,
  122. Data: reBillSelectionTaskPreviews,
  123. }
  124. return result, nil
  125. }
  126. // 品牌种草账单列表
  127. func (s BillService) GetBillProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) {
  128. if param.Page == 0 {
  129. param.Page = 1
  130. }
  131. if param.PageSize == 0 {
  132. param.PageSize = 10
  133. }
  134. var result vo.ResultVO
  135. reBillProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetBillProjectPreviews(param)
  136. if err != nil {
  137. return result, err
  138. }
  139. for i := range reBillProjectTaskPreviews {
  140. var creatorName string
  141. var productName string
  142. var productPrice float64
  143. var mainImage string
  144. if reBillProjectTaskPreviews[i].SubAccountId == 0 {
  145. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillProjectTaskPreviews[i].EnterpriseId)
  146. if err == nil && enterprise != nil {
  147. creatorName = enterprise.BusinessName
  148. }
  149. } else {
  150. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillProjectTaskPreviews[i].SubAccountId)
  151. if err == nil && subAccount != nil {
  152. creatorName = subAccount.SubAccountName
  153. }
  154. }
  155. product, err := dao.ProductDAO{}.GetProductByID(reBillProjectTaskPreviews[i].ProductId)
  156. if err == nil && product != nil {
  157. productName = product.ProductName
  158. productPrice = product.ProductPrice
  159. }
  160. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillProjectTaskPreviews[i].ProductId)
  161. reBillProjectTaskPreviews[i].CreatorName = creatorName
  162. reBillProjectTaskPreviews[i].ProductName = productName
  163. reBillProjectTaskPreviews[i].ProductPrice = productPrice
  164. reBillProjectTaskPreviews[i].MainImage = mainImage
  165. }
  166. result = vo.ResultVO{
  167. Page: param.Page,
  168. PageSize: param.PageSize,
  169. Total: total,
  170. Data: reBillProjectTaskPreviews,
  171. }
  172. return result, nil
  173. }
  174. // 本地生活账单列表
  175. func (s BillService) GetBillLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  176. if param.Page == 0 {
  177. param.Page = 1
  178. }
  179. if param.PageSize == 0 {
  180. param.PageSize = 10
  181. }
  182. var result vo.ResultVO
  183. reBillLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetBillLocalPreviews(param)
  184. if err != nil {
  185. return result, err
  186. }
  187. for i := range reBillLocalTaskPreviews {
  188. var creatorName string
  189. var storeName string
  190. var storeLocation string
  191. var mainImage string
  192. if reBillLocalTaskPreviews[i].SubAccountId == 0 {
  193. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillLocalTaskPreviews[i].EnterpriseId)
  194. if err == nil && enterprise != nil {
  195. creatorName = enterprise.BusinessName
  196. }
  197. } else {
  198. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillLocalTaskPreviews[i].SubAccountId)
  199. if err == nil && subAccount != nil {
  200. creatorName = subAccount.SubAccountName
  201. }
  202. }
  203. store, err := dao.StoreDao{}.GetStoreByID(reBillLocalTaskPreviews[i].StoreId)
  204. if err == nil && store != nil {
  205. storeName = store.StoreName
  206. storeLocation = store.StoreLocation
  207. }
  208. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reBillLocalTaskPreviews[i].StoreId)
  209. reBillLocalTaskPreviews[i].CreatorName = creatorName
  210. reBillLocalTaskPreviews[i].StoreName = storeName
  211. reBillLocalTaskPreviews[i].StoreLocation = storeLocation
  212. reBillLocalTaskPreviews[i].MainImage = mainImage
  213. }
  214. result = vo.ResultVO{
  215. Page: param.Page,
  216. PageSize: param.PageSize,
  217. Total: total,
  218. Data: reBillLocalTaskPreviews,
  219. }
  220. return result, nil
  221. }