order.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. havePowerYx, e := GetArticleDetailUserPower(wxUser)
  176. if e != nil {
  177. err = errors.New("GetArticleDetailUserPower, Err: " + e.Error())
  178. return
  179. }
  180. if havePower || havePowerYx {
  181. if vivoPointsSetDetail.PointsNum == 0 { //有权限情况下,点数为零的时候直接播放
  182. vivoPointsResp.HavePoint = true
  183. }
  184. if companyPointsNum > 0 {
  185. if companyPointsNum >= vivoPointsSetDetail.PointsNum {
  186. vivoPointsResp.PointPermission = 1
  187. } else {
  188. vivoPointsResp.PointPermission = 2
  189. }
  190. } else {
  191. //客户剩余点数为0的情况下,直接支付
  192. vivoPointsResp.PointPermission = 3
  193. }
  194. } else {
  195. if vivoPointsSetDetail.GoodsMoney > 0 {
  196. vivoPointsResp.PointPermission = 3
  197. }
  198. }
  199. return
  200. }
  201. // 获取用户十分钟之内是否有相同的订单信息
  202. func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
  203. var err error
  204. defer func() {
  205. if err != nil {
  206. fmt.Println(err)
  207. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
  208. }
  209. }()
  210. var condition string
  211. var pars []interface{}
  212. endTime := time.Now().Add(-10 * time.Minute)
  213. condition = ` AND order_status = 1 AND user_id = ? AND goods_id = ? AND create_time > ? ORDER BY order_id DESC `
  214. pars = append(pars, userId, goodsId, endTime)
  215. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  216. if e != nil && e.Error() != utils.ErrNoRow() {
  217. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  218. return
  219. }
  220. if len(orderList) == 0 {
  221. return
  222. } else {
  223. for _, v := range orderList {
  224. orderCode = v.OrderCode
  225. }
  226. }
  227. return
  228. }
  229. // 获取用户十分钟之内是否有相同的订单信息
  230. func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode string, seconds int) {
  231. var err error
  232. defer func() {
  233. if err != nil {
  234. fmt.Println(err)
  235. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  236. }
  237. }()
  238. var condition string
  239. var pars []interface{}
  240. endTime := time.Now().Add(-10 * time.Minute)
  241. 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 `
  242. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  243. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  244. if e != nil && e.Error() != utils.ErrNoRow() {
  245. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  246. return
  247. }
  248. if len(orderList) == 0 {
  249. return
  250. } else {
  251. for _, v := range orderList {
  252. orderCode = v.OrderCode
  253. duration := time.Now().Sub(v.CreateTime)
  254. // 将时间差转换为秒数
  255. seconds = 600 - int(duration.Seconds())
  256. }
  257. }
  258. return
  259. }
  260. // 获取用户十分钟之内是否有相同的订单信息
  261. func GetHaverEquallyOrderByUser10MinByActivtyVivo(userId, sourceId int) (orderCode string, seconds int) {
  262. var err error
  263. defer func() {
  264. if err != nil {
  265. fmt.Println(err)
  266. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  267. }
  268. }()
  269. var condition string
  270. var pars []interface{}
  271. endTime := time.Now().Add(-10 * time.Minute)
  272. 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 `
  273. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  274. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  275. if e != nil && e.Error() != utils.ErrNoRow() {
  276. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  277. return
  278. }
  279. if len(orderList) == 0 {
  280. return
  281. } else {
  282. for _, v := range orderList {
  283. orderCode = v.OrderCode
  284. duration := time.Now().Sub(v.CreateTime)
  285. // 将时间差转换为秒数
  286. seconds = 600 - int(duration.Seconds())
  287. }
  288. }
  289. return
  290. }
  291. // 获取用户十分钟之内是否有相同的文章订单信息
  292. func GetHaverEquallyOrderByUser10MinByArticle(userId, sourceId, goodsId int) (orderCode string, seconds int) {
  293. var err error
  294. defer func() {
  295. if err != nil {
  296. fmt.Println(err)
  297. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的文章订单信息失败 GetHaverEquallyOrderByUser10MinByArticle, err:", err.Error()), 2)
  298. }
  299. }()
  300. var condition string
  301. var pars []interface{}
  302. endTime := time.Now().Add(-10 * time.Minute)
  303. 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 `
  304. pars = append(pars, userId, sourceId, goodsId, endTime, utils.REGISTER_PLATFORM)
  305. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  306. if e != nil && e.Error() != utils.ErrNoRow() {
  307. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  308. return
  309. }
  310. if len(orderList) == 0 {
  311. return
  312. } else {
  313. for _, v := range orderList {
  314. orderCode = v.OrderCode
  315. duration := time.Now().Sub(v.CreateTime)
  316. // 将时间差转换为秒数
  317. seconds = 600 - int(duration.Seconds())
  318. }
  319. }
  320. return
  321. }
  322. // GetActivityOrderListLabelKeyword 根据活动ID获取活动自定义类型
  323. func GetActivityOrderListLabelKeywordByActivityIds(activityIds []int) (mapResp map[int]string) {
  324. lenArr := len(activityIds)
  325. if lenArr == 0 {
  326. return
  327. }
  328. var err error
  329. defer func() {
  330. if err != nil {
  331. fmt.Println(err)
  332. go utils.SendAlarmMsg("GetActivityOrderListLabelKeywordByActivityIds,根据活动ID获取活动自定义类型 失败Err:"+err.Error(), 2)
  333. }
  334. }()
  335. var condition string
  336. var pars []interface{}
  337. //获取所有研选类型的活动
  338. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  339. pars = append(pars, activityIds)
  340. listActivity, e := models.GetActivityListByCondition(condition, pars)
  341. if e != nil {
  342. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  343. return
  344. }
  345. mapResp = make(map[int]string, 0)
  346. for _, v := range listActivity {
  347. switch v.ActivityTypeId {
  348. case 1:
  349. mapResp[v.ActivityId] = "专家访谈"
  350. case 5:
  351. mapResp[v.ActivityId] = "专家访谈"
  352. case 3:
  353. mapResp[v.ActivityId] = "上市公司小范围"
  354. case 8:
  355. mapResp[v.ActivityId] = "买方交流"
  356. }
  357. }
  358. return
  359. }
  360. // 获取支付之后活动相关的弹窗信息
  361. func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool) {
  362. var err error
  363. defer func() {
  364. if err != nil {
  365. fmt.Println(err)
  366. go utils.SendAlarmMsg(fmt.Sprint("获取支付之后活动相关的弹窗信息失败 GetActivityWechatPayMsg, err:", err.Error(), "activityId:", activityId), 2)
  367. }
  368. }()
  369. activityInfo, e := models.GetAddActivityInfoById(activityId)
  370. if e != nil {
  371. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  372. return
  373. }
  374. if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)是公开活动
  375. isPublicActivitie = true //日卡月卡商品信息
  376. }
  377. var userPointsNum float64
  378. if activityInfo.IsResearchPoints {
  379. //获取活动对用户要扣的点
  380. userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  381. if e != nil {
  382. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  383. return
  384. }
  385. }
  386. //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
  387. if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
  388. return
  389. } else {
  390. isSignUp = true
  391. }
  392. return
  393. }