order.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_mfyx/models"
  7. "hongze/hongze_mfyx/models/order"
  8. "hongze/hongze_mfyx/utils"
  9. "time"
  10. )
  11. // 获取日卡、月卡商品配置信息
  12. func GetUserGoodsCardList() (goodsListResp []*order.CygxGoodsResp) {
  13. var err error
  14. defer func() {
  15. if err != nil {
  16. fmt.Println(err)
  17. go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetCygxGoodsList, err:", err.Error()), 2)
  18. }
  19. }()
  20. var condition string
  21. var pars []interface{}
  22. condition = ` AND goods_id IN (1,2) `
  23. goodsList, e := order.GetCygxGoodsList(condition, pars)
  24. if e != nil {
  25. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  26. return
  27. }
  28. goodsListResp = goodsList
  29. return
  30. }
  31. // 获取单场活动关联的商品配置信息
  32. func GetGoodsInfoByActivity(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) {
  33. var err error
  34. defer func() {
  35. if err != nil {
  36. fmt.Println(err)
  37. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息 GetGoodsInfoByActivity, err:", err.Error()), 2)
  38. }
  39. }()
  40. if item.IsResearchPoints {
  41. //获取活动对用户要扣的点
  42. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(item.ActivityId)
  43. if e != nil {
  44. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  45. return
  46. }
  47. if userPointsNum > 0 {
  48. item.IsResearchPointsByUser = true
  49. }
  50. }
  51. var condition string
  52. var pars []interface{}
  53. if item.ActivityTypeId == 1 && item.IsLimitPeople == 1 { //专家电话会。限制人数,
  54. condition = ` AND goods_id IN (3) `
  55. } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && item.IsResearchPoints { //买方线下交流/专家线下沙龙。参会人扣点,
  56. condition = ` AND goods_id IN (4) `
  57. } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && !item.IsResearchPoints { //买方线下交流/专家线下沙龙。参会人扣点,
  58. condition = ` AND goods_id IN (5) `
  59. } else if item.ActivityTypeId == 3 && item.IsResearchPoints { //非易董。公司调研电话会参会人扣点
  60. condition = ` AND goods_id IN (6) `
  61. } else if item.ActivityTypeId == 3 && !item.IsResearchPoints { //非易董。公司调研电话会参会人扣点
  62. condition = ` AND goods_id IN (7) `
  63. } else if item.ActivityTypeId == 1 && item.IsResearchPoints { //专家电话会,不限制人数,研选扣点(1299元)
  64. condition = ` AND goods_id IN (8) `
  65. }
  66. goodsList, e := order.GetCygxGoodsList(condition, pars)
  67. if e != nil {
  68. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  69. return
  70. }
  71. //如果活动有自定义的价格就优先按照自定义的价格来
  72. if item.ActivityPrice > 0 {
  73. for k, _ := range goodsList {
  74. goodsList[k].CurrentPrice = fmt.Sprint(item.ActivityPrice)
  75. goodsList[k].Price = fmt.Sprint(item.ActivityOriginalPrice)
  76. goodsList[k].PopupPriceMsg = fmt.Sprint("¥", item.ActivityOriginalPrice)
  77. }
  78. }
  79. goodsListResp = goodsList
  80. return
  81. }
  82. // 获取单场活动音视频关联的商品配置信息
  83. func GetGoodsInfoByActivityVivo(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) {
  84. var err error
  85. defer func() {
  86. if err != nil {
  87. fmt.Println(err)
  88. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2)
  89. }
  90. }()
  91. activityId := item.ActivityId
  92. total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId)
  93. if e != nil {
  94. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  95. return
  96. }
  97. if total == 0 {
  98. goodsListResp = make([]*order.CygxGoodsResp, 0)
  99. return
  100. }
  101. vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
  102. if e != nil {
  103. err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error())
  104. return
  105. }
  106. var condition string
  107. var pars []interface{}
  108. condition = ` AND goods_id IN (9) `
  109. goodsList, e := order.GetCygxGoodsList(condition, pars)
  110. if e != nil {
  111. err = errors.New("GetCygxGoodsList, Err: " + e.Error())
  112. return
  113. }
  114. for k, _ := range goodsList {
  115. goodsList[k].CurrentPrice = fmt.Sprint(vivoPointsSetDetail.GoodsMoney)
  116. goodsList[k].Price = fmt.Sprint(vivoPointsSetDetail.GoodsMoney)
  117. goodsList[k].PopupPriceMsg = fmt.Sprint("¥", vivoPointsSetDetail.GoodsMoney)
  118. }
  119. goodsListResp = goodsList
  120. return
  121. }
  122. func GetActivityVivoPoints(item *models.ActivityDetail, wxUser *models.WxUserItem, havePower bool) (vivoPointsResp models.VivoPointsResp) {
  123. var err error
  124. defer func() {
  125. if err != nil {
  126. fmt.Println(err)
  127. go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2)
  128. }
  129. }()
  130. activityId := item.ActivityId
  131. total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId)
  132. if e != nil {
  133. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  134. return
  135. }
  136. if total == 0 {
  137. //如果没有设置就直接播放
  138. vivoPointsResp.HavePoint = true
  139. return
  140. }
  141. totalMySuccess, e := models.GetActivitySignupCount(wxUser.UserId, activityId)
  142. if e != nil {
  143. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  144. return
  145. }
  146. totalPayVivo, e := order.GetCygxOrderVirtualAssetdCountByVivo(activityId, wxUser.UserId)
  147. if e != nil {
  148. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  149. return
  150. }
  151. totalPointRecord, e := models.GetCygxActivityVivoPointRecordCount(activityId, wxUser.UserId)
  152. if e != nil {
  153. err = errors.New("GetCygxActivityVivoPointRecordCount, Err: " + e.Error())
  154. return
  155. }
  156. //如果报了名,或者付费了,或者单独扣点了;就直接观看
  157. if totalMySuccess > 0 || totalPayVivo > 0 || totalPointRecord > 0 {
  158. vivoPointsResp.HavePoint = true
  159. }
  160. vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
  161. if e != nil {
  162. err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error())
  163. return
  164. }
  165. vivoPointsResp.ActivityPoints = fmt.Sprint(vivoPointsSetDetail.PointsNum)
  166. // 获取用户所在公司剩余的点
  167. companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId)
  168. if e != nil && e.Error() != utils.ErrNoRow() {
  169. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  170. return
  171. }
  172. vivoPointsResp.CompanyPoints = fmt.Sprint(companyPointsNum)
  173. havePowerYx, e := GetArticleDetailUserPower(wxUser)
  174. if e != nil {
  175. err = errors.New("GetArticleDetailUserPower, Err: " + e.Error())
  176. return
  177. }
  178. if havePower || havePowerYx {
  179. if vivoPointsSetDetail.PointsNum == 0 { //有权限情况下,点数为零的时候直接播放
  180. vivoPointsResp.HavePoint = true
  181. }
  182. if companyPointsNum > 0 {
  183. if companyPointsNum >= vivoPointsSetDetail.PointsNum {
  184. vivoPointsResp.PointPermission = 1
  185. } else {
  186. vivoPointsResp.PointPermission = 2
  187. }
  188. } else {
  189. //客户剩余点数为0的情况下,直接支付
  190. vivoPointsResp.PointPermission = 3
  191. }
  192. } else {
  193. if vivoPointsSetDetail.GoodsMoney > 0 {
  194. vivoPointsResp.PointPermission = 3
  195. }
  196. }
  197. return
  198. }
  199. // 获取用户十分钟之内是否有相同的订单信息
  200. func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
  201. var err error
  202. defer func() {
  203. if err != nil {
  204. fmt.Println(err)
  205. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
  206. }
  207. }()
  208. var condition string
  209. var pars []interface{}
  210. endTime := time.Now().Add(-10 * time.Minute)
  211. condition = ` AND order_status = 1 AND user_id = ? AND goods_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC `
  212. pars = append(pars, userId, goodsId, endTime, utils.REGISTER_PLATFORM)
  213. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  214. if e != nil && e.Error() != utils.ErrNoRow() {
  215. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  216. return
  217. }
  218. if len(orderList) == 0 {
  219. return
  220. } else {
  221. for _, v := range orderList {
  222. orderCode = v.OrderCode
  223. }
  224. }
  225. return
  226. }
  227. // 获取用户十分钟之内是否有相同的订单信息
  228. func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode string, seconds int) {
  229. var err error
  230. defer func() {
  231. if err != nil {
  232. fmt.Println(err)
  233. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
  234. }
  235. }()
  236. var condition string
  237. var pars []interface{}
  238. endTime := time.Now().Add(-10 * time.Minute)
  239. 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 `
  240. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  241. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  242. if e != nil && e.Error() != utils.ErrNoRow() {
  243. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  244. return
  245. }
  246. if len(orderList) == 0 {
  247. return
  248. } else {
  249. for _, v := range orderList {
  250. orderCode = v.OrderCode
  251. duration := time.Now().Sub(v.CreateTime)
  252. // 将时间差转换为秒数
  253. seconds = 600 - int(duration.Seconds())
  254. }
  255. }
  256. return
  257. }
  258. // 处理支付订单回调
  259. func HandleOrderByWechatPay(itemCallback *WechatPayCallback) {
  260. var err error
  261. defer func() {
  262. if err != nil {
  263. fmt.Println(err)
  264. go utils.SendAlarmMsg(fmt.Sprint("处理订单回调信息失败 HandleOrderByWechatPay, err:", err.Error()), 2)
  265. }
  266. }()
  267. outTradeNo := itemCallback.OutTradeNo
  268. orderDetail, e := order.GetCygxOrderDetailByOutTradeNo(outTradeNo)
  269. if e != nil {
  270. err = errors.New("GetCygxOrderDetailByOrderCode, Err: " + e.Error())
  271. return
  272. }
  273. //修改过状态的不再二次处理
  274. if orderDetail.OrderStatus == 2 {
  275. return
  276. }
  277. tradeState, _, _ := GetQueryOrderByOutTradeNo(outTradeNo) //主动查询微信支付信息
  278. if tradeState != "SUCCESS" {
  279. return
  280. }
  281. go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
  282. if itemCallback.TradeState != "SUCCESS" { // 回调显示支付不成功,模版消息推送
  283. if e != nil {
  284. err = errors.New("支付失败, OutTradeNo: " + outTradeNo)
  285. return
  286. }
  287. }
  288. itemOrder := new(order.CygxOrder)
  289. itemOrder.OrderCode = orderDetail.OrderCode
  290. itemOrder.PayTime = itemCallback.SuccessTime
  291. itemOrder.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
  292. itemOrder.OrderStatus = 2
  293. itemOrder.OutTradeCode = itemCallback.TransactionID
  294. itemOrder.TradeType = itemCallback.TradeType
  295. //文章处理逻辑 OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  296. if orderDetail.OrderType == 1 {
  297. itemUserCard := new(order.CygxOrderUserCard)
  298. itemUserCard.OrderCode = orderDetail.OrderCode
  299. itemUserCard.UserId = orderDetail.UserId
  300. itemUserCard.Mobile = orderDetail.Mobile
  301. itemUserCard.Email = orderDetail.Email
  302. itemUserCard.CompanyId = orderDetail.CompanyId
  303. itemUserCard.CompanyName = orderDetail.CompanyName
  304. itemUserCard.RealName = orderDetail.RealName
  305. itemUserCard.SellerName = orderDetail.SellerName
  306. itemUserCard.CreateTime = time.Now()
  307. itemUserCard.ModifyTime = time.Now()
  308. itemUserCard.RegisterPlatform = orderDetail.RegisterPlatform
  309. if orderDetail.GoodsId == 1 {
  310. itemUserCard.StartDate = itemOrder.PayTime
  311. itemUserCard.EndDate = itemOrder.PayTime.AddDate(0, 0, 1)
  312. itemUserCard.CardType = "日卡"
  313. } else {
  314. now := time.Now()
  315. itemUserCard.StartDate = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
  316. itemUserCard.EndDate = itemUserCard.StartDate.AddDate(0, 1, 0)
  317. itemUserCard.CardType = "月卡"
  318. }
  319. e = order.AddCygxOrderUserCard(itemUserCard, itemOrder)
  320. if e != nil {
  321. err = errors.New("AddCygxOrderUserCard, Err: " + e.Error())
  322. return
  323. }
  324. } else if orderDetail.OrderType == 2 || orderDetail.OrderType == 3 {
  325. //如果是活动,把单场付费信息的活动写入 用户虚拟资产表
  326. itemOrderVirtualAsset := new(order.CygxOrderVirtualAsset)
  327. itemOrderVirtualAsset.OrderCode = orderDetail.OrderCode
  328. itemOrderVirtualAsset.UserId = orderDetail.UserId
  329. itemOrderVirtualAsset.Mobile = orderDetail.Mobile
  330. itemOrderVirtualAsset.Email = orderDetail.Email
  331. itemOrderVirtualAsset.CompanyId = orderDetail.CompanyId
  332. itemOrderVirtualAsset.CompanyName = orderDetail.CompanyName
  333. itemOrderVirtualAsset.RealName = orderDetail.RealName
  334. itemOrderVirtualAsset.SellerName = orderDetail.SellerName
  335. itemOrderVirtualAsset.Source = orderDetail.Source
  336. itemOrderVirtualAsset.SourceId = orderDetail.SourceId
  337. itemOrderVirtualAsset.CreateTime = time.Now()
  338. itemOrderVirtualAsset.ModifyTime = time.Now()
  339. e = order.AddCygxOrderVirtualAsset(itemOrderVirtualAsset, itemOrder)
  340. if e != nil {
  341. err = errors.New("AddCygxOrderVirtualAsset, Err: " + e.Error())
  342. return
  343. }
  344. }
  345. if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
  346. go AddActivitySignupByWechatPay(orderDetail.SourceId, orderDetail.UserId) //微信付款成功自动添加报名
  347. }
  348. go CancelOtherOrder(orderDetail) //付款成功之后自动取消其他相同的订单
  349. go SendWxCategoryMsgWxPay(orderDetail) //有人支付成功时,模板消息发送给王芳、沈涛和推荐人(没有推荐人时给销售)
  350. return
  351. }
  352. func AddCygxOrderPayment(itemCallback *WechatPayCallback) {
  353. var err error
  354. defer func() {
  355. if err != nil {
  356. fmt.Println(err)
  357. go utils.SendAlarmMsg(fmt.Sprint("处理订单回调信息失败 HandleOrderHandle, err:", err.Error()), 2)
  358. }
  359. }()
  360. itemPay := new(order.CygxOrderPayment)
  361. itemPay.OrderCode = itemCallback.OutTradeNo
  362. itemPay.OutTradeCode = itemCallback.TransactionID
  363. itemPay.PayBody = itemCallback.TradeStateDesc
  364. jsonData, _ := json.Marshal(itemCallback)
  365. itemPay.PayDetail = string(jsonData)
  366. itemPay.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
  367. itemPay.PayStatus = itemCallback.TradeState
  368. itemPay.CreateTime = time.Now()
  369. itemPay.PaymentType = 1
  370. e := order.AddCygxOrderPayment(itemPay)
  371. if e != nil {
  372. err = errors.New("AddCygxOrderPayment, Err: " + e.Error())
  373. return
  374. }
  375. return
  376. }
  377. // 获取用户十分钟之内是否有相同的订单信息
  378. func GetHaverEquallyOrderByUser10MinByActivtyVivo(userId, sourceId int) (orderCode string, seconds int) {
  379. var err error
  380. defer func() {
  381. if err != nil {
  382. fmt.Println(err)
  383. go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2)
  384. }
  385. }()
  386. var condition string
  387. var pars []interface{}
  388. endTime := time.Now().Add(-10 * time.Minute)
  389. 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 `
  390. pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM)
  391. orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
  392. if e != nil && e.Error() != utils.ErrNoRow() {
  393. err = errors.New("GetCygxOrderList, Err: " + e.Error())
  394. return
  395. }
  396. if len(orderList) == 0 {
  397. return
  398. } else {
  399. for _, v := range orderList {
  400. orderCode = v.OrderCode
  401. duration := time.Now().Sub(v.CreateTime)
  402. // 将时间差转换为秒数
  403. seconds = 600 - int(duration.Seconds())
  404. }
  405. }
  406. return
  407. }
  408. // 处理退款订单回调
  409. func HandleOrderRefundByWechatPay(itemCallback *WechatPayCallback) {
  410. var err error
  411. defer func() {
  412. if err != nil {
  413. fmt.Println(err)
  414. go utils.SendAlarmMsg(fmt.Sprint("处理退款订单回调信息失败 HandleOrderRefundByWechatPay, err:", err.Error()), 2)
  415. }
  416. }()
  417. outTradeNo := itemCallback.OutTradeNo
  418. orderDetail, e := order.GetCygxOrderDetailByOutTradeNo(outTradeNo)
  419. if e != nil {
  420. err = errors.New("GetCygxOrderDetailByOrderCode, Err: " + e.Error())
  421. return
  422. }
  423. //go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
  424. //修改过状态的不再二次处理
  425. if orderDetail.OrderStatus == 3 {
  426. return
  427. }
  428. itemOrder := new(order.CygxOrder)
  429. itemOrder.OrderCode = orderDetail.OrderCode
  430. itemOrder.RefundTime = itemCallback.SuccessTime
  431. itemOrder.RefundMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
  432. itemOrder.OrderStatus = 3
  433. //文章处理逻辑 OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  434. if orderDetail.OrderType == 1 {
  435. itemUserCard := new(order.CygxOrderUserCard)
  436. itemUserCard.OrderCode = orderDetail.OrderCode
  437. itemUserCard.UserId = orderDetail.UserId
  438. itemUserCard.Mobile = orderDetail.Mobile
  439. itemUserCard.Email = orderDetail.Email
  440. itemUserCard.CompanyId = orderDetail.CompanyId
  441. itemUserCard.CompanyName = orderDetail.CompanyName
  442. itemUserCard.RealName = orderDetail.RealName
  443. itemUserCard.SellerName = orderDetail.SellerName
  444. itemUserCard.CreateTime = time.Now()
  445. itemUserCard.ModifyTime = time.Now()
  446. itemUserCard.RegisterPlatform = orderDetail.RegisterPlatform
  447. if orderDetail.GoodsId == 1 {
  448. itemUserCard.CardType = "日卡"
  449. } else {
  450. itemUserCard.CardType = "月卡"
  451. }
  452. e = order.RemoveCygxOrderUserCard(itemUserCard, itemOrder) // 移除用户
  453. if e != nil {
  454. err = errors.New("RemoveCygxOrderUserCard, Err: " + e.Error())
  455. return
  456. }
  457. } else if orderDetail.OrderType == 2 || orderDetail.OrderType == 3 {
  458. //如果是活动,把单场付费信息的活动写入 用户虚拟资产表
  459. itemOrderVirtualAsset := new(order.CygxOrderVirtualAsset)
  460. itemOrderVirtualAsset.OrderCode = orderDetail.OrderCode
  461. itemOrderVirtualAsset.UserId = orderDetail.UserId
  462. itemOrderVirtualAsset.Mobile = orderDetail.Mobile
  463. itemOrderVirtualAsset.Email = orderDetail.Email
  464. itemOrderVirtualAsset.CompanyId = orderDetail.CompanyId
  465. itemOrderVirtualAsset.CompanyName = orderDetail.CompanyName
  466. itemOrderVirtualAsset.RealName = orderDetail.RealName
  467. itemOrderVirtualAsset.SellerName = orderDetail.SellerName
  468. itemOrderVirtualAsset.Source = orderDetail.Source
  469. itemOrderVirtualAsset.SourceId = orderDetail.SourceId
  470. itemOrderVirtualAsset.CreateTime = time.Now()
  471. itemOrderVirtualAsset.ModifyTime = time.Now()
  472. e = order.RemoveCygxOrderVirtualAsset(itemOrderVirtualAsset, itemOrder)
  473. if e != nil {
  474. err = errors.New("AddCygxOrderVirtualAsset, Err: " + e.Error())
  475. return
  476. }
  477. }
  478. //if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
  479. // go CancelActivitySignupByWechatPay(orderDetail.SourceId, orderDetail.UserId) //微信退款成功自动取消报名
  480. //}
  481. return
  482. }
  483. // 微信付款成功自动添加报名
  484. func AddActivitySignupByWechatPay(activityId, userId int) {
  485. var err error
  486. defer func() {
  487. if err != nil {
  488. fmt.Println(err)
  489. go utils.SendAlarmMsg(fmt.Sprint("微信付款成功自动添加报名失败 AddActivitySignupByWechatPay, err:", err.Error(), "activityId:", activityId, "userId:", userId), 2)
  490. }
  491. }()
  492. activityInfo, e := models.GetAddActivityInfoById(activityId)
  493. if e != nil {
  494. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  495. return
  496. }
  497. var userPointsNum float64
  498. if activityInfo.IsResearchPoints {
  499. //获取活动对用户要扣的点
  500. userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  501. if e != nil {
  502. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  503. return
  504. }
  505. }
  506. //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
  507. if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
  508. return
  509. }
  510. user, e := models.GetWxUserItemByUserId(userId)
  511. if e != nil {
  512. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  513. return
  514. }
  515. var sellerName string
  516. sellerName, e = models.GetCompanySellerName(user.CompanyId)
  517. if e != nil {
  518. err = errors.New("GetCompanySellerName, Err: " + e.Error())
  519. return
  520. }
  521. item := new(models.CygxActivitySignup)
  522. totalMySuccess, e := models.GetActivitySignupCount(userId, activityId)
  523. if e != nil {
  524. err = errors.New("AddActivitySignup, Err: " + e.Error())
  525. return
  526. }
  527. if totalMySuccess > 0 { //已报名这个活动
  528. return
  529. }
  530. item.UserId = userId
  531. item.RealName = user.RealName
  532. item.SellerName = sellerName
  533. item.ActivityId = activityId
  534. item.CreateTime = time.Now()
  535. item.Mobile = user.Mobile
  536. item.Email = user.Email
  537. item.CompanyId = user.CompanyId
  538. item.CompanyName = user.CompanyName
  539. item.SignupType = 3
  540. item.FailType = 0
  541. item.DoFailType = 0
  542. item.OutboundMobile = user.Mobile
  543. if user.OutboundMobile != "" {
  544. item.OutboundMobile = user.OutboundMobile
  545. if user.OutboundCountryCode == "" {
  546. item.CountryCode = "86"
  547. } else {
  548. item.CountryCode = user.OutboundCountryCode
  549. }
  550. } else {
  551. item.OutboundMobile = user.Mobile
  552. if user.CountryCode == "" {
  553. item.CountryCode = "86"
  554. } else {
  555. item.CountryCode = user.CountryCode
  556. }
  557. }
  558. _, e = models.AddActivitySignup(item)
  559. if e != nil {
  560. err = errors.New("AddActivitySignup, Err: " + e.Error())
  561. return
  562. }
  563. fmt.Println("报名成功")
  564. go ActivityUserRemind(user, activityInfo, 4)
  565. return
  566. }
  567. // 微信退款成功自动取消报名
  568. func CancelActivitySignupByWechatPay(activityId, userId int) {
  569. var err error
  570. defer func() {
  571. if err != nil {
  572. fmt.Println(err)
  573. go utils.SendAlarmMsg(fmt.Sprint("微信退款成功自动取消报名失败 CancelActivitySignupByWechatPay, err:", err.Error(), "activityId:", activityId, "userId:", userId), 2)
  574. }
  575. }()
  576. activityInfo, e := models.GetAddActivityInfoById(activityId)
  577. if e != nil {
  578. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  579. return
  580. }
  581. user, e := models.GetWxUserItemByUserId(userId)
  582. if e != nil {
  583. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  584. return
  585. }
  586. item := new(models.CygxActivitySignup)
  587. item.UserId = userId
  588. item.ActivityId = activityId
  589. item.CreateTime = time.Now()
  590. item.Mobile = user.Mobile
  591. item.Email = user.Email
  592. item.CompanyId = user.CompanyId
  593. item.CompanyName = user.CompanyName
  594. resp := new(models.SignupStatus)
  595. resp.ActivityId = activityId
  596. _, e = models.CancelActivitySignup(item)
  597. if e != nil {
  598. err = errors.New("CancelActivitySignup, Err: " + e.Error())
  599. return
  600. }
  601. // 如果是买方研选下的专家沙龙,同时推给内容组四人
  602. if activityInfo.ActivityTypeId == 5 {
  603. go SendActivitieCancelSignTemplateMsg(user, activityInfo)
  604. }
  605. go SendResearchActivitiesTemplateMsg(user, activityInfo, "取消报名") //公司线下调研活动客户报名后给建会人,所属销售推送模板信息
  606. return
  607. }
  608. // 获取支付之后活动相关的弹窗信息
  609. func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool) {
  610. var err error
  611. defer func() {
  612. if err != nil {
  613. fmt.Println(err)
  614. go utils.SendAlarmMsg(fmt.Sprint("获取支付之后活动相关的弹窗信息失败 GetActivityWechatPayMsg, err:", err.Error(), "activityId:", activityId), 2)
  615. }
  616. }()
  617. activityInfo, e := models.GetAddActivityInfoById(activityId)
  618. if e != nil {
  619. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  620. return
  621. }
  622. if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)是公开活动
  623. isPublicActivitie = true //日卡月卡商品信息
  624. }
  625. var userPointsNum float64
  626. if activityInfo.IsResearchPoints {
  627. //获取活动对用户要扣的点
  628. userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  629. if e != nil {
  630. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  631. return
  632. }
  633. }
  634. //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
  635. if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
  636. return
  637. } else {
  638. isSignUp = true
  639. }
  640. return
  641. }
  642. // 付款成功之后自动取消其他相同的订单
  643. func CancelOtherOrder(item *order.CygxOrder) {
  644. var err error
  645. defer func() {
  646. if err != nil {
  647. fmt.Println(err)
  648. go utils.SendAlarmMsg(fmt.Sprint("付款成功之后自动取消其他相同的订单失败 CancelOtherOrder, err:", err.Error(), "order_id:", item.OrderId), 2)
  649. }
  650. }()
  651. var condition string
  652. var pars []interface{}
  653. userId := item.UserId
  654. //判断是日卡月卡还是单场付费活动
  655. if item.GoodsId == 1 || item.GoodsId == 2 {
  656. condition += ` AND user_id = ? AND goods_id IN (1,2) AND order_id != ? AND order_status = 1 `
  657. pars = append(pars, userId, item.OrderId)
  658. } else {
  659. condition += ` AND user_id = ? AND source_id = ? AND source = ? AND order_id != ? AND order_status = 1 `
  660. pars = append(pars, userId, item.SourceId, item.Source, item.OrderId)
  661. }
  662. listOrder, e := order.GetCygxOrderDetailList(condition, pars) // 这里就一条数据
  663. if e != nil && e.Error() != utils.ErrNoRow() {
  664. err = errors.New("GetCygxOrderDetailList, Err: " + e.Error())
  665. return
  666. }
  667. if len(listOrder) == 0 {
  668. err = nil
  669. return
  670. }
  671. for _, v := range listOrder {
  672. e = order.CancelCygxOrder(v)
  673. if e != nil {
  674. return
  675. }
  676. }
  677. return
  678. }