order.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 GetGoodsInfoByActivityVivo(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) {
  83. var err error
  84. defer func() {
  85. if err != nil {
  86. fmt.Println(err)
  87. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2)
  88. }
  89. }()
  90. activityId := item.ActivityId
  91. total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId)
  92. if e != nil {
  93. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  94. return
  95. }
  96. if total == 0 {
  97. goodsListResp = make([]*order.CygxGoodsResp, 0)
  98. return
  99. }
  100. vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
  101. if e != nil {
  102. err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error())
  103. return
  104. }
  105. var condition string
  106. var pars []interface{}
  107. condition = ` AND goods_id IN (9) `
  108. goodsList, e := order.GetCygxGoodsList(condition, pars)
  109. if e != nil {
  110. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  111. return
  112. }
  113. for k, _ := range goodsList {
  114. goodsList[k].CurrentPrice = fmt.Sprint(vivoPointsSetDetail.GoodsMoney)
  115. goodsList[k].Price = fmt.Sprint(vivoPointsSetDetail.GoodsMoney)
  116. goodsList[k].PopupPriceMsg = fmt.Sprint("¥", vivoPointsSetDetail.GoodsMoney)
  117. }
  118. goodsListResp = goodsList
  119. return
  120. }
  121. func GetActivityVivoPoints(item *models.ActivityDetail, wxUser *models.WxUserItem, havePower bool) (vivoPointsResp models.VivoPointsResp) {
  122. if wxUser.UserId == 0 {
  123. return
  124. }
  125. var err error
  126. defer func() {
  127. if err != nil {
  128. fmt.Println(err)
  129. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2)
  130. }
  131. }()
  132. activityId := item.ActivityId
  133. total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId)
  134. if e != nil {
  135. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  136. return
  137. }
  138. if total == 0 {
  139. //如果没有设置就直接播放
  140. vivoPointsResp.HavePoint = true
  141. return
  142. }
  143. totalMySuccess, e := models.GetActivitySignupCount(wxUser.UserId, activityId)
  144. if e != nil {
  145. err = errors.New("GetActivitySignupCount, Err: " + e.Error())
  146. return
  147. }
  148. totalPayVivo, e := order.GetCygxOrderVirtualAssetdCountByVivo(activityId, wxUser.UserId)
  149. if e != nil {
  150. err = errors.New("GetCygxOrderVirtualAssetdCountByVivo, Err: " + e.Error())
  151. return
  152. }
  153. totalPointRecord, e := models.GetCygxActivityVivoPointRecordCount(activityId, wxUser.UserId)
  154. if e != nil {
  155. err = errors.New("GetCygxActivityVivoPointRecordCount, Err: " + e.Error())
  156. return
  157. }
  158. //如果报了名,或者付费了,或者单独扣点了;就直接观看
  159. if totalMySuccess > 0 || totalPayVivo > 0 || totalPointRecord > 0 {
  160. vivoPointsResp.HavePoint = true
  161. }
  162. vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
  163. if e != nil {
  164. err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error())
  165. return
  166. }
  167. vivoPointsResp.ActivityPoints = fmt.Sprint(vivoPointsSetDetail.PointsNum)
  168. // 获取用户所在公司剩余的点
  169. companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId)
  170. if e != nil && e.Error() != utils.ErrNoRow() {
  171. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  172. return
  173. }
  174. vivoPointsResp.CompanyPoints = fmt.Sprint(companyPointsNum)
  175. if havePower {
  176. if companyPointsNum >= vivoPointsSetDetail.PointsNum {
  177. vivoPointsResp.PointPermission = 1
  178. } else {
  179. vivoPointsResp.PointPermission = 2
  180. }
  181. } else {
  182. if vivoPointsSetDetail.GoodsMoney > 0 {
  183. vivoPointsResp.PointPermission = 3
  184. }
  185. }
  186. return
  187. }
  188. // 获取用户十分钟之内是否有相同的订单信息
  189. func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
  190. var err error
  191. defer func() {
  192. if err != nil {
  193. fmt.Println(err)
  194. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
  195. }
  196. }()
  197. var condition string
  198. var pars []interface{}
  199. endTime := time.Now().Add(-10 * time.Minute)
  200. condition = ` AND order_status = 1 AND user_id = ? AND goods_id = ? AND create_time > ? ORDER BY order_id DESC `
  201. pars = append(pars, userId, goodsId, endTime)
  202. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  203. if e != nil && e.Error() != utils.ErrNoRow() {
  204. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  205. return
  206. }
  207. if len(orderList) == 0 {
  208. return
  209. } else {
  210. for _, v := range orderList {
  211. orderCode = v.OrderCode
  212. }
  213. }
  214. return
  215. }
  216. // 获取用户十分钟之内是否有相同的订单信息
  217. func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode string, seconds int) {
  218. var err error
  219. defer func() {
  220. if err != nil {
  221. fmt.Println(err)
  222. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  223. }
  224. }()
  225. var condition string
  226. var pars []interface{}
  227. endTime := time.Now().Add(-10 * time.Minute)
  228. 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 `
  229. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  230. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  231. if e != nil && e.Error() != utils.ErrNoRow() {
  232. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  233. return
  234. }
  235. if len(orderList) == 0 {
  236. return
  237. } else {
  238. for _, v := range orderList {
  239. orderCode = v.OrderCode
  240. duration := time.Now().Sub(v.CreateTime)
  241. // 将时间差转换为秒数
  242. seconds = 600 - int(duration.Seconds())
  243. }
  244. }
  245. return
  246. }
  247. // 获取用户十分钟之内是否有相同的订单信息
  248. func GetHaverEquallyOrderByUser10MinByActivtyVivo(userId, sourceId int) (orderCode string, seconds int) {
  249. var err error
  250. defer func() {
  251. if err != nil {
  252. fmt.Println(err)
  253. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  254. }
  255. }()
  256. var condition string
  257. var pars []interface{}
  258. endTime := time.Now().Add(-10 * time.Minute)
  259. condition = ` AND order_status = 1 AND source IN ( 'activityvideo', 'activityvoice') AND user_id = ? AND source_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC `
  260. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  261. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  262. if e != nil && e.Error() != utils.ErrNoRow() {
  263. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  264. return
  265. }
  266. if len(orderList) == 0 {
  267. return
  268. } else {
  269. for _, v := range orderList {
  270. orderCode = v.OrderCode
  271. duration := time.Now().Sub(v.CreateTime)
  272. // 将时间差转换为秒数
  273. seconds = 600 - int(duration.Seconds())
  274. }
  275. }
  276. return
  277. }
  278. // 获取用户十分钟之内是否有相同的文章订单信息
  279. func GetHaverEquallyOrderByUser10MinByArticle(userId, sourceId, goodsId int) (orderCode string, seconds int) {
  280. var err error
  281. defer func() {
  282. if err != nil {
  283. fmt.Println(err)
  284. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的文章订单信息失败 GetHaverEquallyOrderByUser10MinByArticle, err:", err.Error()), 2)
  285. }
  286. }()
  287. var condition string
  288. var pars []interface{}
  289. endTime := time.Now().Add(-10 * time.Minute)
  290. 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 `
  291. pars = append(pars, userId, sourceId, goodsId, endTime, utils.REGISTER_PLATFORM)
  292. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  293. if e != nil && e.Error() != utils.ErrNoRow() {
  294. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  295. return
  296. }
  297. if len(orderList) == 0 {
  298. return
  299. } else {
  300. for _, v := range orderList {
  301. orderCode = v.OrderCode
  302. duration := time.Now().Sub(v.CreateTime)
  303. // 将时间差转换为秒数
  304. seconds = 600 - int(duration.Seconds())
  305. }
  306. }
  307. return
  308. }
  309. // GetActivityOrderListLabelKeyword 根据活动ID获取活动自定义类型
  310. func GetActivityOrderListLabelKeywordByActivityIds(activityIds []int) (mapResp map[int]string) {
  311. lenArr := len(activityIds)
  312. if lenArr == 0 {
  313. return
  314. }
  315. var err error
  316. defer func() {
  317. if err != nil {
  318. fmt.Println(err)
  319. go utils.SendAlarmMsg("GetActivityOrderListLabelKeywordByActivityIds,根据活动ID获取活动自定义类型 失败Err:"+err.Error(), 2)
  320. }
  321. }()
  322. var condition string
  323. var pars []interface{}
  324. //获取所有研选类型的活动
  325. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  326. pars = append(pars, activityIds)
  327. listActivity, e := models.GetActivityListByCondition(condition, pars)
  328. if e != nil {
  329. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  330. return
  331. }
  332. mapResp = make(map[int]string, 0)
  333. for _, v := range listActivity {
  334. switch v.ActivityTypeId {
  335. case 1:
  336. mapResp[v.ActivityId] = "专家访谈"
  337. case 5:
  338. mapResp[v.ActivityId] = "专家访谈"
  339. case 3:
  340. mapResp[v.ActivityId] = "上市公司小范围"
  341. case 8:
  342. mapResp[v.ActivityId] = "买方交流"
  343. }
  344. }
  345. return
  346. }
  347. // 获取支付之后活动相关的弹窗信息
  348. func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool) {
  349. var err error
  350. defer func() {
  351. if err != nil {
  352. fmt.Println(err)
  353. go utils.SendAlarmMsg(fmt.Sprint("获取支付之后活动相关的弹窗信息失败 GetActivityWechatPayMsg, err:", err.Error(), "activityId:", activityId), 2)
  354. }
  355. }()
  356. activityInfo, e := models.GetAddActivityInfoById(activityId)
  357. if e != nil {
  358. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  359. return
  360. }
  361. if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)是公开活动
  362. isPublicActivitie = true //日卡月卡商品信息
  363. }
  364. var userPointsNum float64
  365. if activityInfo.IsResearchPoints {
  366. //获取活动对用户要扣的点
  367. userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  368. if e != nil {
  369. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  370. return
  371. }
  372. }
  373. //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
  374. if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
  375. return
  376. } else {
  377. isSignUp = true
  378. }
  379. return
  380. }