custom_service.go 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package service
  2. import (
  3. "XT_Admin_Api/models"
  4. "time"
  5. )
  6. func FindCustomInfo(org_id int64) (admin models.KyyChargeCustom, err error) {
  7. err = ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("xt_org_id = ? AND status = 1", org_id).First(&admin).Error
  8. return
  9. }
  10. func CreateCustom(admin *models.KyyChargeCustom) (err error) {
  11. err = ChargeWriteDB().Model(&models.KyyChargeCustom{}).Create(&admin).Error
  12. return
  13. }
  14. func SaveCustom(admin *models.KyyChargeCustom) (err error) {
  15. err = ChargeWriteDB().Model(&models.KyyChargeCustom{}).Create(&admin).Error
  16. return
  17. }
  18. func SaveCustomTwo(admin models.KyyChargeCustomThree) (err error) {
  19. err = ChargeWriteDB().Model(&models.KyyChargeCustomThree{}).Save(&admin).Error
  20. return
  21. }
  22. func GetAllCustoms(types int64) (cus []*models.KyyChargeCustom, err error) {
  23. switch types {
  24. case 0:
  25. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Where("status = 1").Find(&cus).Error
  26. break
  27. case 2:
  28. currentDate := time.Now()
  29. oneMonthLater := currentDate.AddDate(0, 1, 0)
  30. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Joins("LEFT JOIN kyy_charge_renewal as kr ON kyy_charge_custom.id = kr.custom_id").Where("status = 1 and ((kr.end_time BETWEEN ? AND ?) OR (kr.end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kyy_charge_custom.sign_end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kyy_charge_custom.sign_end_time BETWEEN ? AND ?))", currentDate, oneMonthLater,
  31. currentDate, oneMonthLater,
  32. currentDate, oneMonthLater,
  33. currentDate, oneMonthLater).Find(&cus).Error
  34. break
  35. case 1:
  36. currentDate := time.Now()
  37. threeMonthsLater := currentDate.AddDate(0, 3, 0)
  38. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Joins("LEFT JOIN kyy_charge_renewal as kr ON kyy_charge_custom.id = kr.custom_id").Where("status = 1 and ((kr.end_time BETWEEN ? AND ?) OR (kr.end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kyy_charge_custom.sign_end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kyy_charge_custom.sign_end_time BETWEEN ? AND ?))", currentDate, threeMonthsLater,
  39. currentDate, threeMonthsLater,
  40. currentDate, threeMonthsLater,
  41. currentDate, threeMonthsLater).Find(&cus).Error
  42. break
  43. case 3:
  44. currentYear := time.Now().Year()
  45. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Joins("JOIN kyy_charge_renewal kcr on kcr.custom_id = kyy_charge_custom.id and YEAR(kcr.start_time) = ?", currentYear).Where("status = 1").Find(&cus).Error
  46. break
  47. case 4:
  48. currentYear := time.Now().Year()
  49. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Where("YEAR(sign_time) = ? and is_implement = 0", currentYear).Find(&cus).Error
  50. break
  51. case 5:
  52. currentYear := time.Now().Year()
  53. err = ChargeReadDB().Model(&models.KyyChargeCustomTwo{}).Where("(YEAR(sign_time) = ? and lis_status = 0) or (YEAR(sign_time) = ? and qc_status = 0) or (YEAR(sign_time) = ? and yb_status = 0)", currentYear, currentYear, currentYear).Find(&cus).Error
  54. break
  55. }
  56. return
  57. }
  58. func GetAllPaymentCollections() (cus []*models.KyyChargePaymentCollection, err error) {
  59. err = ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Where("status = 1").Find(&cus).Error
  60. return
  61. }
  62. func GetAllChargeContacts() (cus []*models.KyyChargeContact, err error) {
  63. err = ChargeReadDB().Model(&models.KyyChargeContact{}).Where("status = 1").Find(&cus).Error
  64. return
  65. }
  66. func GetAllChargeContracts() (cus []*models.KyyChargeContract, err error) {
  67. err = ChargeReadDB().Model(&models.KyyChargeContract{}).Where("status = 1").Find(&cus).Error
  68. return
  69. }
  70. func GetAllChargeDemand() (cus []*models.KyyChargeDemand, err error) {
  71. err = ChargeReadDB().Model(&models.KyyChargeDemand{}).Where("status = 1").Find(&cus).Error
  72. return
  73. }
  74. func GetAllChargeFollow() (cus []*models.KyyChargeFollow, err error) {
  75. err = ChargeReadDB().Model(&models.KyyChargeFollow{}).Where("status = 1").Find(&cus).Error
  76. return
  77. }
  78. func GetAllChargeRenewal() (cus []*models.KyyChargeRenewal, err error) {
  79. err = ChargeReadDB().Model(&models.KyyChargeRenewal{}).Where("status = 1").Find(&cus).Error
  80. return
  81. }
  82. func FindCustomInfoByID(id int64) (admin models.KyyChargeCustom, err error) {
  83. err = ChargeReadDB().Model(&models.KyyChargeCustom{}).
  84. Preload("KyyChargePaymentCollection", "status = 1").
  85. Preload("KyyChargeContact", "status = 1").
  86. Preload("KyyChargeContract", "status = 1").
  87. Preload("KyyChargeDemand", "status = 1").
  88. Preload("KyyChargeFollow", "status = 1").
  89. Preload("KyyChargeRenewal", "status = 1").
  90. Where("id = ? AND status = 1", id).First(&admin).Error
  91. return
  92. }
  93. func FindCustomInfoByIDTwo(id int64) (admin models.KyyChargeCustomThree, err error) {
  94. err = ChargeReadDB().Model(&models.KyyChargeCustomThree{}).
  95. Where("id = ? AND status = 1", id).First(&admin).Error
  96. return
  97. }
  98. func UpdateCustom(custom models.KyyChargeCustom) (err error) {
  99. err = ChargeWriteDB().Save(&custom).Error
  100. return
  101. }
  102. func UpdateCustomTwo(custom models.KyyChargeCustomThree) (err error) {
  103. err = ChargeWriteDB().Save(&custom).Error
  104. return
  105. }
  106. func CreateChargePaymentCollection(cpc *models.KyyChargePaymentCollection) (err error) {
  107. err = ChargeWriteDB().Save(&cpc).Error
  108. return
  109. }
  110. func SaveChargePaymentCollection(cpc *models.KyyChargePaymentCollection) (err error) {
  111. err = ChargeWriteDB().Save(&cpc).Error
  112. return
  113. }
  114. func FindPaymentCollectionInfo(id int64) (cpc models.KyyChargePaymentCollection, err error) {
  115. err = ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Where("id = ? AND status = 1", id).First(&cpc).Error
  116. return
  117. }
  118. func SaveChargeContact(chargeContact *models.KyyChargeContact) (err error) {
  119. err = ChargeWriteDB().Save(&chargeContact).Error
  120. return
  121. }
  122. func FindChargeContactInfo(id int64) (cpc models.KyyChargeContact, err error) {
  123. err = ChargeReadDB().Model(&models.KyyChargeContact{}).Where("id = ? AND status = 1", id).First(&cpc).Error
  124. return
  125. }
  126. func SaveChargeContract(chargeContract *models.KyyChargeContract) (err error) {
  127. err = ChargeWriteDB().Save(&chargeContract).Error
  128. return
  129. }
  130. func FindChargeContractInfo(id int64) (cpc models.KyyChargeContract, err error) {
  131. err = ChargeReadDB().Model(&models.KyyChargeContract{}).Where("id = ? AND status = 1", id).First(&cpc).Error
  132. return
  133. }
  134. func SaveChargeFollow(chargeFollow *models.KyyChargeFollow) (err error) {
  135. err = ChargeWriteDB().Save(&chargeFollow).Error
  136. return
  137. }
  138. func CheckChargeFollowTwo(ids []int64) (err error) {
  139. err = ChargeWriteDB().Model(&models.KyyChargeFollow{}).Where("id in (?)", ids).Updates(map[string]interface{}{"is_check": 1}).Error
  140. return
  141. }
  142. func FindChargeFollowInfo(id int64) (cf models.KyyChargeFollow, err error) {
  143. err = ChargeReadDB().Model(&models.KyyChargeFollow{}).Where("id = ? AND status = 1", id).First(&cf).Error
  144. return
  145. }
  146. func FindChargeFollowInfoTwo(id int64) (cf []models.KyyChargeFollow, err error) {
  147. err = ChargeReadDB().Model(&models.KyyChargeFollow{}).Where("custom_id = ? AND status = 1", id).First(&cf).Error
  148. return
  149. }
  150. func SaveChargeDemand(cd *models.KyyChargeDemand) (err error) {
  151. err = ChargeWriteDB().Save(&cd).Error
  152. return
  153. }
  154. func FindChargeDemandInfo(id int64) (cd models.KyyChargeDemand, err error) {
  155. err = ChargeReadDB().Model(&models.KyyChargeDemand{}).Where("id = ? AND status = 1", id).First(&cd).Error
  156. return
  157. }
  158. func SaveChargeRenewal(chargeRenewal *models.KyyChargeRenewal) (err error) {
  159. err = ChargeWriteDB().Save(&chargeRenewal).Error
  160. return
  161. }
  162. func FindChargeRenewalInfo(id int64) (chargeRenewal models.KyyChargeRenewal, err error) {
  163. err = ChargeReadDB().Model(&models.KyyChargeRenewal{}).Where("id = ? AND status = 1", id).First(&chargeRenewal).Error
  164. return
  165. }