附近小店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

db_sys_mod.go 25 KiB

2 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/e"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "errors"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "github.com/gin-gonic/gin"
  12. "github.com/tidwall/gjson"
  13. "xorm.io/xorm"
  14. )
  15. // 返回所有, 不管是否显示
  16. func SysModFindAll(Db *xorm.Engine) (*[]model.SysModule, error) {
  17. var m []model.SysModule
  18. if err := Db.Find(&m); err != nil {
  19. return nil, err
  20. }
  21. return &m, nil
  22. }
  23. // 查找主模块数据
  24. func SysModFindMain(Db *xorm.Engine) (*[]model.SysModule, error) {
  25. var m []model.SysModule
  26. if err := Db.Where("mod_pid = 0 AND state = 1 AND position = 'base'").
  27. Asc("sort").
  28. Find(&m); err != nil {
  29. return nil, err
  30. }
  31. return &m, nil
  32. }
  33. // 用父ID查找子模块数据
  34. func SysModFindByPId(c *gin.Context, Db *xorm.Engine, id int) (*[]model.SysModule, error) {
  35. var m []model.SysModule
  36. if err := Db.Where("state = 1").Where("mod_pid = ?", id).
  37. Asc("sort").
  38. Find(&m); err != nil {
  39. return nil, err
  40. }
  41. mm, err := sysModFormat(c, &m)
  42. if err != nil {
  43. return nil, err
  44. }
  45. var ms []model.SysModule
  46. modname_list := []string{"product", "search_result_taobao_item", "hot_rank_tab_view"}
  47. for _, item := range *mm.(*[]model.SysModule) {
  48. if item.ModName == "product_detail_title" {
  49. if strings.Contains(item.Data, "tmall") == false {
  50. item.Data = strings.Replace(item.Data, "\"platform_css\":[", "\"platform_css\":[{\"name\":\"天猫\",\"type\":\"tmall\",\"text_color\":\"#FFFFFF\",\"bg_color\":\"#FF4242\"},", 1)
  51. }
  52. if strings.Contains(item.Data, "kuaishou") == false {
  53. item.Data = strings.Replace(item.Data, "\"platform_css\":[", "\"platform_css\":[{\"name\":\"快手\",\"type\":\"kuaishou\",\"text_color\":\"#FFFFFF\",\"bg_color\":\"#FF4242\"},", 1)
  54. }
  55. if strings.Contains(item.Data, "tikTok") == false {
  56. item.Data = strings.Replace(item.Data, "\"platform_css\":[", "\"platform_css\":[{\"name\":\"抖音\",\"type\":\"tikTok\",\"text_color\":\"#FFFFFF\",\"bg_color\":\"#FF4242\"},", 1)
  57. }
  58. }
  59. if strings.Contains(item.Data, "tmall") == false && utils.InArr(item.ModName, modname_list) {
  60. item.Data = strings.Replace(item.Data, "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"index\":\"7\",\"type\":\"tmall\",\"platform_name\":\"天猫\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1)
  61. item.Data = strings.Replace(item.Data, "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"type\":\"tmall\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1)
  62. }
  63. if strings.Contains(item.Data, "优惠卷") {
  64. item.Data = strings.Replace(item.Data, "优惠卷", "优惠券", -1)
  65. }
  66. item.Data = strings.ReplaceAll(item.Data, "\\/", "/")
  67. item.Data = strings.ReplaceAll(item.Data, "\\u0026", "&")
  68. ms = append(ms, item)
  69. }
  70. return &ms, nil
  71. }
  72. // 用父ID查找子模块数据
  73. func SysModFindByPIds(c *gin.Context, Db *xorm.Engine, ids ...int) (*[]model.SysModule, error) {
  74. var m []model.SysModule
  75. if err := Db.In("mod_pid", ids).Where("state = 1").
  76. Asc("sort").
  77. Find(&m); err != nil {
  78. return nil, err
  79. }
  80. mm, err := sysModFormat(c, &m)
  81. if err != nil {
  82. return nil, err
  83. }
  84. var ms []model.SysModule
  85. for _, item := range *mm.(*[]model.SysModule) {
  86. //数据里面
  87. if strings.Contains(item.Data, "tmall") == false && item.ModName == "product" {
  88. item.Data = strings.Replace(item.Data, "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"index\":\"7\",\"type\":\"tmall\",\"platform_name\":\"天猫\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1)
  89. }
  90. item = SysModDataByReplace(c, item)
  91. ms = append(ms, item)
  92. }
  93. return &ms, nil
  94. }
  95. // 用IDS找对应模块数据
  96. func SysModFindByIds(Db *xorm.Engine, ids ...int) (*[]model.SysModule, error) {
  97. var m []model.SysModule
  98. if err := Db.In("mod_id", ids).Where("state = 1").
  99. Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort").
  100. Asc("sort").Find(&m); err != nil {
  101. return nil, err
  102. }
  103. return &m, nil
  104. }
  105. // ID查找对应模块
  106. func SysModFindById(c *gin.Context, Db *xorm.Engine, id string) (*model.SysModule, error) {
  107. var m model.SysModule
  108. if has, err := Db.Where("state = 1 AND mod_id = ?", id).
  109. Get(&m); err != nil || has == false {
  110. return nil, logx.Warn(err)
  111. }
  112. mm, err := sysModFormat(c, &m)
  113. if err != nil {
  114. return nil, err
  115. }
  116. return mm.(*model.SysModule), nil
  117. }
  118. // SysModFindByTmpId is 根据模板
  119. func SysModFindByTmpId(c *gin.Context, Db *xorm.Engine, id string) (*model.SysModule, error) {
  120. var m model.SysModule
  121. if has, err := Db.Where("state = 1 AND template_id = ?", id).
  122. Get(&m); err != nil || has == false {
  123. return nil, logx.Warn(err)
  124. }
  125. mm, err := sysModFormat(c, &m)
  126. if err != nil {
  127. return nil, err
  128. }
  129. return mm.(*model.SysModule), nil
  130. }
  131. // Name查找对应模块
  132. func SysModFindByName(c *gin.Context, Db *xorm.Engine, name string) (*model.SysModule, error) {
  133. var m model.SysModule
  134. if has, err := Db.Where("state = 1 AND mod_name = ?", name).
  135. Get(&m); err != nil || has == false {
  136. return nil, logx.Warn(err)
  137. }
  138. mm, err := sysModFormat(c, &m)
  139. if err != nil {
  140. return nil, err
  141. }
  142. return mm.(*model.SysModule), nil
  143. }
  144. // SysModFindByName is Name查找对应模块
  145. func SysModFindByNames(names ...string) (*[]model.SysModule, error) {
  146. var m []model.SysModule
  147. if err := Db.In("mod_name", names).Where("state = 1").
  148. Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort").
  149. Find(&m); err != nil {
  150. return nil, err
  151. }
  152. return &m, nil
  153. }
  154. // SysModFindByPosition is 根据位置查找对应模块
  155. func SysModFindByPosition(Db *xorm.Engine, positions ...string) (*[]model.SysModule, error) {
  156. var m []model.SysModule
  157. if err := Db.In("position", positions).Where("state = 1").Find(&m); err != nil {
  158. return nil, err
  159. }
  160. return &m, nil
  161. }
  162. // 根据跳转标识 查找对应模块
  163. func SysModFindBySkipIdentifier(c *gin.Context, Db *xorm.Engine, name string) (*model.SysModule, error) {
  164. var m model.SysModule
  165. if has, err := Db.Where("state = 1 AND skip_identifier = ?", name).
  166. Get(&m); err != nil || has == false {
  167. return nil, logx.Warn(err)
  168. }
  169. mm, err := sysModFormat(c, &m)
  170. if err != nil {
  171. return nil, err
  172. }
  173. return mm.(*model.SysModule), nil
  174. }
  175. func SysModFindBySkipIdentifierWithUid(c *gin.Context, Db *xorm.Engine, name string, uid int) (*model.SysModule, error) {
  176. var m model.SysModule
  177. if has, err := Db.Where("state = 1 AND skip_identifier = ? and uid=?", name, uid).
  178. Get(&m); err != nil || has == false {
  179. return nil, logx.Warn(err)
  180. }
  181. mm, err := sysModFormat(c, &m)
  182. if err != nil {
  183. return nil, err
  184. }
  185. return mm.(*model.SysModule), nil
  186. }
  187. // 根据跳转标识和位置 查找对应模块list
  188. func SysModFindBySkipIdentifierAndPosition(c *gin.Context, Db *xorm.Engine, name string, position string) (*[]model.SysModule, error) {
  189. var m []model.SysModule
  190. if err := Db.Where("state = 1 AND skip_identifier = ? AND position = ?", name, position).
  191. Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort").
  192. Asc("sort").Find(&m); err != nil {
  193. return nil, err
  194. }
  195. mm, err := sysModFormat(c, &m)
  196. if err != nil {
  197. return nil, err
  198. }
  199. return mm.(*[]model.SysModule), nil
  200. }
  201. func SysModFindByTempId(Db *xorm.Engine, ids []int) (*[]model.SysModule, error) {
  202. var m []model.SysModule
  203. if err := Db.Where("state = 1 ").In("template_id", ids).Asc("sort").Find(&m); err != nil {
  204. return nil, err
  205. }
  206. return &m, nil
  207. }
  208. // SysModFindByTemplateIDAndSkip is 根据模板id 查找对应模块
  209. func SysModFindByTemplateIDAndSkip(Db *xorm.Engine, id interface{}, skip string) (*model.SysModule, error) {
  210. var m model.SysModule
  211. if has, err := Db.Where("state = 1 AND template_id = ? AND skip_identifier = ?", id, skip).
  212. Get(&m); err != nil || has == false {
  213. return nil, logx.Warn(err)
  214. }
  215. return &m, nil
  216. }
  217. // SysModFindByTemplateIDAndPID is 根据模板id 和pid =0 查找父模块
  218. func SysModFindByTemplateIDAndPID(Db *xorm.Engine, id interface{}, pid interface{}) (*model.SysModule, error) {
  219. var m model.SysModule
  220. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_pid = ?", id, pid).
  221. Get(&m); err != nil || has == false {
  222. return nil, logx.Warn(err)
  223. }
  224. return &m, nil
  225. }
  226. // SysModFindByTemplateIDAndModName is 根据模板id 和mod name 查找模块
  227. func SysModFindByTemplateIDAndModName(Db *xorm.Engine, id interface{}, modName string) (*model.SysModule, error) {
  228. var m model.SysModule
  229. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = ?", id, modName).
  230. Get(&m); err != nil || has == false {
  231. return nil, logx.Warn(err)
  232. }
  233. return &m, nil
  234. }
  235. func SysModFindByTemplateIDAndModNameWithIds(Db *xorm.Engine, ids []int, modName string) (*model.SysModule, error) {
  236. var m model.SysModule
  237. if has, err := Db.In("template_id", ids).And(" mod_name = ?", modName).
  238. Get(&m); err != nil || has == false {
  239. return nil, logx.Warn(err)
  240. }
  241. return &m, nil
  242. }
  243. // SysModFindNavIsUsed 查找正在使用的底部导航栏模板
  244. func SysModFindNavIsUsedByPlatform(c *gin.Context, Db *xorm.Engine, platform string) (*model.SysModule, error) {
  245. var (
  246. tm model.SysTemplate
  247. m model.SysModule
  248. )
  249. mid := c.GetString("mid")
  250. fmt.Println("===================================app_type", c.GetString("app_type"))
  251. if c.GetString("app_type") != "" && c.GetString("app_type") != "daogou" {
  252. var (
  253. tempType string
  254. )
  255. switch c.GetString("app_type") {
  256. case "o2o":
  257. tempType = "o2o_store_bottomNav"
  258. }
  259. switch platform {
  260. case "ios":
  261. if has, err := Db.Where("is_use = 1 AND type = ? AND platform = 2 ", tempType).
  262. Cols("id,uid,name,is_use,is_system").
  263. Get(&tm); err != nil || has == false {
  264. return nil, logx.Warn(err)
  265. }
  266. appVersion := GetCloudBuild(c, platform)
  267. if c.GetHeader("app_version_name") == appVersion && c.GetHeader("app_version_name") != "" {
  268. m, err := GetCloudBundleByVersion(Db, appVersion, 2, 1)
  269. if err != nil {
  270. return nil, logx.Warn(err)
  271. }
  272. tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int())
  273. }
  274. case "android":
  275. has, err := Db.Where("is_use = 1 AND type = ? AND platform = 2 ", tempType).Cols("id,uid,name,is_use,is_system").Get(&tm)
  276. if err != nil || has == false {
  277. return nil, logx.Warn(err)
  278. }
  279. fmt.Println("===================================app_type", tm)
  280. appVersion := GetCloudBuild(c, platform)
  281. fmt.Println("===================================app_type", appVersion)
  282. if appVersion != "" && c.GetHeader("app_version_name") == appVersion {
  283. m, err := GetCloudBundleByVersion(Db, appVersion, 1, 1)
  284. if err != nil {
  285. return nil, logx.Warn(err)
  286. }
  287. fmt.Println("===================================app_type", m)
  288. tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int())
  289. }
  290. case "wx_applet", "wap":
  291. if has, err := Db.Where("is_use = 1 AND type = ? AND platform = 4 ", tempType).
  292. Cols("id,uid,name,is_use,is_system").
  293. Get(&tm); err != nil || has == false {
  294. return nil, logx.Warn(err)
  295. }
  296. case "baidu_applet":
  297. if has, err := Db.Where("is_use = 1 AND type = ? AND platform = 4 ", tempType).
  298. Cols("id,uid,name,is_use,is_system").
  299. Get(&tm); err != nil || has == false {
  300. return nil, logx.Warn(err)
  301. }
  302. case "toutiao_applet":
  303. if has, err := Db.Where("is_use = 1 AND type = ? AND platform = 4 ", tempType).
  304. Cols("id,uid,name,is_use,is_system").
  305. Get(&tm); err != nil || has == false {
  306. return nil, logx.Warn(err)
  307. }
  308. case "alipay_applet":
  309. if has, err := Db.Where("is_use = 1 AND type = ? AND platform = 4 ", tempType).
  310. Cols("id,uid,name,is_use,is_system").
  311. Get(&tm); err != nil || has == false {
  312. return nil, logx.Warn(err)
  313. }
  314. default:
  315. return &m, errors.New("Platform not support")
  316. }
  317. if has, err := Db.Where("state = 1 AND template_id = ?", tm.Id).
  318. Get(&m); err != nil || has == false {
  319. return nil, logx.Warn(err)
  320. }
  321. fmt.Println("===================================app_type", m)
  322. if tempType == "o2o_store_bottomNav" {
  323. bottomMap := make(map[string]interface{})
  324. utils.Unserialize([]byte(m.Data), &bottomMap)
  325. list, ok := bottomMap["list"]
  326. if ok {
  327. m.Data = string(utils.MarshalJSONCamelCase2JsonSnakeCase(utils.SerializeStr(list)))
  328. }
  329. }
  330. mm, err := sysModFormat(c, &m)
  331. if err != nil {
  332. return nil, err
  333. }
  334. return mm.(*model.SysModule), nil
  335. }
  336. switch platform {
  337. case "ios":
  338. if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 2 ").
  339. Cols("id,uid,name,is_use,is_system").
  340. Get(&tm); err != nil || has == false {
  341. return nil, logx.Warn(err)
  342. }
  343. appVersion := GetCloudBuild(c, platform)
  344. if c.GetHeader("app_version_name") == appVersion && c.GetHeader("app_version_name") != "" {
  345. m, err := GetCloudBundleByVersion(Db, appVersion, 2, 0)
  346. if err != nil {
  347. return nil, logx.Warn(err)
  348. }
  349. tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int())
  350. }
  351. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id).
  352. Get(&m); err != nil || has == false {
  353. return nil, logx.Warn(err)
  354. }
  355. mm, err := sysModFormat(c, &m)
  356. if err != nil {
  357. return nil, err
  358. }
  359. return mm.(*model.SysModule), nil
  360. case "android":
  361. has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 2 ").Cols("id,uid,name,is_use,is_system").Get(&tm)
  362. if err != nil || has == false {
  363. return nil, logx.Warn(err)
  364. }
  365. appVersion := GetCloudBuild(c, platform)
  366. if appVersion != "" && c.GetHeader("app_version_name") == appVersion {
  367. m, err := GetCloudBundleByVersion(Db, appVersion, 1, 0)
  368. if err != nil {
  369. return nil, logx.Warn(err)
  370. }
  371. tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int())
  372. }
  373. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id).
  374. Get(&m); err != nil || has == false {
  375. return nil, logx.Warn(err)
  376. }
  377. mm, err := sysModFormat(c, &m)
  378. if err != nil {
  379. return nil, err
  380. }
  381. return mm.(*model.SysModule), nil
  382. case "wx_applet", "wap":
  383. wxAppletCfg := GetAppletKey(c, Db)
  384. id := utils.StrToInt(wxAppletCfg["bottom_nav_css_id"])
  385. if id == 0 {
  386. return nil, e.NewErr(400, "找不到模板配置")
  387. }
  388. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", id).
  389. Get(&m); err != nil || has == false {
  390. return nil, logx.Warn(err)
  391. }
  392. mm, err := sysModFormat(c, &m)
  393. if err != nil {
  394. return nil, err
  395. }
  396. return mm.(*model.SysModule), nil
  397. case "baidu_applet":
  398. if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 ").
  399. Cols("id,uid,name,is_use,is_system").
  400. Get(&tm); err != nil || has == false {
  401. return nil, logx.Warn(err)
  402. }
  403. appVersion := SysCfgGetWithDb(Db, mid, "baidu_audit_version")
  404. if appVersion != "" && c.GetHeader("app_version_name") == appVersion {
  405. m := SysCfgGetWithDb(Db, mid, "baidu_audit_template")
  406. if m == "" {
  407. return nil, e.NewErr(400, "找不到模板配置")
  408. }
  409. tm.Id = int(gjson.Get(m, "bottom").Int())
  410. }
  411. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id).
  412. Get(&m); err != nil || has == false {
  413. return nil, logx.Warn(err)
  414. }
  415. mm, err := sysModFormat(c, &m)
  416. if err != nil {
  417. return nil, err
  418. }
  419. return mm.(*model.SysModule), nil
  420. case "toutiao_applet":
  421. if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 ").
  422. Cols("id,uid,name,is_use,is_system").
  423. Get(&tm); err != nil || has == false {
  424. return nil, logx.Warn(err)
  425. }
  426. appVersion := SysCfgGetWithDb(Db, mid, "tt_audit_version")
  427. if appVersion != "" && c.GetHeader("app_version_name") == appVersion {
  428. m := SysCfgGetWithDb(Db, mid, "tt_audit_template")
  429. if m == "" {
  430. return nil, errors.New("找不到模板配置")
  431. }
  432. tm.Id = int(gjson.Get(m, "bottom").Int())
  433. }
  434. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id).
  435. Get(&m); err != nil || has == false {
  436. return nil, logx.Warn(err)
  437. }
  438. mm, err := sysModFormat(c, &m)
  439. if err != nil {
  440. return nil, err
  441. }
  442. return mm.(*model.SysModule), nil
  443. case "alipay_applet":
  444. if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 ").
  445. Cols("id,uid,name,is_use,is_system").
  446. Get(&tm); err != nil || has == false {
  447. return nil, logx.Warn(err)
  448. }
  449. appVersion := SysCfgGetWithDb(Db, mid, "zfb_audit_version")
  450. if appVersion != "" && c.GetHeader("app_version_name") == appVersion {
  451. m := SysCfgGetWithDb(Db, mid, "zfb_audit_template")
  452. if m == "" {
  453. return nil, errors.New("找不到模板配置")
  454. }
  455. tm.Id = int(gjson.Get(m, "bottom").Int())
  456. }
  457. if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id).
  458. Get(&m); err != nil || has == false {
  459. return nil, logx.Warn(err)
  460. }
  461. mm, err := sysModFormat(c, &m)
  462. if err != nil {
  463. return nil, err
  464. }
  465. return mm.(*model.SysModule), nil
  466. default:
  467. return &m, errors.New("Platform not support")
  468. }
  469. }
  470. // SysModFindBySkipIdentifierAndModName is 根据mod_name和位置 查找对应模块
  471. func SysModFindBySkipIdentifierAndModName(c *gin.Context, Db *xorm.Engine, name string, modName string) (*model.SysModule, error) {
  472. var m model.SysModule
  473. if has, err := Db.Where("state = 1 AND skip_identifier = ? AND mod_name = ?", name, modName).Get(&m); err != nil || !has {
  474. return nil, logx.Warn(err)
  475. }
  476. mm, err := sysModFormat(c, &m)
  477. if err != nil {
  478. return nil, err
  479. }
  480. return mm.(*model.SysModule), nil
  481. }
  482. // SysModFindByModName is 根据mod_name和位置 查找对应模块
  483. func SysModFindByModName(c *gin.Context, Db *xorm.Engine, modName string) (*model.SysModule, error) {
  484. var m model.SysModule
  485. if has, err := Db.Where("state = 1 AND mod_name = ?", modName).Get(&m); err != nil || !has {
  486. return nil, logx.Warn(err)
  487. }
  488. mm, err := sysModFormat(c, &m)
  489. if err != nil {
  490. return nil, err
  491. }
  492. return mm.(*model.SysModule), nil
  493. }
  494. // 根据跳转标识和平台类型查找
  495. func SysModFindBySkipIdentifierAndPlatform(c *gin.Context, Db *xorm.Engine, name string, platform int) (*model.SysModule, error) {
  496. var m model.SysModule
  497. if has, err := Db.Where("state = 1 AND skip_identifier = ? AND platform = ?", name, platform).Get(&m); err != nil || !has {
  498. return nil, logx.Warn(err)
  499. }
  500. mm, err := sysModFormat(c, &m)
  501. if err != nil {
  502. return nil, err
  503. }
  504. return mm.(*model.SysModule), nil
  505. }
  506. // 公共处理modData的链接
  507. func SysModDataByReplace(c *gin.Context, mod model.SysModule) model.SysModule {
  508. //替换链接的一些参数
  509. if strings.Contains(mod.Data, "[replace_APP_URL]") {
  510. mod.Data = strings.Replace(mod.Data, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1)
  511. }
  512. if strings.Contains(mod.Data, "[replace_masterId]") {
  513. mod.Data = strings.Replace(mod.Data, "[replace_masterId]", c.GetString("mid"), -1)
  514. }
  515. if strings.Contains(mod.Data, "[replace_platform]") {
  516. mod.Data = strings.Replace(mod.Data, "[replace_platform]", c.GetHeader("Platform"), -1)
  517. }
  518. if strings.Contains(mod.Data, "优惠卷") {
  519. mod.Data = strings.Replace(mod.Data, "优惠卷", "优惠券", -1)
  520. }
  521. if strings.Contains(mod.Data, "[replace_uid]") {
  522. token := c.GetHeader("Authorization")
  523. // 按空格分割
  524. parts := strings.SplitN(token, " ", 2)
  525. if len(parts) == 2 && parts[0] == "Bearer" {
  526. // parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它
  527. mc, _ := utils.ParseToken(parts[1])
  528. mod.Data = strings.Replace(mod.Data, "[replace_uid]", strconv.Itoa(mc.UID), -1)
  529. }
  530. }
  531. //if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") {
  532. // //如果存在这两个字段,要换一下
  533. // mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id")
  534. // mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id")
  535. //}
  536. return mod
  537. }
  538. // 公共处理modData的链接
  539. func StringByReplace(c *gin.Context, skip string) string {
  540. //替换链接的一些参数
  541. if strings.Contains(skip, "[replace_APP_URL]") {
  542. skip = strings.Replace(skip, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1)
  543. }
  544. if strings.Contains(skip, "[replace_masterId]") {
  545. skip = strings.Replace(skip, "[replace_masterId]", c.GetString("mid"), -1)
  546. }
  547. if strings.Contains(skip, "[replace_platform]") {
  548. skip = strings.Replace(skip, "[replace_platform]", c.GetHeader("Platform"), -1)
  549. }
  550. if strings.Contains(skip, "优惠卷") {
  551. skip = strings.Replace(skip, "优惠卷", "优惠券", -1)
  552. }
  553. if strings.Contains(skip, "[replace_uid]") {
  554. token := c.GetHeader("Authorization")
  555. // 按空格分割
  556. parts := strings.SplitN(token, " ", 2)
  557. if len(parts) == 2 && parts[0] == "Bearer" {
  558. // parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它
  559. mc, _ := utils.ParseToken(parts[1])
  560. skip = strings.Replace(skip, "[replace_uid]", strconv.Itoa(mc.UID), -1)
  561. }
  562. }
  563. //if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") {
  564. // //如果存在这两个字段,要换一下
  565. // mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id")
  566. // mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id")
  567. //}
  568. return skip
  569. }
  570. // 公共处理modSkip的链接 首页弹窗
  571. func SysModSkipByReplace(c *gin.Context, mod *model.SysPopup) *model.SysPopup {
  572. //替换链接的一些参数
  573. if strings.Contains(mod.Skip, "[replace_APP_URL]") {
  574. mod.Skip = strings.Replace(mod.Skip, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1)
  575. }
  576. if strings.Contains(mod.Skip, "[replace_masterId]") {
  577. mod.Skip = strings.Replace(mod.Skip, "[replace_masterId]", c.GetString("mid"), -1)
  578. }
  579. if strings.Contains(mod.Skip, "[replace_platform]") {
  580. mod.Skip = strings.Replace(mod.Skip, "[replace_platform]", c.GetHeader("Platform"), -1)
  581. }
  582. if strings.Contains(mod.Skip, "优惠卷") {
  583. mod.Skip = strings.Replace(mod.Skip, "优惠卷", "优惠券", -1)
  584. }
  585. if strings.Contains(mod.Skip, "[replace_uid]") {
  586. token := c.GetHeader("Authorization")
  587. // 按空格分割
  588. parts := strings.SplitN(token, " ", 2)
  589. if len(parts) == 2 && parts[0] == "Bearer" {
  590. // parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它
  591. mc, _ := utils.ParseToken(parts[1])
  592. mod.Skip = strings.Replace(mod.Skip, "[replace_uid]", strconv.Itoa(mc.UID), -1)
  593. }
  594. }
  595. //if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") {
  596. // //如果存在这两个字段,要换一下
  597. // mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id")
  598. // mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id")
  599. //}
  600. return mod
  601. }
  602. // 公共处理modData的链接
  603. func SysModDataByReplaceSecond(c *gin.Context, mod *model.SysModule) *model.SysModule {
  604. //替换链接的一些参数
  605. if strings.Contains(mod.Data, "[replace_APP_URL]") {
  606. mod.Data = strings.Replace(mod.Data, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1)
  607. }
  608. if strings.Contains(mod.Data, "[replace_masterId]") {
  609. mod.Data = strings.Replace(mod.Data, "[replace_masterId]", c.GetString("mid"), -1)
  610. }
  611. if strings.Contains(mod.Data, "优惠卷") {
  612. mod.Data = strings.Replace(mod.Data, "优惠卷", "优惠券", -1)
  613. }
  614. if strings.Contains(mod.Data, "[replace_uid]") {
  615. token := c.GetHeader("Authorization")
  616. // 按空格分割
  617. parts := strings.SplitN(token, " ", 2)
  618. if len(parts) == 2 && parts[0] == "Bearer" {
  619. // parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它
  620. mc, _ := utils.ParseToken(parts[1])
  621. if mc == nil {
  622. mod.Data = strings.Replace(mod.Data, "[replace_uid]", "0", -1)
  623. } else {
  624. mod.Data = strings.Replace(mod.Data, "[replace_uid]", strconv.Itoa(mc.UID), -1)
  625. }
  626. }
  627. }
  628. if mod.ModName == "product" && strings.Contains(mod.Data, "product_3") {
  629. if strings.Contains(mod.Data, "second_kill_style") == false {
  630. mod.Data = strings.ReplaceAll(mod.Data, "\"coupon_commission\"", "\"second_kill_style\":{\"btn_bg_img\":\"http://ossn.izhim.net/gift.png\",\"left_stock_text_color\":\"#D59E21\",\"buy_now_text_color\":\"#D59E21\",\"is_show\":\"0\"},\"coupon_commission\"")
  631. }
  632. }
  633. mod.Data = strings.ReplaceAll(mod.Data, "\\/", "/")
  634. mod.Data = strings.ReplaceAll(mod.Data, "\\u0026", "&")
  635. //if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") {
  636. // //如果存在这两个字段,要换一下
  637. // mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id")
  638. // mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id")
  639. //}
  640. return mod
  641. }