bill_service.go 7.2 KB

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