activity_special_trip_bill.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package cygx
  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. type CygxActivitySpecialTripBillList struct {
  28. Id int `orm:"column(id);pk"`
  29. UserId int `description:"用户id,多个用,隔开"`
  30. ActivityId int `description:"活动ID"`
  31. CreateTime time.Time `description:"创建时间"`
  32. Mobile string `description:"手机号"`
  33. Email string `description:"邮箱号"`
  34. CompanyId int `description:"公司ID"`
  35. CompanyName string `description:"公司名称"`
  36. RealName string `description:"用户实际名称"`
  37. AdminId int `description:"销售/管理员ID"`
  38. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  39. BillDetailed int `description:"流水明细,判断是进账还是出账"`
  40. DoType int `description:"操作方式,1报名,2取消报名"`
  41. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  42. ChartPermissionId int `description:"行业id"`
  43. ChartPermissionName string `description:"行业名称"`
  44. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  45. Content string `description:"内容"`
  46. Total string `description:"总和"`
  47. }
  48. // 添加
  49. func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
  50. o := orm.NewOrmUsingDB("hz_cygx")
  51. _, err = o.Insert(item)
  52. if err != nil {
  53. return
  54. }
  55. return
  56. }
  57. func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
  58. o := orm.NewOrmUsingDB("hz_cygx")
  59. sql := `SELECT *
  60. FROM
  61. cygx_activity_special_trip_bill
  62. WHERE 1 = 1 ` + condition
  63. _, err = o.Raw(sql, pars).QueryRows(&item)
  64. return
  65. }
  66. func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
  67. o := orm.NewOrmUsingDB("hz_cygx")
  68. sql := `SELECT
  69. b.*
  70. FROM
  71. cygx_activity_special_trip_bill AS b
  72. WHERE
  73. 1 = 1` + condition
  74. _, err = o.Raw(sql, pars).QueryRows(&item)
  75. return
  76. }
  77. type AirborneCount struct {
  78. Count int
  79. ChartPermissionId int ` description:"品种权限ID"`
  80. }
  81. // 获取空降的公司报名的记录
  82. func GetActivitySpecialTripAirborneListByActivitySpecial(condition string, pars []interface{}) (items []*AirborneCount, err error) {
  83. sqlCount := ` SELECT chart_permission_id,COUNT(1) AS count
  84. FROM
  85. cygx_activity_special_meeting_detail AS t
  86. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  87. WHERE
  88. 1= 1 AND YEAR ( t.create_time )= YEAR (NOW()) ` + condition + `GROUP BY chart_permission_id`
  89. o := orm.NewOrmUsingDB("hz_cygx")
  90. _, err = o.Raw(sqlCount, pars).QueryRows(&items)
  91. return
  92. }
  93. // 获取空降的公司报名的记录
  94. func GetActivitySpecialTripAirborneCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
  95. sqlCount := ` SELECT COUNT(1) AS count
  96. FROM
  97. cygx_activity_special_meeting_detail AS t
  98. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  99. WHERE
  100. 1= 1 AND YEAR ( t.create_time )= YEAR (NOW()) ` + condition
  101. o := orm.NewOrmUsingDB("hz_cygx")
  102. err = o.Raw(sqlCount, pars).QueryRow(&count)
  103. return
  104. }
  105. type CygxActivitySpecialTripBillDetailList struct {
  106. Id int `orm:"column(id);pk"`
  107. UserId int `description:"用户id,多个用,隔开"`
  108. ActivityId int `description:"活动ID"`
  109. ResearchTheme string `description:"调研主题"`
  110. CreateTime time.Time `description:"创建时间"`
  111. Mobile string `description:"手机号"`
  112. Email string `description:"邮箱号"`
  113. CompanyId int `description:"公司ID"`
  114. CompanyName string `description:"公司名称"`
  115. RealName string `description:"用户实际名称"`
  116. AdminId int `description:"销售/管理员ID"`
  117. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  118. BillDetailed int `description:"流水明细,判断是进账还是出账"`
  119. DoType int `description:"操作方式,1报名,2取消报名"`
  120. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  121. ChartPermissionId int `description:"行业id"`
  122. ChartPermissionName string `description:"行业名称"`
  123. Content string `description:"内容"`
  124. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  125. Total string `description:"总和"`
  126. }
  127. //func GetCygxActivitySpecialTripBillDetailList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillDetailList, err error) {
  128. // o := orm.NewOrm()
  129. // sql := `SELECT
  130. // b.*,
  131. // a.research_theme,
  132. // c.chart_permission_name
  133. // FROM
  134. // cygx_activity_special_trip_bill AS b
  135. // INNER JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id
  136. // INNER JOIN cygx_activity_special AS a ON a.activity_id = b.activity_id
  137. // WHERE
  138. // 1 = 1` + condition
  139. // _, err = o.Raw(sql, pars).QueryRows(&item)
  140. // return
  141. //}
  142. type CygxActivitySpecialPointsBillRespItem struct {
  143. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT"`
  144. Content string `gorm:"column:content" ` // 内容说明
  145. Total string `gorm:"column:points;default:0;NOT NULL" ` // 合计
  146. CreateTime string `gorm:"column:create_time" ` // 创建时间
  147. CompanyId int `gorm:"column:company_id;default:0" ` // 公司ID
  148. CompanyName string `gorm:"column:company_name" ` // 公司名称
  149. RealName string `gorm:"column:real_name"` // 用户实际名称
  150. BillDetailed int `gorm:"column:bill_detailed;default:0;NOT NULL" json:""` // 流水明细,判断是进账还是出账
  151. ActivityName string `description:"活动标题"`
  152. ChartPermissionId int `description:"行业id"`
  153. ChartPermissionName string `description:"行业名称"`
  154. }
  155. type CygxActivitySpecialPointsBillResp struct {
  156. List []*CygxActivitySpecialPointsBillRespItem
  157. }
  158. func GetCygxActivitySpecialTripBillDetailListAll(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillDetailList, err error) {
  159. o := orm.NewOrmUsingDB("hz_cygx")
  160. sql := `SELECT
  161. b.*,
  162. a.research_theme
  163. FROM
  164. cygx_activity_special_trip_bill AS b
  165. LEFT JOIN cygx_activity_special AS a ON a.activity_id = b.activity_id
  166. WHERE
  167. 1 = 1` + condition
  168. sql += ` ORDER BY b.create_time DESC`
  169. _, err = o.Raw(sql, pars).QueryRows(&item)
  170. return
  171. }
  172. func GetCygxActivitySpecialTripBillByCompanyId(companyId int) (item *CygxActivitySpecialTripBill, err error) {
  173. o := orm.NewOrmUsingDB("hz_cygx")
  174. sql := `SELECT
  175. *
  176. FROM
  177. cygx_activity_special_trip_bill WHERE company_id = ? ORDER BY create_time DESC LIMIT 1
  178. `
  179. err = o.Raw(sql, companyId).QueryRow(&item)
  180. return
  181. }
  182. // GetCygxActivitySpecialTripBillLastDetialByActivityId 根据活动ID获取最后一条扣点明细
  183. func GetCygxActivitySpecialTripBillLastDetialByActivityId(activityId, userId int) (item *CygxActivitySpecialTripBill, err error) {
  184. o := orm.NewOrmUsingDB("hz_cygx")
  185. sql := `SELECT *
  186. FROM
  187. cygx_activity_special_trip_bill
  188. WHERE 1 = 1 AND activity_id =? AND user_id = ? ORDER BY id DESC LIMIT 1 `
  189. err = o.Raw(sql, activityId, userId).QueryRow(&item)
  190. return
  191. }
  192. func GetBestNewBillList() (item []*CygxActivitySpecialTripBillList, err error) {
  193. o := orm.NewOrmUsingDB("hz_cygx")
  194. sql := `SELECT
  195. *
  196. FROM
  197. cygx_activity_special_trip_bill
  198. WHERE
  199. 1 = 1
  200. AND id IN (SELECT
  201. MAX(id) as mid
  202. FROM
  203. cygx_activity_special_trip_bill
  204. WHERE
  205. 1 = 1
  206. GROUP BY
  207. company_id)`
  208. _, err = o.Raw(sql).QueryRows(&item)
  209. return
  210. }