balanceService.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jyResourcesCenter/entity"
  4. "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
  5. "bytes"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. "io/ioutil"
  10. "log"
  11. "net/http"
  12. "strconv"
  13. "time"
  14. )
  15. type BalanceService struct{}
  16. const (
  17. ConsumeRecord = "consume_record" //流水表
  18. AccountResources = "account_resources" //结存表
  19. )
  20. // 根据账户标识新增资源
  21. func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, producMap map[string]interface{}) (int64, string) {
  22. orm := entity.Engine.NewSession()
  23. err := orm.Begin()
  24. balance := entity.Balance{}
  25. userType := int64(1)
  26. remarks := detailedData.Remarks
  27. if detailedData.ResourceType == "附件下载包" {
  28. remarksMap := map[string]interface{}{}
  29. switch balanceData.Model {
  30. case 0:
  31. remarksMap["describe"] = fmt.Sprintf("购买附件下载包,获得%v(读取购买数量)个附件下载权益。\n附件下载权益当月有效。\n", balanceData.Number)
  32. case 2:
  33. userType = 2
  34. remarksMap["describe"] = "剑鱼币兑换成功\n兑换剑鱼币30天内有效。\n"
  35. case 3:
  36. userType = 3
  37. remarksMap["describe"] = fmt.Sprintf("超级订阅用户每月享有下载%v个附件的权限,每月1号上余额清零重新计算。", balanceData.Number)
  38. }
  39. jsonData, err := json.Marshal(remarksMap)
  40. if err != nil {
  41. fmt.Println(err)
  42. }
  43. remarks = string(jsonData)
  44. }
  45. if producMap[balanceData.ResourceType] != nil {
  46. fool, err := orm.Table(AccountResources).
  47. Select("*").
  48. Where("accountId=? and companyId=? and departmentId=? and ResourceType=? and endTime=? and vipTime=? and sourceType=?",
  49. balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, balanceData.EndTime, balanceData.VipTime, userType).
  50. Get(&balance)
  51. if err != nil && !fool {
  52. fmt.Println("结存查询失败:", err)
  53. return entity.ErrorCode, "企业下的组织查询失败"
  54. }
  55. } else {
  56. fool, err := orm.Table(AccountResources).
  57. Select("*").
  58. Where("accountId=? and companyId=? and departmentId=? and ResourceType=? and endTime=? and sourceType=?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, balanceData.EndTime, userType).
  59. Get(&balance)
  60. if err != nil && !fool {
  61. fmt.Println("结存查询失败:", err)
  62. return entity.ErrorCode, "企业下的组织查询失败"
  63. }
  64. }
  65. //新增流水记录
  66. detailed := entity.Detailed{
  67. AccountId: detailedData.AccountId,
  68. CompanyId: detailedData.CompanyId,
  69. DepartmentId: detailedData.DepartmentId,
  70. ResourceType: detailedData.ResourceType,
  71. Number: detailedData.Number,
  72. RuleId: detailedData.RuleId,
  73. Name: detailedData.Name,
  74. CreateTime: time.Now().Local(),
  75. Remarks: remarks,
  76. UserType: userType,
  77. }
  78. insertNumb, err := orm.Table(ConsumeRecord).Insert(&detailed)
  79. if err != nil {
  80. fmt.Println("新增流水失败:", err)
  81. orm.Rollback()
  82. return entity.ErrorCode, "新增流水失败"
  83. }
  84. if insertNumb <= 0 {
  85. orm.Rollback()
  86. return entity.ErrorCode, "新增流水失败"
  87. }
  88. //资源流水新增
  89. //orm.Table(AccountResources).Insert(&balance)
  90. if balance.Id == 0 {
  91. //新增结存记录
  92. balance = entity.Balance{
  93. AccountId: balanceData.AccountId,
  94. CompanyId: balanceData.CompanyId,
  95. DepartmentId: balanceData.DepartmentId,
  96. Name: balanceData.Name,
  97. ResourceType: balanceData.ResourceType,
  98. Number: balanceData.Number,
  99. Spec: balanceData.Spec,
  100. AppId: balanceData.AppId,
  101. EndTime: balanceData.EndTime,
  102. VipTime: balanceData.VipTime,
  103. SourceType: userType,
  104. }
  105. insertNumb, err = orm.Table(AccountResources).Insert(&balance)
  106. if err != nil || insertNumb <= 0 {
  107. fmt.Println("结存查询失败:", err)
  108. orm.Rollback()
  109. return entity.ErrorCode, "结存新增失败"
  110. }
  111. orm.Commit()
  112. return entity.SuccessCode, "结存新增成功"
  113. }
  114. balance.Number = balance.Number + balanceData.Number
  115. updateNumb, err := orm.Table(AccountResources).Cols("number").
  116. Where(" id=?", balance.Id).
  117. Update(&balance)
  118. if err != nil || updateNumb <= 0 {
  119. orm.Rollback()
  120. fmt.Println("结存修改失败:", err)
  121. return entity.ErrorCode, "结存修改失败"
  122. }
  123. orm.Commit()
  124. return entity.SuccessCode, "结存修改成功"
  125. }
  126. // 根据账户标识使用资源
  127. func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, infoId, url string, producMap map[string]interface{}) (int64, string, int64) {
  128. orm := entity.Engine.NewSession()
  129. err := orm.Begin()
  130. //去重
  131. deductionNumb := detailedData.Number
  132. deductionNumbs := detailedData.Number
  133. if duplicateRemoval == 1 {
  134. dataDesc := 0
  135. if detailedData.ResourceType == "标准字段包" {
  136. dataDesc = 2
  137. } else if detailedData.ResourceType == "高级字段包" {
  138. dataDesc = 1
  139. }
  140. var appheader = "application/x-www-form-urlencoded"
  141. param := "dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + detailedData.UserId + "&infoId=" + infoId + "&accountId=" + detailedData.AccountId
  142. resp, status, _ := HttpPost_M(url+"/data/dedupAndSave/"+fmt.Sprint(time.Now().Unix()), appheader, param, 20)
  143. log.Println(resp, status)
  144. if status != 200 && (resp == nil || len(resp) <= 0) {
  145. return entity.ErrorCode, "请求去重接口出错", 0
  146. }
  147. data := resp["data"].(map[string]interface{})
  148. if fmt.Sprint(resp["code"]) == "0" {
  149. deductionNumb, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
  150. deductionNumbs, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
  151. if fmt.Sprint(data["totalCount"]) == "0" {
  152. return entity.ErrorCode, "去重失败", 0
  153. }
  154. } else {
  155. return entity.ErrorCode, "去重失败", 0
  156. }
  157. }
  158. //查询结存是否够用
  159. type SumStruct struct {
  160. Age int `xorm:"age"`
  161. }
  162. sumStruct := "0"
  163. now1 := time.Now()
  164. currentYear, currentMonth, _ := now1.Date()
  165. currentLocation := now1.Location()
  166. firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
  167. lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
  168. endTime := lastOfMonth.Format("2006-01-02")
  169. starteTime := lastOfMonth.Format("2006-01-02")
  170. nowTime := now1.Format("2006-01-02")
  171. if producMap[balanceData.ResourceType] != nil {
  172. if balanceData.ResourceType == "附件下载包" {
  173. _, err = orm.Table(AccountResources).
  174. Select("sum(number) as number").
  175. Where("accountId=? and companyId=? and departmentId=? and ResourceType=? "+
  176. "and (( endTime>= ? and endTime<=? and vipTime>? )or (endTime>= ? and endTime<=? and (vipTime = '' or vipTime is NULL ) )) ",
  177. balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, starteTime, endTime, nowTime, starteTime, endTime).
  178. Get(&sumStruct)
  179. } else {
  180. _, err = orm.Table(AccountResources).
  181. Select("sum(number) as number").
  182. Where("accountId=? and companyId=? and departmentId=? and ResourceType=? and endTime=? and vipTime>?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, endTime, nowTime).
  183. Get(&sumStruct)
  184. }
  185. } else {
  186. _, err = orm.Table(AccountResources).
  187. Select("sum(number) as number").
  188. Where("accountId=? and companyId=? and departmentId=? and ResourceType=? and endTime>=?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, time.Now().Format("2006-01-02")).
  189. Get(&sumStruct)
  190. }
  191. if err != nil {
  192. fmt.Println("结存查询失败:", err)
  193. orm.Rollback()
  194. return entity.ErrorCode, "结存查询失败", 0
  195. }
  196. surplusNumb, err := strconv.ParseInt(sumStruct, 10, 64)
  197. if surplusNumb < deductionNumb {
  198. return entity.ErrorCode, "结存不足,请立即充值", 0
  199. }
  200. //新增流水记录
  201. detailed := entity.Detailed{
  202. AccountId: detailedData.AccountId,
  203. CompanyId: detailedData.CompanyId,
  204. DepartmentId: detailedData.DepartmentId,
  205. ResourceType: detailedData.ResourceType,
  206. Number: detailedData.Number,
  207. RuleId: detailedData.RuleId,
  208. CreateTime: time.Now().Local(),
  209. UserType: 0,
  210. UserId: detailedData.UserId,
  211. Remarks: detailedData.Remarks,
  212. DeductionNumb: deductionNumb,
  213. Name: detailedData.Name,
  214. }
  215. insertNumb, err := orm.Table(ConsumeRecord).Insert(&detailed)
  216. if err != nil || insertNumb <= 0 {
  217. fmt.Println("新增流水失败:", err)
  218. orm.Rollback()
  219. return entity.ErrorCode, "新增流水失败", 0
  220. }
  221. if deductionNumb == 0 {
  222. orm.Commit()
  223. return entity.SuccessCode, "修改结存成功", deductionNumb
  224. }
  225. //修改结存
  226. balanceList := []entity.Balance{}
  227. if producMap[balanceData.ResourceType] != nil {
  228. if balanceData.ResourceType == "附件下载包" {
  229. err = orm.Table(AccountResources).
  230. Select("*").
  231. Where("accountId=? and companyId=? and departmentId=? and number>0 and ResourceType=?"+
  232. " and (( endTime>= ? and endTime<=? and vipTime>=? )or (endTime>= ? and (vipTime='' or vipTime is NULL ) )) ",
  233. balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, starteTime, endTime, nowTime, nowTime).
  234. OrderBy("endTime").
  235. Find(&balanceList)
  236. } else {
  237. err = orm.Table(AccountResources).
  238. Select("*").
  239. Where("accountId=? and companyId=? and departmentId=? and number>0 and ResourceType=? and endTime=? and vipTime>? ", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, endTime, nowTime).
  240. OrderBy("endTime").
  241. Find(&balanceList)
  242. }
  243. } else {
  244. err = orm.Table(AccountResources).
  245. Select("*").
  246. Where("accountId=? and companyId=? and departmentId=? and number>0 and ResourceType=? and endTime>=? ", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, time.Now().Format("2006-01-02")).
  247. OrderBy("endTime").
  248. Find(&balanceList)
  249. }
  250. if err != nil {
  251. fmt.Println("结存查询失败:", err)
  252. orm.Rollback()
  253. return entity.ErrorCode, "企业下的组织查询失败", 0
  254. }
  255. for _, value := range balanceList {
  256. if value.Number > deductionNumb {
  257. value.Number = value.Number - deductionNumb
  258. deductionNumb = 0
  259. } else {
  260. deductionNumb = deductionNumb - value.Number
  261. value.Number = 0
  262. }
  263. updateNumb, err := orm.Table(AccountResources).
  264. Cols("number").ID(value.Id).
  265. Update(&value)
  266. if err != nil || updateNumb <= 0 {
  267. fmt.Println("结存修改失败:", err)
  268. orm.Rollback()
  269. return entity.ErrorCode, "结存修改失败", 0
  270. }
  271. if deductionNumb == 0 {
  272. break
  273. }
  274. }
  275. orm.Commit()
  276. return entity.SuccessCode, "使用结存成功", deductionNumbs
  277. }
  278. // 去重查询
  279. func (service *BalanceService) FindPreview(in *resourcesCenter.PreviewReq, url string) (int64, string, int64, int64) {
  280. orm := entity.Engine
  281. balance := []entity.AccountBalance{}
  282. //先查询余额
  283. dataDesc := 0
  284. if in.ResourceType == "标准字段包" {
  285. dataDesc = 2
  286. } else if in.ResourceType == "高级字段包" {
  287. dataDesc = 1
  288. }
  289. err := orm.Table("account_resources").Select("number").
  290. Where("accountId = ? and resourceType = ?", in.AccountId, in.ResourceType).Find(&balance)
  291. if err != nil {
  292. return entity.ErrorCode, "查询余额失败", 0, 0
  293. }
  294. var appheader = "application/x-www-form-urlencoded"
  295. param := "dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + in.AccountId + "&infoId=" + in.InfoId + "&accountId=" + in.AccountId
  296. resp, status, _ := HttpPost_M(url+"/data/dedupByAcount/"+fmt.Sprint(time.Now().Unix()), appheader, param, 20)
  297. log.Println(resp, status)
  298. if status != 200 && (resp == nil || len(resp) <= 0) {
  299. return entity.ErrorCode, "请求去重接口出错", 0, 0
  300. }
  301. data := resp["data"].(map[string]interface{})
  302. repeatNumb := data["existCount"].(float64)
  303. deductionNumb := data["newCount"].(float64)
  304. log.Println(repeatNumb, deductionNumb)
  305. return entity.SuccessCode, "去重", int64(repeatNumb), int64(deductionNumb)
  306. }
  307. func HttpPost_M(href, contentType, param string, timeout int) (map[string]interface{}, int, int64) {
  308. t1 := time.Now().UnixNano()
  309. client := &http.Client{}
  310. client.Timeout = time.Duration(timeout) * time.Second
  311. req, _ := http.NewRequest("POST", href, bytes.NewReader([]byte(param)))
  312. req.Header.Set("Content-Type", contentType)
  313. resp, err := client.Do(req)
  314. if err != nil {
  315. log.Println("post_M err1:", err)
  316. return nil, -1, 0
  317. }
  318. defer resp.Body.Close()
  319. bs, err := ioutil.ReadAll(resp.Body)
  320. if err != nil {
  321. log.Println("post_M err2:", err)
  322. return nil, -2, 0
  323. }
  324. var resData = map[string]interface{}{}
  325. json.Unmarshal(bs, &resData)
  326. t2 := time.Now().UnixNano()
  327. return resData, resp.StatusCode, t2 - t1
  328. }
  329. // 账号合并
  330. func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string, producMap map[string]interface{}) (int64, string) {
  331. orm := entity.Engine.NewSession()
  332. err := orm.Begin()
  333. if err != nil {
  334. return entity.ErrorCode, "账号合并失败"
  335. }
  336. //查询有效的资源量
  337. balanceList := []entity.Balance{}
  338. err = orm.Table(AccountResources).
  339. Select("*").
  340. Where("accountId=? and number >0 and endTime>=? ", mergedUser, time.Now().Format("2006-01-02")).
  341. OrderBy("endTime").
  342. Find(&balanceList)
  343. //计算总量
  344. for _, value := range balanceList {
  345. //流水操作
  346. //被合并用户流水
  347. mergedDetailed := entity.Detailed{
  348. AccountId: mergedUser,
  349. CompanyId: int64(0),
  350. DepartmentId: int64(0),
  351. ResourceType: value.ResourceType + "(合并)",
  352. Number: value.Number,
  353. RuleId: "",
  354. CreateTime: time.Now().Local(),
  355. UserType: 0,
  356. UserId: mergeUser,
  357. Remarks: "",
  358. DeductionNumb: int64(0),
  359. Name: value.Name + "(合并)",
  360. }
  361. insertNumb, err := orm.Table(ConsumeRecord).Insert(&mergedDetailed)
  362. if err != nil || insertNumb <= 0 {
  363. fmt.Println("新增流水失败:", err)
  364. orm.Rollback()
  365. return entity.ErrorCode, "新增流水失败"
  366. }
  367. //合并用户流水
  368. pType := 0
  369. if value.ResourceType == "标准字段包" {
  370. pType = 1
  371. } else if value.ResourceType == "高级字段包" {
  372. pType = 2
  373. }
  374. times, _ := time.Parse("2006-01-02 15:04:05", value.EndTime+" 23:59:59")
  375. timeUnix := times.Unix()
  376. filter_map := map[string]interface{}{
  377. "pType": pType,
  378. "pNum": value.Number,
  379. "validYear": -1,
  380. "price": -1,
  381. "endTime": timeUnix,
  382. }
  383. filter, _ := json.Marshal(filter_map)
  384. mergeDetailed := entity.Detailed{
  385. AccountId: mergeUser,
  386. CompanyId: int64(0),
  387. DepartmentId: int64(0),
  388. ResourceType: value.ResourceType + "(合并)",
  389. Number: value.Number,
  390. RuleId: "",
  391. CreateTime: time.Now().Local(),
  392. UserType: 1,
  393. UserId: mergeUser,
  394. Remarks: string(filter),
  395. DeductionNumb: int64(0),
  396. Name: value.Name + "(合并)",
  397. }
  398. insertNumb, err = orm.Table(ConsumeRecord).Insert(&mergeDetailed)
  399. if err != nil || insertNumb <= 0 {
  400. fmt.Println("新增流水失败:", err)
  401. orm.Rollback()
  402. return entity.ErrorCode, "新增流水失败"
  403. }
  404. //结存操作
  405. balance := entity.Balance{}
  406. _, err = orm.Table(AccountResources).
  407. Select("*").
  408. Where("accountId=? and resourceType=? endTime=? and vipTime=?", mergeUser, value.ResourceType, value.EndTime, value.VipTime).
  409. OrderBy("endTime").
  410. Get(&balance)
  411. if balance.Id != 0 {
  412. //增加结存数量
  413. balance.Number += value.Number
  414. updateNumb, err := orm.Table(AccountResources).
  415. Cols("number").ID(balance.Id).
  416. Update(&balance)
  417. if err != nil || updateNumb <= 0 {
  418. fmt.Println("结存修改失败:", err)
  419. orm.Rollback()
  420. return entity.ErrorCode, "结存修改失败"
  421. }
  422. //增加用户资源量
  423. //查看是否有结止时间为endTime的数据
  424. } else {
  425. //新增结存信息
  426. mergeBalance := entity.Balance{
  427. AccountId: mergeUser,
  428. CompanyId: 0,
  429. DepartmentId: 0,
  430. Name: value.Name,
  431. ResourceType: value.ResourceType,
  432. Number: value.Number,
  433. Spec: value.Spec,
  434. AppId: value.AppId,
  435. EndTime: value.EndTime,
  436. VipTime: value.VipTime,
  437. }
  438. insertNumb, err := orm.Table(AccountResources).Insert(&mergeBalance)
  439. if err != nil || insertNumb <= 0 {
  440. fmt.Println("结存新增失败:", err)
  441. orm.Rollback()
  442. return entity.ErrorCode, "结存新增失败"
  443. }
  444. }
  445. value.Number = 0
  446. updateNumb, err := orm.Table(AccountResources).
  447. Cols("number").ID(value.Id).
  448. Update(&value)
  449. if err != nil || updateNumb <= 0 {
  450. fmt.Println("结存修改失败:", err)
  451. orm.Rollback()
  452. return entity.ErrorCode, "结存修改失败"
  453. }
  454. }
  455. orm.Commit()
  456. return entity.SuccessCode, "合并成功"
  457. }
  458. // 超级订阅时间修改
  459. func (service *BalanceService) UpdateVipTime(data *resourcesCenter.VipReq, productValue string) (int64, string) {
  460. orm := entity.Engine.NewSession()
  461. err := orm.Begin()
  462. defer orm.Close()
  463. updateNumb := int64(0)
  464. now1 := time.Now()
  465. currentYear, currentMonth, _ := now1.Date()
  466. currentLocation := now1.Location()
  467. firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
  468. lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
  469. endTime := lastOfMonth.Format("2006-01-02")
  470. dataMap := map[string]interface{}{
  471. "vipTime": data.VipTime,
  472. }
  473. resourceTypeStr := `FIND_IN_SET(resourceType,%s)`
  474. resourceTypeStr = fmt.Sprintf(` FIND_IN_SET(resourceType,"%s")`, productValue)
  475. updateNumb, err = orm.Table(AccountResources).
  476. Cols("vipTime").Where("endTime = ? and accountId=? and sourceType in(1,3) and "+resourceTypeStr, endTime, data.AccountId).
  477. Update(&dataMap)
  478. if err != nil || updateNumb < 0 {
  479. fmt.Println("结存修改失败:", err)
  480. orm.Rollback()
  481. return entity.ErrorCode, "超级订阅时间修改失败"
  482. }
  483. orm.Commit()
  484. return entity.SuccessCode, "超级订阅时间修改成功"
  485. }
  486. func (service *BalanceService) ExpireHandle() {
  487. orm := entity.Engine.NewSession()
  488. endTime := time.Now().Format("2006-01-02")
  489. expireList := []map[string]interface{}{}
  490. endTime = "2023-10-21"
  491. orm.Table(AccountResources).Where("resourceType=? and (endTime=? or vipTime=?) and number >0 ", "附件下载包", endTime, endTime).Find(&expireList)
  492. for _, m := range expireList {
  493. //流水生成
  494. sourceType := gconv.Int64(m["sourceType"])
  495. accountId := gconv.String(m["accountId"])
  496. number := gconv.Int64(m["number"])
  497. resourcesId := gconv.Int64(m["id"])
  498. userType := int64(1)
  499. remarks := ""
  500. remarksMap := map[string]interface{}{}
  501. switch sourceType {
  502. case 1:
  503. remarksMap["describe"] = "购买附件下载包权益未使用失效。"
  504. case 2:
  505. userType = 2
  506. remarksMap["describe"] = "剑鱼币兑换权益未使用失效。"
  507. case 3:
  508. userType = 3
  509. remarksMap["describe"] = fmt.Sprintf("超级订阅%s附件下载权益未使用失效。", time.Now().Format("2006年01"))
  510. }
  511. jsonData, err := json.Marshal(remarksMap)
  512. if err != nil {
  513. fmt.Println(err)
  514. }
  515. remarks = string(jsonData)
  516. detailed := entity.Detailed{
  517. AccountId: accountId,
  518. ResourceType: "附件下载包",
  519. Number: number,
  520. Name: "附件下载包",
  521. CreateTime: time.Now().Local(),
  522. Remarks: remarks,
  523. UserType: userType,
  524. }
  525. orm.Table(ConsumeRecord).Insert(&detailed)
  526. //jie结存清空
  527. updataMap := map[string]interface{}{
  528. "number": 0,
  529. }
  530. orm.Table(AccountResources).
  531. Cols("number").Where("id =? ", resourcesId).
  532. Update(&updataMap)
  533. }
  534. }