golang 的 rabbitmq 消费项目
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

zhios_acquisition_condition.go 22 KiB

1 yıl önce
10 ay önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
10 ay önce
1 yıl önce
1 yıl önce
10 ay önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
6 ay önce
1 yıl önce
6 ay önce
1 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. package consume
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "applet/consume/md"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  9. "encoding/json"
  10. "errors"
  11. "fmt"
  12. "github.com/streadway/amqp"
  13. "strings"
  14. "time"
  15. "xorm.io/xorm"
  16. )
  17. func ZhiosAcquisitionCondition(queue md.MqQueue) {
  18. fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
  19. ch, err := rabbit.Cfg.Pool.GetChannel()
  20. if err != nil {
  21. logx.Error(err)
  22. return
  23. }
  24. defer ch.Release()
  25. //1、将自己绑定到交换机上
  26. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  27. //2、取出数据进行消费
  28. ch.Qos(300)
  29. delivery := ch.Consume(queue.Name, false)
  30. var res amqp.Delivery
  31. var ok bool
  32. for {
  33. res, ok = <-delivery
  34. if ok == true {
  35. //fmt.Println(string(res.Body))
  36. fmt.Println(">>>>>>>>>>>>>>>>ZhiosAcquisitionCondition<<<<<<<<<<<<<<<<<<<<<<<<<")
  37. err = handleZhiosAcquisition(res.Body)
  38. //_ = res.Reject(false)
  39. fmt.Println(err)
  40. if err == nil {
  41. _ = res.Ack(true)
  42. } else {
  43. var canalMsg *md.ZhiosAcquisition
  44. var tmpString string
  45. err := json.Unmarshal(res.Body, &tmpString)
  46. if err == nil {
  47. fmt.Println(tmpString)
  48. err = json.Unmarshal([]byte(tmpString), &canalMsg)
  49. if err == nil {
  50. ch.Publish(queue.ExchangeName, utils.SerializeStr(canalMsg), queue.RoutKey)
  51. }
  52. }
  53. }
  54. } else {
  55. panic(errors.New("error getting message"))
  56. }
  57. }
  58. fmt.Println("get msg done")
  59. }
  60. func handleZhiosAcquisition(msg []byte) error {
  61. //1、解析canal采集至mq中queue的数据结构体
  62. var canalMsg *md.ZhiosAcquisition
  63. fmt.Println(string(msg))
  64. var tmpString string
  65. err := json.Unmarshal(msg, &tmpString)
  66. if err != nil {
  67. fmt.Println(err.Error())
  68. return err
  69. }
  70. fmt.Println(tmpString)
  71. err = json.Unmarshal([]byte(tmpString), &canalMsg)
  72. if err != nil {
  73. return err
  74. }
  75. mid := canalMsg.Mid
  76. eg := db.DBs[mid]
  77. if eg == nil {
  78. return nil
  79. }
  80. if canalMsg.Uid == "" {
  81. return nil
  82. }
  83. userInfo, _ := db.UserFindByID(eg, canalMsg.Uid)
  84. if userInfo == nil {
  85. return nil
  86. }
  87. userProfile, _ := db.UserProfileFindByID(eg, canalMsg.Uid)
  88. if userProfile == nil {
  89. return nil
  90. }
  91. cfg := db.GetAcquisitionCfg(eg, canalMsg.Id, userInfo.CreateAt)
  92. if cfg == nil {
  93. return nil
  94. }
  95. nextUserProfile, _ := db.UserProfileFindByID(eg, userProfile.ParentUid)
  96. var user = &md.User{Info: userInfo, Profile: userProfile}
  97. bools, str := checkAllCompleteTmp(eg, user, cfg)
  98. isFull := 0
  99. fullTime := 0
  100. toRewardTime := 0
  101. if bools {
  102. isFull = 1
  103. fullTime = int(time.Now().Unix())
  104. toRewardTime = int(time.Now().Unix()) + utils.StrToInt(cfg.RewardAccountDay)*86400
  105. }
  106. //写入奖励记录
  107. //新的设置 读第一个新注册的奖励
  108. lv := 0
  109. if len(cfg.RewardRule.LvRewardList) > 0 {
  110. isEnd := 0
  111. for k, v := range cfg.RewardRule.LvRewardList {
  112. if isEnd == 1 {
  113. continue
  114. }
  115. if utils.StrToInt(v.Id) == user.Info.Level {
  116. isEnd = 1
  117. }
  118. lv = utils.StrToInt(v.Id)
  119. if cfg.RewardRule.NewRewardCoinId != "" {
  120. ex := strings.Split(cfg.RewardRule.NewRewardCoinId, ",")
  121. for _, v1 := range v.CoinList {
  122. if utils.InArr(v1.CoinId, ex) {
  123. InvitedReward := v1.InvitedReward
  124. if cfg.RewardRule.RewardType == "1" {
  125. InvitedReward = Rands(v1.InvitedReward, v1.InvitedRewardMax)
  126. }
  127. //直推
  128. DirectSuccess := v1.DirectSuccess
  129. if cfg.RewardRule.RewardType == "1" {
  130. DirectSuccess = Rands(v1.DirectSuccess, v1.DirectSuccessMax)
  131. }
  132. //间推
  133. IndirectSuccess := v1.IndirectSuccess
  134. if cfg.RewardRule.RewardType == "1" {
  135. IndirectSuccess = Rands(v1.IndirectSuccess, v1.IndirectSuccessMax)
  136. }
  137. InvitedSource := 0
  138. DirectSource := 1
  139. IndirectSource := 2
  140. InvitedSourceStr := "注册奖励"
  141. DirectSourceStr := "直推好友"
  142. IndirectSourceStr := "间推好友"
  143. if k > 0 {
  144. InvitedSource = 3
  145. DirectSource = 4
  146. IndirectSource = 5
  147. InvitedSourceStr = "升级" + v.Name + "奖励"
  148. DirectSourceStr = "直推好友升级" + v.Name + "奖励"
  149. IndirectSourceStr = "间推好友升级" + v.Name + "奖励"
  150. }
  151. if utils.StrToFloat64(InvitedReward) > 0 {
  152. ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, userProfile.Uid, user.Profile.Uid, lv, utils.StrToInt(v1.CoinId))
  153. if !ownhas {
  154. ownRewardLog = &model.NewAcquisitionRewardLog{
  155. Uid: user.Profile.Uid,
  156. ToUid: user.Profile.Uid,
  157. Title: user.Info.Nickname,
  158. Source: InvitedSource,
  159. SourceText: InvitedSourceStr,
  160. Money: InvitedReward,
  161. CreatedAt: int(time.Now().Unix()),
  162. State: 0,
  163. CoinId: utils.StrToInt(v1.CoinId),
  164. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  165. InviteTime: int(userInfo.CreateAt.Unix()),
  166. Lv: lv,
  167. }
  168. db.InsertNewRewardLog(eg, ownRewardLog)
  169. }
  170. if ownRewardLog.GivenAt == 0 {
  171. ownRewardLog.CompleteCon = str
  172. ownRewardLog.IsFull = isFull
  173. if ownRewardLog.FullTime == 0 {
  174. ownRewardLog.FullTime = fullTime
  175. }
  176. if ownRewardLog.ToRewardTime == 0 {
  177. ownRewardLog.ToRewardTime = toRewardTime
  178. }
  179. eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog)
  180. }
  181. }
  182. if utils.StrToFloat64(DirectSuccess) > 0 {
  183. if userProfile.ParentUid > 0 {
  184. //写入奖励记录
  185. extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, userProfile.ParentUid, userProfile.Uid, lv, utils.StrToInt(v1.CoinId))
  186. if !extendHas {
  187. extendRewardLog = &model.NewAcquisitionRewardLog{
  188. Uid: user.Profile.ParentUid,
  189. ToUid: user.Profile.Uid,
  190. Title: user.Info.Nickname,
  191. Source: DirectSource,
  192. SourceText: DirectSourceStr,
  193. Money: DirectSuccess,
  194. CreatedAt: int(time.Now().Unix()),
  195. State: 0,
  196. CoinId: utils.StrToInt(v1.CoinId),
  197. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  198. InviteTime: int(userInfo.CreateAt.Unix()),
  199. Lv: lv,
  200. }
  201. db.InsertNewRewardLog(eg, extendRewardLog)
  202. }
  203. if extendRewardLog.GivenAt == 0 {
  204. extendRewardLog.CompleteCon = str
  205. extendRewardLog.IsFull = isFull
  206. if extendRewardLog.FullTime == 0 {
  207. extendRewardLog.FullTime = fullTime
  208. }
  209. if extendRewardLog.ToRewardTime == 0 {
  210. extendRewardLog.ToRewardTime = toRewardTime
  211. }
  212. eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog)
  213. }
  214. }
  215. }
  216. if utils.StrToFloat64(IndirectSuccess) > 0 {
  217. if nextUserProfile != nil && nextUserProfile.ParentUid > 0 {
  218. IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, nextUserProfile.ParentUid, userProfile.Uid, lv, utils.StrToInt(v1.CoinId))
  219. if !IndirectHas {
  220. IndirectRewardLog = &model.NewAcquisitionRewardLog{
  221. Uid: nextUserProfile.ParentUid,
  222. ToUid: user.Profile.Uid,
  223. Title: user.Info.Nickname,
  224. Source: IndirectSource,
  225. SourceText: IndirectSourceStr,
  226. Money: IndirectSuccess,
  227. CreatedAt: int(time.Now().Unix()),
  228. State: 0,
  229. CoinId: utils.StrToInt(v1.CoinId),
  230. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  231. InviteTime: int(userInfo.CreateAt.Unix()),
  232. Lv: lv,
  233. }
  234. db.InsertNewRewardLog(eg, IndirectRewardLog)
  235. }
  236. if IndirectRewardLog.GivenAt == 0 {
  237. IndirectRewardLog.CompleteCon = str
  238. IndirectRewardLog.IsFull = isFull
  239. if IndirectRewardLog.FullTime == 0 {
  240. IndirectRewardLog.FullTime = fullTime
  241. }
  242. if IndirectRewardLog.ToRewardTime == 0 {
  243. IndirectRewardLog.ToRewardTime = toRewardTime
  244. }
  245. eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog)
  246. }
  247. }
  248. }
  249. }
  250. }
  251. } else {
  252. InvitedReward := v.InvitedReward
  253. if cfg.RewardRule.RewardType == "1" {
  254. InvitedReward = Rands(v.InvitedReward, v.InvitedRewardMax)
  255. }
  256. //直推
  257. DirectSuccess := v.DirectSuccess
  258. if cfg.RewardRule.RewardType == "1" {
  259. DirectSuccess = Rands(v.DirectSuccess, v.DirectSuccessMax)
  260. }
  261. //间推
  262. IndirectSuccess := v.IndirectSuccess
  263. if cfg.RewardRule.RewardType == "1" {
  264. IndirectSuccess = Rands(v.IndirectSuccess, v.IndirectSuccessMax)
  265. }
  266. InvitedSource := 0
  267. DirectSource := 1
  268. IndirectSource := 2
  269. InvitedSourceStr := "注册奖励"
  270. DirectSourceStr := "直推好友"
  271. IndirectSourceStr := "间推好友"
  272. if k > 0 {
  273. InvitedSource = 3
  274. DirectSource = 4
  275. IndirectSource = 5
  276. InvitedSourceStr = "升级" + v.Name + "奖励"
  277. DirectSourceStr = "直推好友升级" + v.Name + "奖励"
  278. IndirectSourceStr = "间推好友升级" + v.Name + "奖励"
  279. }
  280. if utils.StrToFloat64(InvitedReward) > 0 {
  281. ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.Uid, user.Profile.Uid, lv)
  282. if !ownhas {
  283. ownRewardLog = &model.NewAcquisitionRewardLog{
  284. Uid: user.Profile.Uid,
  285. ToUid: user.Profile.Uid,
  286. Title: user.Info.Nickname,
  287. Source: InvitedSource,
  288. SourceText: InvitedSourceStr,
  289. Money: InvitedReward,
  290. CreatedAt: int(time.Now().Unix()),
  291. State: 0,
  292. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  293. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  294. InviteTime: int(userInfo.CreateAt.Unix()),
  295. Lv: lv,
  296. }
  297. db.InsertNewRewardLog(eg, ownRewardLog)
  298. }
  299. if ownRewardLog.GivenAt == 0 {
  300. ownRewardLog.CompleteCon = str
  301. ownRewardLog.IsFull = isFull
  302. if ownRewardLog.FullTime == 0 {
  303. ownRewardLog.FullTime = fullTime
  304. }
  305. if ownRewardLog.ToRewardTime == 0 {
  306. ownRewardLog.ToRewardTime = toRewardTime
  307. }
  308. eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog)
  309. }
  310. }
  311. if utils.StrToFloat64(DirectSuccess) > 0 {
  312. if userProfile.ParentUid > 0 {
  313. //写入奖励记录
  314. extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.ParentUid, userProfile.Uid, lv)
  315. if !extendHas {
  316. extendRewardLog = &model.NewAcquisitionRewardLog{
  317. Uid: user.Profile.ParentUid,
  318. ToUid: user.Profile.Uid,
  319. Title: user.Info.Nickname,
  320. Source: DirectSource,
  321. SourceText: DirectSourceStr,
  322. Money: DirectSuccess,
  323. CreatedAt: int(time.Now().Unix()),
  324. State: 0,
  325. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  326. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  327. InviteTime: int(userInfo.CreateAt.Unix()),
  328. Lv: lv,
  329. }
  330. db.InsertNewRewardLog(eg, extendRewardLog)
  331. }
  332. if extendRewardLog.GivenAt == 0 {
  333. extendRewardLog.CompleteCon = str
  334. extendRewardLog.IsFull = isFull
  335. if extendRewardLog.FullTime == 0 {
  336. extendRewardLog.FullTime = fullTime
  337. }
  338. if extendRewardLog.ToRewardTime == 0 {
  339. extendRewardLog.ToRewardTime = toRewardTime
  340. }
  341. eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog)
  342. }
  343. }
  344. }
  345. if utils.StrToFloat64(IndirectSuccess) > 0 {
  346. if nextUserProfile != nil && nextUserProfile.ParentUid > 0 {
  347. IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, nextUserProfile.ParentUid, userProfile.Uid, lv)
  348. if !IndirectHas {
  349. IndirectRewardLog = &model.NewAcquisitionRewardLog{
  350. Uid: nextUserProfile.ParentUid,
  351. ToUid: user.Profile.Uid,
  352. Title: user.Info.Nickname,
  353. Source: IndirectSource,
  354. SourceText: IndirectSourceStr,
  355. Money: IndirectSuccess,
  356. CreatedAt: int(time.Now().Unix()),
  357. State: 0,
  358. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  359. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  360. InviteTime: int(userInfo.CreateAt.Unix()),
  361. Lv: lv,
  362. }
  363. db.InsertNewRewardLog(eg, IndirectRewardLog)
  364. }
  365. if IndirectRewardLog.GivenAt == 0 {
  366. IndirectRewardLog.CompleteCon = str
  367. IndirectRewardLog.IsFull = isFull
  368. if IndirectRewardLog.FullTime == 0 {
  369. IndirectRewardLog.FullTime = fullTime
  370. }
  371. if IndirectRewardLog.ToRewardTime == 0 {
  372. IndirectRewardLog.ToRewardTime = toRewardTime
  373. }
  374. eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog)
  375. }
  376. }
  377. }
  378. }
  379. }
  380. } else {
  381. InvitedReward := cfg.RewardRule.InvitedReward
  382. if cfg.RewardRule.RewardType == "1" {
  383. InvitedReward = Rands(cfg.RewardRule.InvitedReward, cfg.RewardRule.InvitedRewardMax)
  384. }
  385. //直推
  386. DirectSuccess := cfg.RewardRule.DirectSuccess
  387. if cfg.RewardRule.RewardType == "1" {
  388. DirectSuccess = Rands(cfg.RewardRule.DirectSuccess, cfg.RewardRule.DirectSuccessMax)
  389. }
  390. //间推
  391. IndirectSuccess := cfg.RewardRule.IndirectSuccess
  392. if cfg.RewardRule.RewardType == "1" {
  393. IndirectSuccess = Rands(cfg.RewardRule.IndirectSuccess, cfg.RewardRule.IndirectSuccessMax)
  394. }
  395. if utils.StrToFloat64(InvitedReward) > 0 {
  396. ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLog(eg, &model.NewAcquisitionRewardLog{
  397. Uid: user.Profile.Uid,
  398. ToUid: user.Profile.Uid,
  399. })
  400. if !ownhas {
  401. ownRewardLog = &model.NewAcquisitionRewardLog{
  402. Uid: user.Profile.Uid,
  403. ToUid: user.Profile.Uid,
  404. Title: user.Info.Nickname,
  405. Source: 0,
  406. SourceText: "注册奖励",
  407. Money: InvitedReward,
  408. CreatedAt: int(time.Now().Unix()),
  409. State: 0,
  410. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  411. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  412. InviteTime: int(userInfo.CreateAt.Unix()),
  413. Lv: lv,
  414. }
  415. db.InsertNewRewardLog(eg, ownRewardLog)
  416. }
  417. if ownRewardLog.GivenAt == 0 {
  418. ownRewardLog.CompleteCon = str
  419. ownRewardLog.IsFull = isFull
  420. if ownRewardLog.FullTime == 0 {
  421. ownRewardLog.FullTime = fullTime
  422. }
  423. if ownRewardLog.ToRewardTime == 0 {
  424. ownRewardLog.ToRewardTime = toRewardTime
  425. }
  426. eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog)
  427. }
  428. }
  429. if utils.StrToFloat64(DirectSuccess) > 0 {
  430. if userProfile.ParentUid > 0 {
  431. //写入奖励记录
  432. extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLog(eg, &model.NewAcquisitionRewardLog{
  433. Uid: userProfile.ParentUid,
  434. ToUid: userProfile.Uid,
  435. })
  436. if !extendHas {
  437. extendRewardLog = &model.NewAcquisitionRewardLog{
  438. Uid: user.Profile.ParentUid,
  439. ToUid: user.Profile.Uid,
  440. Title: user.Info.Nickname,
  441. Source: 1,
  442. SourceText: "直推好友",
  443. Money: DirectSuccess,
  444. CreatedAt: int(time.Now().Unix()),
  445. State: 0,
  446. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  447. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  448. InviteTime: int(userInfo.CreateAt.Unix()),
  449. Lv: lv,
  450. }
  451. db.InsertNewRewardLog(eg, extendRewardLog)
  452. }
  453. if extendRewardLog.GivenAt == 0 {
  454. extendRewardLog.CompleteCon = str
  455. extendRewardLog.IsFull = isFull
  456. if extendRewardLog.FullTime == 0 {
  457. extendRewardLog.FullTime = fullTime
  458. }
  459. if extendRewardLog.ToRewardTime == 0 {
  460. extendRewardLog.ToRewardTime = toRewardTime
  461. }
  462. eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog)
  463. }
  464. }
  465. }
  466. if utils.StrToFloat64(IndirectSuccess) > 0 {
  467. if nextUserProfile != nil && nextUserProfile.ParentUid > 0 {
  468. IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLog(eg, &model.NewAcquisitionRewardLog{
  469. Uid: nextUserProfile.ParentUid,
  470. ToUid: userProfile.Uid,
  471. })
  472. if !IndirectHas {
  473. IndirectRewardLog = &model.NewAcquisitionRewardLog{
  474. Uid: nextUserProfile.ParentUid,
  475. ToUid: user.Profile.Uid,
  476. Title: user.Info.Nickname,
  477. Source: 2,
  478. SourceText: "间推好友",
  479. Money: IndirectSuccess,
  480. CreatedAt: int(time.Now().Unix()),
  481. State: 0,
  482. CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId),
  483. RewardType: utils.StrToInt(cfg.RewardRule.RewardType),
  484. InviteTime: int(userInfo.CreateAt.Unix()),
  485. Lv: lv,
  486. }
  487. db.InsertNewRewardLog(eg, IndirectRewardLog)
  488. }
  489. if IndirectRewardLog.GivenAt == 0 {
  490. IndirectRewardLog.CompleteCon = str
  491. IndirectRewardLog.IsFull = isFull
  492. if IndirectRewardLog.FullTime == 0 {
  493. IndirectRewardLog.FullTime = fullTime
  494. }
  495. if IndirectRewardLog.ToRewardTime == 0 {
  496. IndirectRewardLog.ToRewardTime = toRewardTime
  497. }
  498. eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog)
  499. }
  500. }
  501. }
  502. }
  503. return nil
  504. }
  505. func Rands(minVal, maxVal string) string {
  506. min := int(utils.StrToFloat64(minVal) * 100)
  507. max := int(utils.StrToFloat64(maxVal) * 100)
  508. return utils.Float64ToStrByPrec(float64(utils.RandIntRand(min, max))/100, 3)
  509. }
  510. //判断是否符合条件
  511. func checkAllCompleteTmp(eg *xorm.Engine, user *md.User, acqCfg *md.AcquisitionCfg) (bool, string) {
  512. res := true
  513. str := ""
  514. if acqCfg.SuccessConditions.Register.Open == "1" {
  515. res = res && AcqRegisterTmp(user, acqCfg)
  516. if res {
  517. str += ",Register"
  518. }
  519. }
  520. if acqCfg.SuccessConditions.TaobaoAuthorization.Open == "1" {
  521. res = res && AcqTaoBaoAuthTmp(user, acqCfg)
  522. if res {
  523. str += ",TaobaoAuthorization"
  524. }
  525. }
  526. if acqCfg.SuccessConditions.FirstOrder.Open == "1" {
  527. res = res && AcqFirstOrder(eg, user, acqCfg)
  528. if res {
  529. str += ",FirstOrder"
  530. }
  531. }
  532. if acqCfg.SuccessConditions.SelfOrder.Open == "1" {
  533. res = res && AcqSelfOrder(eg, user, acqCfg)
  534. if res {
  535. str += ",SelfOrder"
  536. }
  537. }
  538. if acqCfg.SuccessConditions.OrderPay.Open == "1" {
  539. //AcqOrderPay(eg, user, acqCfg)
  540. res = res && AcqOrderPay(eg, user, acqCfg)
  541. if res {
  542. str += ",OrderPay"
  543. }
  544. }
  545. if len(str) > 0 {
  546. str = str[1:]
  547. }
  548. return res, str
  549. }
  550. func AcqRegisterTmp(user *md.User, acqCfg *md.AcquisitionCfg) bool {
  551. var startTime = utils.TimeStdParseUnix(acqCfg.StartTime)
  552. var endTime = utils.TimeStdParseUnix(acqCfg.EndTime)
  553. if startTime == 0 || endTime == 0 {
  554. return false
  555. }
  556. //时间不在活动范围之内返回false
  557. if user.Info.CreateAt.Unix() < startTime {
  558. return false
  559. }
  560. if user.Info.CreateAt.Unix() > endTime {
  561. return false
  562. }
  563. return true
  564. }
  565. func AcqTaoBaoAuthTmp(user *md.User, acqCfg *md.AcquisitionCfg) bool {
  566. if user.Profile.AccTaobaoAuthTime > 0 {
  567. return true
  568. }
  569. return false
  570. }
  571. func AcqFirstOrder(eg *xorm.Engine, user *md.User, acqCfg *md.AcquisitionCfg) bool {
  572. endTime := int(user.Info.CreateAt.Unix()) + utils.StrToInt(acqCfg.SuccessConditions.FirstOrder.Day)*86400
  573. return commAmount(eg, utils.IntToStr(user.Info.Uid), endTime, 0, acqCfg)
  574. }
  575. func AcqSelfOrder(eg *xorm.Engine, user *md.User, acqCfg *md.AcquisitionCfg) bool {
  576. return commAmount(eg, utils.IntToStr(user.Info.Uid), 0, 2, acqCfg)
  577. }
  578. func AcqOrderPay(eg *xorm.Engine, user *md.User, acqCfg *md.AcquisitionCfg) bool {
  579. return commAmount(eg, utils.IntToStr(user.Info.Uid), 0, 1, acqCfg)
  580. }
  581. func sqlSelect(eg *xorm.Engine, uid string, endTime, types int, acqCfg *md.AcquisitionCfg, arr []string) int {
  582. sql := `SELECT COUNT(*) as count FROM %s ol
  583. LEFT JOIN %s olr on olr.oid=%s and olr.uid=%s
  584. WHERE ol.uid=? %s %s
  585. `
  586. str := ""
  587. if endTime > 0 {
  588. str += " AND olr.create_at<=" + utils.IntToStr(endTime)
  589. }
  590. if types == 2 {
  591. str += " AND olr.amount>=" + acqCfg.SuccessConditions.SelfOrder.Money
  592. }
  593. if types == 1 {
  594. str += " AND %s>=" + acqCfg.SuccessConditions.OrderPay.Money
  595. str = fmt.Sprintf(str, arr[0])
  596. }
  597. sqlOrd := fmt.Sprintf(sql, arr[1], arr[2], arr[3], arr[4], str, arr[5])
  598. ordResult, err := db.QueryNativeString(eg, sqlOrd, uid)
  599. fmt.Println(sqlOrd)
  600. fmt.Println(err)
  601. count := 0
  602. for _, v := range ordResult {
  603. count = utils.StrToInt(v["count"])
  604. }
  605. return count
  606. }
  607. func commAmount(eg *xorm.Engine, uid string, endTime, types int, acqCfg *md.AcquisitionCfg) bool {
  608. state := "0,1,2,3,5"
  609. psoState := "'订单付款','订单结算'"
  610. mallState := "1,2,3"
  611. o2oState := "1,2,3,4"
  612. b2cState := "1,2,3,4"
  613. if acqCfg.SuccessConditions.FirstOrder.Status == "1" {
  614. state = "1,2,3,5"
  615. mallState = "2,3"
  616. o2oState = "2,3,4"
  617. b2cState = "2,3,4"
  618. }
  619. if acqCfg.SuccessConditions.FirstOrder.Status == "2" {
  620. state = "2,3,5"
  621. mallState = "2,3"
  622. o2oState = "2,3,4"
  623. b2cState = "2,3,4"
  624. }
  625. if acqCfg.SuccessConditions.FirstOrder.Status == "3" {
  626. state = "3,5"
  627. mallState = "3"
  628. o2oState = "3,4"
  629. b2cState = "3,4"
  630. psoState = "'订单结算'"
  631. }
  632. arr := []string{"ol.paid_price", "ord_list", "ord_list_relate", "ol.ord_id", "ol.uid", " and ol.state in(" + state + ")"}
  633. count := sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  634. arr = []string{"ol.paid_price", "privilege_card_ord", "ord_list_relate", "ol.ord_id", "ol.uid", " and ol.state=1"}
  635. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  636. arr = []string{"ol.money", "express_order", "ord_list_relate", "ol.oid", "ol.uid", " and ol.status in('待取件','运输中','已完成')"}
  637. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  638. arr = []string{"ol.commission", "duoyou_ord_list", "ord_list_relate", "ol.oid", "ol.uid", " and ol.id>0"}
  639. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  640. arr = []string{"ol.amount", "recharge_order", "ord_list_relate", "ol.oid", "ol.uid", " and ol.status<>'已退款'"}
  641. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  642. arr = []string{"ol.amount", "playlet_sale_order", "ord_list_relate", "ol.custom_oid", "ol.uid", " and ol.status in(" + psoState + ")"}
  643. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  644. arr = []string{"ol.cost_price", "mall_ord", "mall_ord_list_relate", "ol.ord_id", "ol.uid", " and ol.state in(" + mallState + ")"}
  645. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  646. arr = []string{"ol.cost_price", "o2o_ord", "o2o_ord_list_relate", "ol.ord_id", "ol.uid", " and ol.state in(" + o2oState + ")"}
  647. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  648. arr = []string{"ol.actual_pay_amount", "o2o_pay_to_merchant", "o2o_ord_list_relate", "ol.pay_id", "ol.uid", " and ol.state >=1"}
  649. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  650. arr = []string{"ol.cost_price", "b2c_ord", "b2c_ord_list_relate", "ol.ord_id", "ol.uid", " and ol.state in(" + b2cState + ")"}
  651. count += sqlSelect(eg, uid, endTime, types, acqCfg, arr)
  652. if count > 0 {
  653. return true
  654. }
  655. return false
  656. }