company_renewal.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/services"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. //公司未续约操作
  11. type CompanyRenewalController struct {
  12. BaseAuthController
  13. }
  14. // @Title 新建归因
  15. // @Description 新建归因接口
  16. // @Param request body company.CompanyAscribeAddReq true "type json string"
  17. // @Success 200 {object} "保存成功"
  18. // @router /company_ascribe/add [post]
  19. func (this *CompanyRenewalController) CompanyAscribeAdd() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. var req company.CompanyAscribeAddReq
  33. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  34. if err != nil {
  35. br.Msg = "参数解析异常!"
  36. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  37. return
  38. }
  39. ascribeContent := req.AscribeContent
  40. var condition string
  41. var pars []interface{}
  42. condition += " AND ascribe_content = ? "
  43. pars = append(pars, ascribeContent)
  44. total, err := company.GetCompanyAscribeCount(condition, pars)
  45. if err != nil {
  46. br.Msg = "新建失败"
  47. br.ErrMsg = "获取失败,GetCompanyAscribeCount Err:" + err.Error()
  48. return
  49. }
  50. if total > 0 {
  51. br.Msg = "此归因已存在"
  52. return
  53. }
  54. item := new(company.CompanyAscribe)
  55. item.AscribeContent = ascribeContent
  56. item.AdminId = sysUser.AdminId
  57. item.CreateTime = time.Now()
  58. item.ModifyTime = time.Now()
  59. newId, err := company.AddCompanyAscribe(item)
  60. if err != nil {
  61. br.Msg = "新建失败"
  62. br.ErrMsg = "新建失败,Err:" + err.Error()
  63. return
  64. }
  65. detail := new(company.CompanyAscribeResp)
  66. detail.CompanyAscribeId = int(newId)
  67. detail.AscribeContent = ascribeContent
  68. resp := new(company.CompanyAscribeDetailResp)
  69. resp.Detail = detail
  70. br.Ret = 200
  71. br.Success = true
  72. br.Data = resp
  73. br.Msg = "新建成功"
  74. }
  75. // @Title 归因列表接口
  76. // @Description 归因列表接口
  77. // @Param KeyWord query string true "搜索关键词"
  78. // @Success 200 {object} company.CompanyAscribeListResp
  79. // @router /company_ascribe/list [get]
  80. func (this *CompanyRenewalController) CompanyAscribeList() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. sysUser := this.SysUser
  87. if sysUser == nil {
  88. br.Msg = "请登录"
  89. br.ErrMsg = "请登录,SysUser Is Empty"
  90. return
  91. }
  92. keyWord := this.GetString("KeyWord")
  93. var condition string
  94. var pars []interface{}
  95. if keyWord != "" {
  96. condition += ` AND ascribe_content LIKE '%` + keyWord + `%' ORDER BY create_time DESC `
  97. }
  98. list, err := company.GetCompanyAscribeList(condition, pars, 0, 0)
  99. if err != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取失败,Err:" + err.Error()
  102. return
  103. }
  104. resp := new(company.CompanyAscribeListResp)
  105. if len(list) == 0 {
  106. list = make([]*company.CompanyAscribeResp, 0)
  107. }
  108. resp.List = list
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "获取成功"
  112. br.Data = resp
  113. }
  114. // @Title 添加未续约备注
  115. // @Description 添加未续约备注接口
  116. // @Param request body company.CompanyNoRenewedNoteReq true "type json string"
  117. // @Success 200 {object} "保存成功"
  118. // @router /company_no_renewed_note/add [post]
  119. func (this *CompanyRenewalController) CompanyNoRenewedNoteAdd() {
  120. br := new(models.BaseResponse).Init()
  121. defer func() {
  122. this.Data["json"] = br
  123. this.ServeJSON()
  124. }()
  125. sysUser := this.SysUser
  126. if sysUser == nil {
  127. br.Msg = "请登录"
  128. br.ErrMsg = "请登录,SysUser Is Empty"
  129. br.Ret = 408
  130. return
  131. }
  132. var req company.CompanyNoRenewedNoteReq
  133. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  134. if err != nil {
  135. br.Msg = "参数解析异常!"
  136. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  137. return
  138. }
  139. content := req.Content
  140. companyId := req.CompanyId
  141. productId := req.ProductId
  142. if companyId < 1 {
  143. br.Msg = "公司ID错误!"
  144. return
  145. }
  146. if productId != 1 && productId != 2 {
  147. br.Msg = "ProductId错误!"
  148. return
  149. }
  150. item := new(company.CompanyNoRenewedNote)
  151. item.Content = content
  152. item.CompanyId = companyId
  153. item.AdminId = sysUser.AdminId
  154. item.ProductId = productId
  155. item.CreateTime = time.Now()
  156. item.ModifyTime = time.Now()
  157. var newId int64
  158. newId, err = company.AddCompanyNoRenewedNote(item)
  159. if err != nil {
  160. br.Msg = "新建失败"
  161. br.ErrMsg = "新建失败,Err:" + err.Error()
  162. return
  163. }
  164. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  165. //权益客户新增历史备注总表
  166. itemRecord := new(company.CompanyHistoryRemark)
  167. itemRecord.CompanyId = req.CompanyId
  168. itemRecord.Content = req.Content
  169. itemRecord.SysAdminId = sysUser.AdminId
  170. itemRecord.SysAdminName = sysUser.RealName
  171. itemRecord.CreateTime = time.Now().Local()
  172. itemRecord.ModifyTime = time.Now().Local()
  173. itemRecord.ShowTime = time.Now().Local()
  174. itemRecord.ProductId = 2
  175. itemRecord.TableName = "company_no_renewed_note"
  176. itemRecord.TableId = int(newId)
  177. go services.AddCompanyHistoryRemark(itemRecord)
  178. }
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "新建成功"
  182. }
  183. // @Title 未续约备注列表
  184. // @Description 未续约备注列表接口
  185. // @Param CompanyId query int true "公司ID"
  186. // @Param ProductId query int true "产品ID 1:FICC ,2:权益"
  187. // @Success 200 {object} company.CompanyAscribeListResp
  188. // @router /company_no_renewed_note/list [get]
  189. func (this *CompanyRenewalController) CompanyNoRenewedNoteList() {
  190. br := new(models.BaseResponse).Init()
  191. defer func() {
  192. this.Data["json"] = br
  193. this.ServeJSON()
  194. }()
  195. sysUser := this.SysUser
  196. if sysUser == nil {
  197. br.Msg = "请登录"
  198. br.ErrMsg = "请登录,SysUser Is Empty"
  199. return
  200. }
  201. companyId, _ := this.GetInt("CompanyId")
  202. productId, _ := this.GetInt("ProductId")
  203. if companyId < 1 {
  204. br.Msg = "公司ID错误!"
  205. return
  206. }
  207. if productId != 1 && productId != 2 {
  208. br.Msg = "ProductId错误!"
  209. return
  210. }
  211. var condition string
  212. var pars []interface{}
  213. condition += ` AND company_id = ? AND product_id = ? ORDER BY create_time DESC `
  214. pars = append(pars, companyId, productId)
  215. list, err := company.GetCompanyNoRenewedNoteList(condition, pars, 0, 0)
  216. if err != nil {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = "获取失败,Err:" + err.Error()
  219. return
  220. }
  221. resp := new(company.CompanyNoRenewedNoteListResp)
  222. if len(list) == 0 {
  223. list = make([]*company.CompanyNoRenewedNoteResp, 0)
  224. }
  225. resp.List = list
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "获取成功"
  229. br.Data = resp
  230. }
  231. // @Title 通过归因添加确认不续约
  232. // @Description 通过归因添加确认不续约接口
  233. // @Param request body company.CompanyNoRenewedNoteReq true "type json string"
  234. // @Success 200 {object} "保存成功"
  235. // @router /company_no_renewed_ascribe/add [post]
  236. func (this *CompanyRenewalController) CompanyNoRenewedAscribeAdd() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. this.Data["json"] = br
  240. this.ServeJSON()
  241. }()
  242. sysUser := this.SysUser
  243. if sysUser == nil {
  244. br.Msg = "请登录"
  245. br.ErrMsg = "请登录,SysUser Is Empty"
  246. br.Ret = 408
  247. return
  248. }
  249. //内容仅权益管理员账号可以修改
  250. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  251. br.Msg = "仅管理员可修改!"
  252. return
  253. }
  254. var req company.CompanyNoRenewedAscribeReq
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. content := req.Content
  262. companyId := req.CompanyId
  263. productId := req.ProductId
  264. companyAscribeId := req.CompanyAscribeId
  265. if content == "" {
  266. br.Msg = "内容不能为空!"
  267. return
  268. }
  269. if companyId < 1 {
  270. br.Msg = "公司ID错误!"
  271. return
  272. }
  273. if productId != 1 && productId != 2 {
  274. if companyId < 1 {
  275. br.Msg = "ProductId错误!"
  276. return
  277. }
  278. }
  279. detail, err := company.GetCompanyAscribeDetail(companyAscribeId)
  280. if err != nil {
  281. br.Msg = "新建失败"
  282. br.ErrMsg = "新建失败,GetCompanyAscribeDetail Err:" + err.Error()
  283. return
  284. }
  285. var condition string
  286. var pars []interface{}
  287. condition += ` AND company_id = ? AND product_id = ? ORDER BY create_time DESC `
  288. pars = append(pars, companyId, productId)
  289. total, err := company.GetCompanyNoRenewedAscribeCount(condition, pars)
  290. if err != nil {
  291. br.Msg = "新建失败"
  292. br.ErrMsg = "新建失败,GetCompanyNoRenewedAscribeCount Err:" + err.Error()
  293. return
  294. }
  295. item := new(company.CompanyNoRenewedAscribe)
  296. item.CompanyAscribeId = companyAscribeId
  297. item.AscribeContent = detail.AscribeContent
  298. item.Content = content
  299. item.ProductId = productId
  300. item.CompanyId = companyId
  301. item.AdminId = sysUser.AdminId
  302. item.CreateTime = time.Now()
  303. item.ModifyTime = time.Now()
  304. itemLog := new(company.CompanyNoRenewedAscribeLog)
  305. itemLog.CompanyAscribeId = companyAscribeId
  306. itemLog.AscribeContent = detail.AscribeContent
  307. itemLog.Content = content
  308. itemLog.ProductId = productId
  309. itemLog.CompanyId = companyId
  310. itemLog.AdminId = sysUser.AdminId
  311. itemLog.CreateTime = time.Now()
  312. itemLog.ModifyTime = time.Now()
  313. if total == 0 {
  314. err = company.AddCompanyNoRenewedAscribe(item, itemLog)
  315. } else {
  316. err = company.UpdateCompanyNoRenewedAscribe(item, itemLog)
  317. }
  318. if err != nil {
  319. br.Msg = "新建失败"
  320. br.ErrMsg = "新建失败,Err:" + err.Error()
  321. return
  322. }
  323. br.Ret = 200
  324. br.Success = true
  325. br.Msg = "新建成功"
  326. }
  327. // @Title 确认归因不续约详情接口
  328. // @Description 确认归因不续约详情接口
  329. // @Param CompanyId query int true "公司ID"
  330. // @Param ProductId query int true "产品ID 1:FICC ,2:权益"
  331. // @Success 200 {object} company.CompanyAscribeListResp
  332. // @router /company_no_renewed_ascribe/detail [get]
  333. func (this *CompanyRenewalController) CompanyNoRenewedAscribeAddDetail() {
  334. br := new(models.BaseResponse).Init()
  335. defer func() {
  336. this.Data["json"] = br
  337. this.ServeJSON()
  338. }()
  339. sysUser := this.SysUser
  340. if sysUser == nil {
  341. br.Msg = "请登录"
  342. br.ErrMsg = "请登录,SysUser Is Empty"
  343. return
  344. }
  345. companyId, _ := this.GetInt("CompanyId")
  346. productId, _ := this.GetInt("ProductId")
  347. if companyId < 1 {
  348. br.Msg = "公司ID错误!"
  349. return
  350. }
  351. if productId != 1 && productId != 2 {
  352. br.Msg = "ProductId错误!"
  353. return
  354. }
  355. resp := new(company.CompanyNoRenewedAscribeDetailResp)
  356. detail, err := company.GetCompanyNoRenewedAscribeDetail(companyId, productId)
  357. if err != nil {
  358. br.Msg = "获取失败"
  359. br.ErrMsg = "获取失败,Err:" + err.Error()
  360. return
  361. }
  362. resp.Detail = detail
  363. br.Ret = 200
  364. br.Success = true
  365. br.Msg = "获取成功"
  366. br.Data = resp
  367. }
  368. // @Title 合同通过归因添加确认不续约
  369. // @Description 合同通过归因添加确认不续约接口
  370. // @Param request body company.CompanyNoRenewedNoteReq true "type json string"
  371. // @Success 200 {object} "保存成功"
  372. // @router /company_contract_no_renewed_ascribe/add [post]
  373. func (this *CompanyRenewalController) CompanyContractNoRenewedAscribeAdd() {
  374. br := new(models.BaseResponse).Init()
  375. defer func() {
  376. this.Data["json"] = br
  377. this.ServeJSON()
  378. }()
  379. sysUser := this.SysUser
  380. if sysUser == nil {
  381. br.Msg = "请登录"
  382. br.ErrMsg = "请登录,SysUser Is Empty"
  383. br.Ret = 408
  384. return
  385. }
  386. //内容仅权益管理员账号可以修改
  387. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  388. br.Msg = "仅管理员可修改!"
  389. return
  390. }
  391. var req company.CompanyContractNoRenewedAscribeReq
  392. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  393. if err != nil {
  394. br.Msg = "参数解析异常!"
  395. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  396. return
  397. }
  398. content := req.Content
  399. companyAscribeId := req.CompanyAscribeId
  400. companyContractId := req.CompanyContractId
  401. if content == "" {
  402. br.Msg = "内容不能为空!"
  403. return
  404. }
  405. contractInfo, err := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
  406. if err != nil {
  407. br.Msg = "获取合同失败"
  408. br.ErrMsg = "获取合同失败,Err:" + err.Error()
  409. return
  410. }
  411. companyId := contractInfo.CompanyId //公司ID
  412. productId := contractInfo.ProductId //权益还是FICC
  413. detail, err := company.GetCompanyAscribeDetail(companyAscribeId)
  414. if err != nil {
  415. br.Msg = "新建失败"
  416. br.ErrMsg = "新建失败,GetCompanyAscribeDetail Err:" + err.Error()
  417. return
  418. }
  419. var condition string
  420. var pars []interface{}
  421. condition += ` AND company_id = ? AND product_id = ? AND company_contract_id = ? `
  422. pars = append(pars, companyId, productId, companyContractId)
  423. total, err := company.GetCompanyContractNoRenewedAscribeCount(condition, pars)
  424. if err != nil {
  425. br.Msg = "新建失败"
  426. br.ErrMsg = "新建失败,GetCompanyContractNoRenewedAscribeCount Err:" + err.Error()
  427. return
  428. }
  429. item := new(company.CompanyContractNoRenewedAscribe)
  430. item.CompanyAscribeId = companyAscribeId
  431. item.AscribeContent = detail.AscribeContent
  432. item.Content = content
  433. item.ProductId = productId
  434. item.CompanyId = companyId
  435. item.CompanyContractId = companyContractId
  436. item.AdminId = sysUser.AdminId
  437. item.CreateTime = time.Now()
  438. item.ModifyTime = time.Now()
  439. itemLog := new(company.CompanyContractNoRenewedAscribeLog)
  440. itemLog.CompanyAscribeId = companyAscribeId
  441. itemLog.AscribeContent = detail.AscribeContent
  442. itemLog.Content = content
  443. itemLog.ProductId = productId
  444. itemLog.CompanyId = companyId
  445. itemLog.CompanyContractId = companyContractId
  446. itemLog.AdminId = sysUser.AdminId
  447. itemLog.CreateTime = time.Now()
  448. itemLog.ModifyTime = time.Now()
  449. if total == 0 {
  450. err = company.AddCompanyContractNoRenewedAscribe(item, itemLog)
  451. } else {
  452. err = company.UpdateCompanyContractNoRenewedAscribe(item, itemLog)
  453. }
  454. if err != nil {
  455. br.Msg = "新建失败"
  456. br.ErrMsg = "新建失败,Err:" + err.Error()
  457. return
  458. }
  459. br.Ret = 200
  460. br.Success = true
  461. br.Msg = "新建成功"
  462. }
  463. // @Title 合同确认归因不续约详情接口
  464. // @Description 合同确认归因不续约详情接口
  465. // @Param CompanyContractId query int true "合同ID"
  466. // @Success 200 {object} company.CompanyAscribeListResp
  467. // @router /company_contract_no_renewed_ascribe/detail [get]
  468. func (this *CompanyRenewalController) CompanyContractNoRenewedAscribeAddDetail() {
  469. br := new(models.BaseResponse).Init()
  470. defer func() {
  471. this.Data["json"] = br
  472. this.ServeJSON()
  473. }()
  474. sysUser := this.SysUser
  475. if sysUser == nil {
  476. br.Msg = "请登录"
  477. br.ErrMsg = "请登录,SysUser Is Empty"
  478. return
  479. }
  480. companyContractId, _ := this.GetInt("CompanyContractId")
  481. if companyContractId < 1 {
  482. br.Msg = "合同ID错误!"
  483. return
  484. }
  485. resp := new(company.CompanyContractNoRenewedAscribeDetailResp)
  486. detail, err := company.GetCompanyContractNoRenewedAscribeDetail(companyContractId)
  487. if err != nil {
  488. br.Msg = "获取失败"
  489. br.ErrMsg = "获取失败,Err:" + err.Error()
  490. return
  491. }
  492. resp.Detail = detail
  493. br.Ret = 200
  494. br.Success = true
  495. br.Msg = "获取成功"
  496. br.Data = resp
  497. }