price_driven.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. package yb
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/yb/request"
  8. "hongze/hz_crm_api/models/yb/response"
  9. "hongze/hz_crm_api/services/yb"
  10. "hongze/hz_crm_api/utils"
  11. )
  12. // PriceDrivenController 价格驱动模块
  13. type PriceDrivenController struct {
  14. controllers.BaseAuthController
  15. }
  16. // GetPriceDrivenDetail
  17. // @Title 获取价格驱动详情
  18. // @Description 获取价格驱动详情
  19. // @Param VarietyTagId query int false "标签ID"
  20. // @Success 200 {object} response.PriceDrivenDetail
  21. // @router /price_driven/detail [get]
  22. func (this *PriceDrivenController) GetPriceDrivenDetail() {
  23. br := new(models.BaseResponse).Init()
  24. br.IsSendEmail = false
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. varietyTagId, _ := this.GetInt("VarietyTagId")
  37. if varietyTagId <= 0 {
  38. br.Msg = "参数有误"
  39. br.ErrMsg = "参数有误"
  40. return
  41. }
  42. detail, msg, err := yb.GetPriceDrivenDetail(varietyTagId)
  43. if err != nil {
  44. br.Msg = msg
  45. br.ErrMsg = "获取价格驱动详情失败, Err:" + err.Error()
  46. return
  47. }
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = detail
  52. }
  53. // UpdatePriceDriven
  54. // @Title 更新价格驱动
  55. // @Description 更新价格驱动
  56. // @Param request body request.UpdatePriceDrivenReq true "type json string"
  57. // @Success 200 {object} response.PriceDrivenDetail
  58. // @router /price_driven/update [post]
  59. func (this *PriceDrivenController) UpdatePriceDriven() {
  60. br := new(models.BaseResponse).Init()
  61. br.IsSendEmail = false
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. sysUser := this.SysUser
  67. if sysUser == nil {
  68. br.Msg = "请登录"
  69. br.ErrMsg = "请登录,SysUser Is Empty"
  70. br.Ret = 408
  71. return
  72. }
  73. var req request.UpdatePriceDrivenReq
  74. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  75. br.Msg = "参数解析异常!"
  76. br.ErrMsg = "参数解析失败, Err:" + err.Error()
  77. return
  78. }
  79. if req.VarietyTagId <= 0 {
  80. br.Msg = "参数有误"
  81. return
  82. }
  83. if req.AutoSave != 1 {
  84. if req.MainVariable == "" {
  85. br.Msg = "请输入关键变量"
  86. return
  87. }
  88. if req.CoreDrivenContent == "" {
  89. br.Msg = "请输入核心驱动"
  90. return
  91. }
  92. if req.CoreContent == "" {
  93. br.Msg = "请输入核心内容"
  94. return
  95. }
  96. }
  97. detail, msg, err := yb.UpdatePriceDriven(req)
  98. if err != nil {
  99. br.Msg = msg
  100. br.ErrMsg = "更新价格驱动失败, Err:" + err.Error()
  101. return
  102. }
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "操作成功"
  106. br.Data = detail
  107. }
  108. // GetPriceDrivenPermissionTree
  109. // @Title 获取价格驱动分类列表
  110. // @Description 获取价格驱动分类列表
  111. // @Success 200 {object} response.ChartPermissionTree
  112. // @router /price_driven/permission_tree [get]
  113. func (this *PriceDrivenController) GetPriceDrivenPermissionTree() {
  114. br := new(models.BaseResponse).Init()
  115. br.IsSendEmail = false
  116. defer func() {
  117. this.Data["json"] = br
  118. this.ServeJSON()
  119. }()
  120. sysUser := this.SysUser
  121. if sysUser == nil {
  122. br.Msg = "请登录"
  123. br.ErrMsg = "请登录,SysUser Is Empty"
  124. br.Ret = 408
  125. return
  126. }
  127. list, err := yb.GetPriceDrivenPermissionTree()
  128. if err != nil {
  129. br.Msg = "获取失败"
  130. br.ErrMsg = "获取价格驱动分类列表失败, Err:" + err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "获取成功"
  136. br.Data = list
  137. }
  138. // SwitchPriceDrivenPermissionState
  139. // @Title 切换价格驱动分类状态
  140. // @Description 切换价格驱动分类状态
  141. // @Param request body request.SwitchPriceDrivenPermissionStateReq true "type json string"
  142. // @Success 200 string "操作成功"
  143. // @router /price_driven/switch_permission_state [post]
  144. func (this *PriceDrivenController) SwitchPriceDrivenPermissionState() {
  145. br := new(models.BaseResponse).Init()
  146. br.IsSendEmail = false
  147. defer func() {
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. sysUser := this.SysUser
  152. if sysUser == nil {
  153. br.Msg = "请登录"
  154. br.ErrMsg = "请登录,SysUser Is Empty"
  155. br.Ret = 408
  156. return
  157. }
  158. var req request.SwitchPriceDrivenPermissionStateReq
  159. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  160. br.Msg = "参数解析异常!"
  161. br.ErrMsg = "参数解析失败, Err:" + err.Error()
  162. return
  163. }
  164. if req.VarietyTagId <= 0 {
  165. br.Msg = "参数有误"
  166. return
  167. }
  168. msg, err := yb.SwitchPriceDrivenPermissionState(req.VarietyTagId, req.PriceDrivenState)
  169. if err != nil {
  170. br.Msg = msg
  171. br.ErrMsg = "切换价格驱动分类状态失败, Err:" + err.Error()
  172. return
  173. }
  174. br.Ret = 200
  175. br.Success = true
  176. br.Msg = "操作成功"
  177. }
  178. // SendPriceDrivenTemplateMsg
  179. // @Title 推送价格驱动模板消息
  180. // @Description 推送价格驱动模板消息
  181. // @Param request body request.PriceDrivenSendMsgReq true "type json string"
  182. // @Success 200 string "操作成功"
  183. // @router /price_driven/send_template_msg [post]
  184. func (this *PriceDrivenController) SendPriceDrivenTemplateMsg() {
  185. br := new(models.BaseResponse).Init()
  186. br.IsSendEmail = false
  187. defer func() {
  188. this.Data["json"] = br
  189. this.ServeJSON()
  190. }()
  191. sysUser := this.SysUser
  192. if sysUser == nil {
  193. br.Msg = "请登录"
  194. br.ErrMsg = "请登录,SysUser Is Empty"
  195. br.Ret = 408
  196. return
  197. }
  198. var req request.PriceDrivenSendMsgReq
  199. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  200. br.Msg = "参数解析异常!"
  201. br.ErrMsg = "参数解析失败, Err:" + err.Error()
  202. return
  203. }
  204. if req.PriceDrivenId <= 0 {
  205. br.Msg = "参数有误"
  206. return
  207. }
  208. msg, err := yb.SendPriceDrivenTemplateMsg(req.PriceDrivenId)
  209. if err != nil {
  210. br.Msg = msg
  211. br.ErrMsg = "推送价格驱动模板消息失败, Err:" + err.Error()
  212. return
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "操作成功"
  217. }
  218. // SendPriceDrivenThsMsg
  219. // @Title 推送价格驱动同花顺客群消息
  220. // @Description 推送价格驱动同花顺客群消息
  221. // @Param request body request.PriceDrivenSendMsgReq true "type json string"
  222. // @Success 200 string "操作成功"
  223. // @router /price_driven/send_ths_msg [post]
  224. func (this *PriceDrivenController) SendPriceDrivenThsMsg() {
  225. br := new(models.BaseResponse).Init()
  226. br.IsSendEmail = false
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. sysUser := this.SysUser
  232. if sysUser == nil {
  233. br.Msg = "请登录"
  234. br.ErrMsg = "请登录,SysUser Is Empty"
  235. br.Ret = 408
  236. return
  237. }
  238. var req request.PriceDrivenSendMsgReq
  239. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  240. br.Msg = "参数解析异常!"
  241. br.ErrMsg = "参数解析失败, Err:" + err.Error()
  242. return
  243. }
  244. if req.PriceDrivenId <= 0 {
  245. br.Msg = "参数有误"
  246. return
  247. }
  248. msg, err := yb.SendPriceDrivenThsMsg(req.PriceDrivenId)
  249. if err != nil {
  250. br.Msg = msg
  251. br.ErrMsg = "推送价格驱动客群消息失败, Err:" + err.Error()
  252. return
  253. }
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "操作成功"
  257. }
  258. // ClickCensusList
  259. // @Title 价格驱动点击量列表
  260. // @Description 价格驱动点击量列表
  261. // @Param SortField query int false "排序字段:1-按照累计点击量排序(默认) 2-按照最近点击量排序"
  262. // @Param SortRule query int false "排序规则:1-升序 2-降序"
  263. // @Success 200 {object} response.PriceDrivenClickCensusResp
  264. // @router /price_driven/click_census_list [get]
  265. func (this *PriceDrivenController) ClickCensusList() {
  266. br := new(models.BaseResponse).Init()
  267. defer func() {
  268. this.Data["json"] = br
  269. this.ServeJSON()
  270. }()
  271. sysUser := this.SysUser
  272. if sysUser == nil {
  273. br.Msg = "请登录"
  274. br.ErrMsg = "请登录,SysUser Is Empty"
  275. br.Ret = 408
  276. return
  277. }
  278. sortField, _ := this.GetInt("SortField")
  279. sortRule, _ := this.GetInt("SortRule")
  280. var startSize int
  281. pageSize, _ := this.GetInt("PageSize")
  282. currentIndex, _ := this.GetInt("CurrentIndex")
  283. if pageSize <= 0 {
  284. pageSize = utils.PageSize20
  285. }
  286. if currentIndex <= 0 {
  287. currentIndex = 1
  288. }
  289. startSize = paging.StartIndex(currentIndex, pageSize)
  290. resp := new(response.PriceDrivenClickCensusResp)
  291. total, list, err := yb.GetPriceDrivenClickCensusList(startSize, pageSize, sortField, sortRule)
  292. if err != nil {
  293. br.Msg = "获取点击量统计列表失败"
  294. br.ErrMsg = "获取价格驱动统计列表失败-ClickCensusList ErrMsg:" + err.Error()
  295. return
  296. }
  297. resp.List = list
  298. page := paging.GetPaging(currentIndex, pageSize, int(total))
  299. resp.Paging = page
  300. br.Ret = 200
  301. br.Success = true
  302. br.Msg = "获取成功"
  303. br.Data = resp
  304. }
  305. // ClickCensusDetail
  306. // @Title 价格驱动点击量详情
  307. // @Description 价格驱动点击量详情
  308. // @Param VarietyTagId query int false "标签ID:查询累计点击量详情"
  309. // @Param PriceDrivenId query int false "价格驱动ID:查询最近点击量详情"
  310. // @Success 200 {object} response.PriceDrivenClickCensusDetailResp
  311. // @router /price_driven/click_census_detail [get]
  312. func (this *PriceDrivenController) ClickCensusDetail() {
  313. br := new(models.BaseResponse).Init()
  314. defer func() {
  315. this.Data["json"] = br
  316. this.ServeJSON()
  317. }()
  318. sysUser := this.SysUser
  319. if sysUser == nil {
  320. br.Msg = "请登录"
  321. br.ErrMsg = "请登录,SysUser Is Empty"
  322. br.Ret = 408
  323. return
  324. }
  325. varietyTagId, _ := this.GetInt("VarietyTagId")
  326. priceDrivenId, _ := this.GetInt("PriceDrivenId")
  327. if varietyTagId <= 0 && priceDrivenId <= 0 {
  328. br.Msg = "参数有误"
  329. return
  330. }
  331. var startSize int
  332. pageSize, _ := this.GetInt("PageSize")
  333. currentIndex, _ := this.GetInt("CurrentIndex")
  334. if pageSize <= 0 {
  335. pageSize = utils.PageSize20
  336. }
  337. if currentIndex <= 0 {
  338. currentIndex = 1
  339. }
  340. startSize = paging.StartIndex(currentIndex, pageSize)
  341. resp := new(response.PriceDrivenClickCensusDetailResp)
  342. total, pageTotal, list, err := yb.GetPriceDrivenClickCensusDetail(startSize, pageSize, varietyTagId, priceDrivenId)
  343. if err != nil {
  344. br.Msg = "获取点击量统计详情列表失败"
  345. br.ErrMsg = "获取价格驱动统计详情列表失败-ClickCensusDetail ErrMsg:" + err.Error()
  346. return
  347. }
  348. resp.List = list
  349. page := paging.GetPaging(currentIndex, pageSize, total)
  350. resp.Paging = page
  351. resp.PageTotal = pageTotal
  352. br.Ret = 200
  353. br.Success = true
  354. br.Msg = "获取成功"
  355. br.Data = resp
  356. }