activity_special_trip_bill.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxActivitySpecialTripBill struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int `description:"用户id,多个用,隔开"`
  9. ActivityId int `description:"活动ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱号"`
  13. CompanyId int `description:"公司ID"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. AdminId int `description:"销售/管理员ID"`
  17. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  18. BillDetailed int `description:"流水明细,判断是进账还是出账"`
  19. DoType int `description:"操作方式,1报名,2取消报名"`
  20. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  21. ChartPermissionId int `description:"行业id"`
  22. ChartPermissionName string `description:"行业名称"`
  23. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  24. Content string `description:"内容"`
  25. Total string `description:"总和"`
  26. }
  27. // 添加
  28. func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
  29. o := orm.NewOrm()
  30. _, err = o.Insert(item)
  31. if err != nil {
  32. return
  33. }
  34. return
  35. }
  36. func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT *
  39. FROM
  40. cygx_activity_special_trip_bill
  41. WHERE 1 = 1 ` + condition
  42. _, err = o.Raw(sql, pars).QueryRows(&item)
  43. return
  44. }
  45. type CygxActivitySpecialTripBillList struct {
  46. Id int `orm:"column(id);pk"`
  47. UserId int `description:"用户id,多个用,隔开"`
  48. ActivityId int `description:"活动ID"`
  49. CreateTime time.Time `description:"创建时间"`
  50. Mobile string `description:"手机号"`
  51. Email string `description:"邮箱号"`
  52. CompanyId int `description:"公司ID"`
  53. CompanyName string `description:"公司名称"`
  54. RealName string `description:"用户实际名称"`
  55. AdminId int `description:"销售/管理员ID"`
  56. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  57. BillDetailed int `description:"流水明细,判断是进账还是出账"`
  58. DoType int `description:"操作方式,1报名,2取消报名"`
  59. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  60. ChartPermissionId int `description:"行业id"`
  61. ChartPermissionName string `description:"行业名称"`
  62. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  63. Content string `description:"内容"`
  64. }
  65. func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
  66. o := orm.NewOrm()
  67. sql := `SELECT
  68. b.*
  69. FROM
  70. cygx_activity_special_trip_bill AS b
  71. WHERE
  72. 1 = 1` + condition
  73. _, err = o.Raw(sql, pars).QueryRows(&item)
  74. return
  75. }
  76. type SpecialBillInitBig struct {
  77. ApprovalTime time.Time
  78. CompanyId int
  79. CompanyName string
  80. }
  81. func GetActivitySecialTirpBillForInit(packageType int) (item []*SpecialBillInitBig, err error) {
  82. o := orm.NewOrm()
  83. sql := ` SELECT
  84. a.approve_time,d.company_id,c.company_name
  85. FROM
  86. company_approval a
  87. INNER JOIN company_contract b ON a.company_contract_id = b.company_contract_id
  88. INNER JOIN company c ON a.company_id = c.company_id
  89. INNER JOIN cygx_company_user_type d ON a.company_id = d.company_id
  90. WHERE
  91. a.apply_method = 1
  92. AND a.product_id = 2
  93. AND a.approve_status = '已审批'
  94. AND b.product_id = 2
  95. AND d.package_type = ?
  96. GROUP BY d.company_id `
  97. _, err = o.Raw(sql, packageType).QueryRows(&item)
  98. return
  99. }
  100. type SpecialBillInitNotBig struct {
  101. ApprovalTime time.Time
  102. CompanyId int
  103. CompanyName string
  104. ChartPermissionIds string
  105. }
  106. func GetActivitySecialTirpBillForInitNotBig() (item []*SpecialBillInitNotBig, err error) {
  107. o := orm.NewOrm()
  108. sql := ` SELECT
  109. a.approve_time,d.company_id,d.company_name,GROUP_CONCAT(DISTINCT c.chart_permission_id) AS chart_permission_ids
  110. FROM
  111. company_approval a
  112. INNER JOIN company_contract b ON a.company_contract_id = b.company_contract_id
  113. INNER JOIN company_report_permission c ON a.company_id = c.company_id
  114. INNER JOIN company d ON a.company_id = d.company_id
  115. WHERE
  116. a.apply_method = 1
  117. AND a.product_id = 2
  118. AND a.approve_status = '已审批'
  119. AND b.product_id = 2
  120. AND c.product_id = 2
  121. AND c.is_upgrade = 1
  122. GROUP BY d.company_id `
  123. _, err = o.Raw(sql).QueryRows(&item)
  124. return
  125. }
  126. // 批量添加
  127. func AddCygxActivitySpecialTripBillMulti(items []*CygxActivitySpecialTripBill) (err error) {
  128. o := orm.NewOrm()
  129. if len(items) > 0 {
  130. //批量添加
  131. _, err = o.InsertMulti(len(items), items)
  132. }
  133. return
  134. }
  135. type SpecialBillInitReduce struct {
  136. CreateTime time.Time
  137. CompanyId int
  138. CompanyName string
  139. }
  140. func GetActivitySecialTirpBillForReduce() (item []*SpecialBillInitReduce, err error) {
  141. o := orm.NewOrm()
  142. sql := ` SELECT
  143. a.create_time,a.company_id,c.company_name
  144. FROM
  145. company_operation_record a
  146. INNER JOIN company c ON a.company_id = c.company_id
  147. INNER JOIN company_report_permission e ON a.company_id = e.company_id
  148. WHERE
  149. a.operation = 'try_out'
  150. AND a.product_id = 2
  151. AND e.status NOT IN ('正式','永续')
  152. GROUP BY a.company_id `
  153. _, err = o.Raw(sql).QueryRows(&item)
  154. return
  155. }
  156. func GetCygxActivitySpecialTripBillForInit() (item []*CygxActivitySpecialTripBill, err error) {
  157. o := orm.NewOrm()
  158. sql := ` SELECT * FROM cygx_activity_special_trip_bill GROUP BY company_id `
  159. _, err = o.Raw(sql).QueryRows(&item)
  160. return
  161. }
  162. func GetCygxActivitySpecialTripBillByCompanyIdForInit(companyId int) (item []*CygxActivitySpecialTripBill, err error) {
  163. o := orm.NewOrm()
  164. sql := ` SELECT * FROM cygx_activity_special_trip_bill WHERE company_id = ? ORDER BY create_time DESC `
  165. _, err = o.Raw(sql, companyId).QueryRows(&item)
  166. return
  167. }
  168. func UpdateCygxActivitySpecialTripBillByCompanyIdForInit(total string, id int) (err error) {
  169. o := orm.NewOrm()
  170. sql := ` UPDATE cygx_activity_special_trip_bill SET total=? WHERE id = ? `
  171. _, err = o.Raw(sql, total, id).Exec()
  172. return
  173. }