order.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_web_mfyx/models"
  6. "hongze/hongze_web_mfyx/models/order"
  7. "hongze/hongze_web_mfyx/utils"
  8. "time"
  9. )
  10. // 获取日卡、月卡商品配置信息
  11. func GetUserGoodsCardList() (goodsListResp []*order.CygxGoodsResp) {
  12. var err error
  13. defer func() {
  14. if err != nil {
  15. fmt.Println(err)
  16. go utils.SendAlarmMsg(fmt.Sprint("获取日卡、月卡商品配置信息失败 GetUserGoodsCardList, err:", err.Error()), 2)
  17. }
  18. }()
  19. var condition string
  20. var pars []interface{}
  21. condition = ` AND goods_id IN (1,2) `
  22. goodsList, e := order.GetCygxGoodsList(condition, pars)
  23. if e != nil {
  24. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  25. return
  26. }
  27. goodsListResp = goodsList
  28. return
  29. }
  30. // 获取单场活动关联的商品配置信息
  31. func GetGoodsInfoByActivity(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) {
  32. var err error
  33. defer func() {
  34. if err != nil {
  35. fmt.Println(err)
  36. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2)
  37. }
  38. }()
  39. if item.IsResearchPoints {
  40. //获取活动对用户要扣的点
  41. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(item.ActivityId)
  42. if e != nil {
  43. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  44. return
  45. }
  46. if userPointsNum > 0 {
  47. item.IsResearchPointsByUser = true
  48. }
  49. }
  50. var condition string
  51. var pars []interface{}
  52. if item.ActivityTypeId == 1 && item.IsLimitPeople == 1 { //专家电话会。限制人数,
  53. condition = ` AND goods_id IN (3) `
  54. } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && item.IsResearchPointsByUser { //买方线下交流/专家线下沙龙。参会人扣点,
  55. condition = ` AND goods_id IN (4) `
  56. } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && !item.IsResearchPointsByUser { //买方线下交流/专家线下沙龙。参会人扣点,
  57. condition = ` AND goods_id IN (5) `
  58. } else if item.ActivityTypeId == 3 && item.IsResearchPointsByUser { //非易董。公司调研电话会参会人扣点
  59. condition = ` AND goods_id IN (6) `
  60. } else if item.ActivityTypeId == 3 && !item.IsResearchPointsByUser { //非易董。公司调研电话会参会人扣点
  61. condition = ` AND goods_id IN (7) `
  62. } else if item.ActivityTypeId == 1 && item.IsResearchPointsByUser { //专家电话会,不限制人数,研选扣点(1299元)
  63. condition = ` AND goods_id IN (8) `
  64. }
  65. goodsList, e := order.GetCygxGoodsList(condition, pars)
  66. if e != nil {
  67. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  68. return
  69. }
  70. //如果活动有自定义的价格就优先按照自定义的价格来
  71. if item.ActivityPrice > 0 {
  72. for k, _ := range goodsList {
  73. goodsList[k].CurrentPrice = fmt.Sprint(item.ActivityPrice)
  74. goodsList[k].Price = fmt.Sprint(item.ActivityOriginalPrice)
  75. goodsList[k].PopupPriceMsg = fmt.Sprint("¥", item.ActivityOriginalPrice)
  76. }
  77. }
  78. goodsListResp = goodsList
  79. return
  80. }
  81. // 获取用户十分钟之内是否有相同的订单信息
  82. func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
  83. var err error
  84. defer func() {
  85. if err != nil {
  86. fmt.Println(err)
  87. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
  88. }
  89. }()
  90. var condition string
  91. var pars []interface{}
  92. endTime := time.Now().Add(-10 * time.Minute)
  93. condition = ` AND order_status = 1 AND user_id = ? AND goods_id = ? AND create_time > ? ORDER BY order_id DESC `
  94. pars = append(pars, userId, goodsId, endTime)
  95. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  96. if e != nil && e.Error() != utils.ErrNoRow() {
  97. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  98. return
  99. }
  100. if len(orderList) == 0 {
  101. return
  102. } else {
  103. for _, v := range orderList {
  104. orderCode = v.OrderCode
  105. }
  106. }
  107. return
  108. }
  109. // 获取用户十分钟之内是否有相同的订单信息
  110. func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode string, seconds int) {
  111. var err error
  112. defer func() {
  113. if err != nil {
  114. fmt.Println(err)
  115. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  116. }
  117. }()
  118. var condition string
  119. var pars []interface{}
  120. endTime := time.Now().Add(-10 * time.Minute)
  121. condition = ` AND order_status = 1 AND source = 'activity' AND user_id = ? AND source_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC `
  122. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  123. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  124. if e != nil && e.Error() != utils.ErrNoRow() {
  125. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  126. return
  127. }
  128. if len(orderList) == 0 {
  129. return
  130. } else {
  131. for _, v := range orderList {
  132. orderCode = v.OrderCode
  133. duration := time.Now().Sub(v.CreateTime)
  134. // 将时间差转换为秒数
  135. seconds = 600 - int(duration.Seconds())
  136. }
  137. }
  138. return
  139. }
  140. // 获取用户十分钟之内是否有相同的文章订单信息
  141. func GetHaverEquallyOrderByUser10MinByArticle(userId, sourceId, goodsId int) (orderCode string, seconds int) {
  142. var err error
  143. defer func() {
  144. if err != nil {
  145. fmt.Println(err)
  146. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的文章订单信息失败 GetHaverEquallyOrderByUser10MinByArticle, err:", err.Error()), 2)
  147. }
  148. }()
  149. var condition string
  150. var pars []interface{}
  151. endTime := time.Now().Add(-10 * time.Minute)
  152. condition = ` AND order_status = 1 AND user_id = ? AND source_id = ? AND goods_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC `
  153. pars = append(pars, userId, sourceId, goodsId, endTime, utils.REGISTER_PLATFORM)
  154. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  155. if e != nil && e.Error() != utils.ErrNoRow() {
  156. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  157. return
  158. }
  159. if len(orderList) == 0 {
  160. return
  161. } else {
  162. for _, v := range orderList {
  163. orderCode = v.OrderCode
  164. duration := time.Now().Sub(v.CreateTime)
  165. // 将时间差转换为秒数
  166. seconds = 600 - int(duration.Seconds())
  167. }
  168. }
  169. return
  170. }
  171. // GetActivityOrderListLabelKeyword 根据活动ID获取活动自定义类型
  172. func GetActivityOrderListLabelKeywordByActivityIds(activityIds []int) (mapResp map[int]string) {
  173. lenArr := len(activityIds)
  174. if lenArr == 0 {
  175. return
  176. }
  177. var err error
  178. defer func() {
  179. if err != nil {
  180. fmt.Println(err)
  181. go utils.SendAlarmMsg("GetActivityOrderListLabelKeywordByActivityIds,根据活动ID获取活动自定义类型 失败Err:"+err.Error(), 2)
  182. }
  183. }()
  184. var condition string
  185. var pars []interface{}
  186. //获取所有研选类型的活动
  187. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  188. pars = append(pars, activityIds)
  189. listActivity, e := models.GetActivityListByCondition(condition, pars)
  190. if e != nil {
  191. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  192. return
  193. }
  194. mapResp = make(map[int]string, 0)
  195. for _, v := range listActivity {
  196. switch v.ActivityTypeId {
  197. case 1:
  198. mapResp[v.ActivityId] = "专家访谈"
  199. case 5:
  200. mapResp[v.ActivityId] = "专家访谈"
  201. case 3:
  202. mapResp[v.ActivityId] = "上市公司小范围"
  203. case 8:
  204. mapResp[v.ActivityId] = "买方交流"
  205. }
  206. }
  207. return
  208. }
  209. // 获取支付之后活动相关的弹窗信息
  210. func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool) {
  211. var err error
  212. defer func() {
  213. if err != nil {
  214. fmt.Println(err)
  215. go utils.SendAlarmMsg(fmt.Sprint("获取支付之后活动相关的弹窗信息失败 GetActivityWechatPayMsg, err:", err.Error(), "activityId:", activityId), 2)
  216. }
  217. }()
  218. activityInfo, e := models.GetAddActivityInfoById(activityId)
  219. if e != nil {
  220. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  221. return
  222. }
  223. if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)是公开活动
  224. isPublicActivitie = true //日卡月卡商品信息
  225. }
  226. var userPointsNum float64
  227. if activityInfo.IsResearchPoints {
  228. //获取活动对用户要扣的点
  229. userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  230. if e != nil {
  231. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  232. return
  233. }
  234. }
  235. //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
  236. if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
  237. return
  238. } else {
  239. isSignUp = true
  240. }
  241. return
  242. }