company_approval.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/contract"
  8. "hongze/hz_crm_api/services"
  9. "hongze/hz_crm_api/services/company_apply"
  10. contractService "hongze/hz_crm_api/services/contract"
  11. "hongze/hz_crm_api/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 审批管理
  17. type CompanyApprovalController struct {
  18. BaseAuthController
  19. }
  20. // @Title 审批列表
  21. // @Description 审批列表接口
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param Status query string true "状态:'全部','待审批','已审批','驳回','已撤回'"
  25. // @Param KeyWord query string true "搜索关键词"
  26. // @Success 200 {object} company.CompanyApprovalListResp
  27. // @router /approval/list_old [get]
  28. func (this *CompanyApprovalController) ApprovalListOld() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. roleTypeCode := sysUser.RoleTypeCode
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. status := this.GetString("Status")
  45. keyWord := this.GetString("KeyWord")
  46. var startSize int
  47. if pageSize <= 0 {
  48. pageSize = utils.PageSize20
  49. }
  50. if currentIndex <= 0 {
  51. currentIndex = 1
  52. }
  53. startSize = paging.StartIndex(currentIndex, pageSize)
  54. var condition string
  55. var pars []interface{}
  56. if status != "" {
  57. if status == "已审批" {
  58. condition += ` AND c.approve_status IN('已审批','驳回','已撤回') `
  59. } else {
  60. condition += ` AND c.approve_status=? `
  61. pars = append(pars, status)
  62. }
  63. }
  64. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
  65. condition += ` AND c.approve_role_type_code=? `
  66. pars = append(pars, roleTypeCode)
  67. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售
  68. condition += ` AND c.apply_user_id=? `
  69. pars = append(pars, sysUser.AdminId)
  70. }
  71. if keyWord != "" {
  72. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%') `
  73. }
  74. total, err := company.GetApprovalCount(condition, pars)
  75. if err != nil {
  76. br.Msg = "获取失败"
  77. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  78. return
  79. }
  80. list, err := company.GetApprovalList(condition, pars, startSize, pageSize)
  81. if err != nil {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  84. return
  85. }
  86. listLen := len(list)
  87. for i := 0; i < listLen; i++ {
  88. item := list[i]
  89. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  90. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  91. if time.Now().Before(freezeEndDate) {
  92. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  93. list[i].FreezeExpireDays = int(expireDays)
  94. }
  95. }
  96. if item.StartDate != "" && item.EndDate != "" {
  97. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  98. if time.Now().Before(endDate) {
  99. expireDays := endDate.Sub(time.Now()).Hours() / 24
  100. list[i].ExpireDay = int(expireDays)
  101. }
  102. }
  103. switch item.ApplyMethod {
  104. case 2:
  105. //客户冻结转试用次数
  106. approvalCount, err := company.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取冻结转试用审批次数失败,Err:" + err.Error()
  110. return
  111. }
  112. list[i].ApprovalCount = approvalCount
  113. case 3:
  114. delayPermission, err := company.GetApplyDelayPermission(item.CompanyApprovalId)
  115. if err != nil && err.Error() != utils.ErrNoRow() {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "获取延期审批权限失败,Err:" + err.Error()
  118. return
  119. }
  120. list[i].DelayPermission = delayPermission
  121. //客户审批试用延期次数
  122. approvalCount, err := company.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
  123. if err != nil && err.Error() != utils.ErrNoRow() {
  124. br.Msg = "获取失败"
  125. br.ErrMsg = "获取延期审批次数失败,Err:" + err.Error()
  126. return
  127. }
  128. list[i].ApprovalCount = approvalCount
  129. }
  130. }
  131. page := paging.GetPaging(currentIndex, pageSize, total)
  132. resp := new(company.CompanyApprovalListResp)
  133. resp.Paging = page
  134. resp.List = list
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = resp
  139. }
  140. // @Title 审批列表
  141. // @Description 审批列表接口
  142. // @Param PageSize query int true "每页数据条数"
  143. // @Param CurrentIndex query int true "当前页页码,从1开始"
  144. // @Param Status query string true "状态:'全部','待审批','已审批','驳回','已撤回'"
  145. // @Param KeyWord query string true "搜索关键词"
  146. // @Success 200 {object} company.CompanyApprovalListResp
  147. // @router /approval/list [get]
  148. func (this *CompanyApprovalController) ApprovalList() {
  149. br := new(models.BaseResponse).Init()
  150. defer func() {
  151. this.Data["json"] = br
  152. this.ServeJSON()
  153. }()
  154. sysUser := this.SysUser
  155. if sysUser == nil {
  156. br.Msg = "请登录"
  157. br.ErrMsg = "请登录,SysUser Is Empty"
  158. br.Ret = 408
  159. return
  160. }
  161. roleTypeCode := sysUser.RoleTypeCode
  162. pageSize, _ := this.GetInt("PageSize")
  163. currentIndex, _ := this.GetInt("CurrentIndex")
  164. status := this.GetString("Status")
  165. keyWord := this.GetString("KeyWord")
  166. var startSize int
  167. if pageSize <= 0 {
  168. pageSize = utils.PageSize20
  169. }
  170. if currentIndex <= 0 {
  171. currentIndex = 1
  172. }
  173. startSize = paging.StartIndex(currentIndex, pageSize)
  174. var condition string
  175. var pars []interface{}
  176. if status != "" {
  177. if status == "已审批" {
  178. condition += ` AND c.approve_status IN('已审批','驳回','已撤回') `
  179. } else {
  180. condition += ` AND c.approve_status=? `
  181. pars = append(pars, status)
  182. }
  183. }
  184. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
  185. condition += ` AND c.approve_role_type_code=? `
  186. pars = append(pars, roleTypeCode)
  187. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售
  188. condition += ` AND c.apply_user_id=? `
  189. pars = append(pars, sysUser.AdminId)
  190. }
  191. if keyWord != "" {
  192. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%') `
  193. }
  194. total, err := company.GetApprovalCount(condition, pars)
  195. if err != nil {
  196. br.Msg = "获取失败"
  197. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  198. return
  199. }
  200. list, err := company.GetApprovalList(condition, pars, startSize, pageSize)
  201. if err != nil {
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  204. return
  205. }
  206. listLen := len(list)
  207. if listLen > 0 {
  208. contractApprovalIdSlice := make([]string, 0)
  209. for i := 0; i < len(list); i++ {
  210. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].CompanyApprovalId))
  211. }
  212. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  213. //获取审批流列表数据
  214. contractApprovalRecordList, err := contract.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
  215. if err != nil {
  216. br.Msg = "获取审批流列表失败!"
  217. br.ErrMsg = "获取审批流列表失败,Err:" + err.Error()
  218. return
  219. }
  220. contractApprovalRecordMap := make(map[int]*contract.ContractApprovalRecord)
  221. for i := 0; i < len(contractApprovalRecordList); i++ {
  222. contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
  223. }
  224. for i := 0; i < listLen; i++ {
  225. item := list[i]
  226. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  227. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  228. if time.Now().Before(freezeEndDate) {
  229. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  230. list[i].FreezeExpireDays = int(expireDays)
  231. }
  232. }
  233. if item.StartDate != "" && item.EndDate != "" {
  234. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  235. if time.Now().Before(endDate) {
  236. expireDays := endDate.Sub(time.Now()).Hours() / 24
  237. list[i].ExpireDay = int(expireDays)
  238. }
  239. }
  240. switch item.ApplyMethod {
  241. case 2:
  242. //客户冻结转试用次数
  243. approvalCount, err := company.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
  244. if err != nil && err.Error() != utils.ErrNoRow() {
  245. br.Msg = "获取失败"
  246. br.ErrMsg = "获取冻结转试用审批次数失败,Err:" + err.Error()
  247. return
  248. }
  249. list[i].ApprovalCount = approvalCount
  250. case 3:
  251. delayPermission, err := company.GetApplyDelayPermission(item.CompanyApprovalId)
  252. if err != nil && err.Error() != utils.ErrNoRow() {
  253. br.Msg = "获取失败"
  254. br.ErrMsg = "获取延期审批权限失败,Err:" + err.Error()
  255. return
  256. }
  257. list[i].DelayPermission = delayPermission
  258. //客户审批试用延期次数
  259. approvalCount, err := company.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
  260. if err != nil && err.Error() != utils.ErrNoRow() {
  261. br.Msg = "获取失败"
  262. br.ErrMsg = "获取延期审批次数失败,Err:" + err.Error()
  263. return
  264. }
  265. list[i].ApprovalCount = approvalCount
  266. }
  267. }
  268. }
  269. page := paging.GetPaging(currentIndex, pageSize, total)
  270. resp := new(company.CompanyApprovalListResp)
  271. resp.Paging = page
  272. resp.List = list
  273. br.Ret = 200
  274. br.Success = true
  275. br.Msg = "获取成功"
  276. br.Data = resp
  277. }
  278. // List
  279. // @Title 审批列表
  280. // @Description 审批列表接口
  281. // @Param PageSize query int true "每页数据条数"
  282. // @Param CurrentIndex query int true "当前页页码,从1开始"
  283. // @Param Status query string true "状态:'全部','待审批','已审批','驳回','已撤回'"
  284. // @Param KeyWord query string true "搜索关键词"
  285. // @Success 200 {object} company.CompanyApprovalListResp
  286. // @router /approval/listV2 [get]
  287. func (this *CompanyApprovalController) List() {
  288. br := new(models.BaseResponse).Init()
  289. defer func() {
  290. this.Data["json"] = br
  291. this.ServeJSON()
  292. }()
  293. sysUser := this.SysUser
  294. if sysUser == nil {
  295. br.Msg = "请登录"
  296. br.ErrMsg = "请登录,SysUser Is Empty"
  297. br.Ret = 408
  298. return
  299. }
  300. //合同类型、产品类型、合同状态、更新时间、所选销售
  301. //关键字:合同编号、客户名称,社会信用码
  302. contractType := this.GetString("ContractType")
  303. status := this.GetString("Status")
  304. productId, _ := this.GetInt("ProductId")
  305. sellerIds := this.GetString("SellerId")
  306. keyword := this.GetString("KeyWord")
  307. modifyStartTime := this.GetString("ModifyStartTime")
  308. modifyEndTime := this.GetString("ModifyEndTime")
  309. childCondition := ""
  310. condition := ""
  311. childPars := make([]interface{}, 0)
  312. pars := make([]interface{}, 0)
  313. //如果不是超管或者合规,那么只能查看自己的合同
  314. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //权益管理员
  315. condition += ` AND c.product_id = ? `
  316. pars = append(pars, 2)
  317. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //ficc管理员
  318. condition += ` AND c.product_id = ? `
  319. pars = append(pars, 1)
  320. } else {
  321. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  322. condition += ` AND c.apply_user_id = ? `
  323. pars = append(pars, sysUser.AdminId)
  324. }
  325. }
  326. //合同类型、、更新时间、所选销售
  327. //关键字:合同编号、客户名称,社会信用码
  328. if contractType != "" {
  329. condition += ` AND c.contract_type = ? `
  330. pars = append(pars, contractType)
  331. }
  332. //审批状态
  333. if status != "" {
  334. //childCondition += ` AND status = ? `
  335. //childPars = append(childPars, status)
  336. if status == "已审批" {
  337. if services.CheckAdminIsSeller(sysUser.RoleTypeCode) {
  338. condition += ` AND c.approve_status in ("已审批","驳回","已撤回") `
  339. } else {
  340. condition += ` AND c.approve_status in ("已审批","驳回") `
  341. }
  342. } else {
  343. condition += ` AND c.approve_status = ? `
  344. pars = append(pars, status)
  345. }
  346. } else {
  347. //如果不是销售,那么不展示 已撤回 的客户单
  348. if !services.CheckAdminIsSeller(sysUser.RoleTypeCode) {
  349. condition += ` AND c.approve_status !="已撤回" `
  350. }
  351. }
  352. //产品类型
  353. if productId > 0 {
  354. condition += ` AND c.product_id = ? `
  355. pars = append(pars, productId)
  356. }
  357. //所选销售
  358. if sellerIds != "" {
  359. condition += ` AND c.apply_user_id IN (` + sellerIds + `) `
  360. }
  361. //更新开始时间
  362. //更新开始时间
  363. if modifyStartTime != "" {
  364. condition += ` AND a.modify_time >= ? `
  365. pars = append(pars, modifyStartTime)
  366. }
  367. //更新结束时间
  368. if modifyEndTime != "" {
  369. condition += ` AND a.modify_time <= ? `
  370. pars = append(pars, modifyEndTime)
  371. }
  372. //关键字
  373. if keyword != "" {
  374. condition += ` AND ( e.company_name LIKE '%` + keyword + `%' OR e.credit_code LIKE '%` + keyword + `%' ) `
  375. }
  376. pageSize, _ := this.GetInt("PageSize")
  377. currentIndex, _ := this.GetInt("CurrentIndex")
  378. var startSize int
  379. if pageSize <= 0 {
  380. pageSize = utils.PageSize20
  381. }
  382. if currentIndex <= 0 {
  383. currentIndex = 1
  384. }
  385. startSize = paging.StartIndex(currentIndex, pageSize)
  386. total, err := contract.GetCompanyApprovalListCount(condition, pars)
  387. if err != nil {
  388. br.Msg = "获取失败"
  389. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  390. return
  391. }
  392. list, err := contract.GetCompanyApprovalList(childCondition, condition, childPars, pars, startSize, pageSize)
  393. if err != nil {
  394. br.Msg = "获取审批列表失败!"
  395. br.ErrMsg = "获取审批列表失败,Err:" + err.Error()
  396. return
  397. }
  398. respList := make([]*company.CompanyApprovalList, 0)
  399. if len(list) > 0 {
  400. contractApprovalIdSlice := make([]string, 0)
  401. for i := 0; i < len(list); i++ {
  402. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
  403. }
  404. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  405. //获取审批流列表数据
  406. contractApprovalRecordList, err := contract.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
  407. if err != nil {
  408. br.Msg = "获取审批流列表失败!"
  409. br.ErrMsg = "获取审批流列表失败,Err:" + err.Error()
  410. return
  411. }
  412. contractApprovalRecordMap := make(map[int]*contract.ContractApprovalRecord)
  413. for i := 0; i < len(contractApprovalRecordList); i++ {
  414. contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
  415. }
  416. for i := 0; i < len(list); i++ {
  417. item := list[i]
  418. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  419. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  420. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  421. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  422. list[i].ApproveTimeStr = item.ApproveTime.Format(utils.FormatDateTime)
  423. //合同操作权限
  424. var opButton company.ApprovalButton
  425. var contractDetail contract.ContractDetail
  426. jsonErr := json.Unmarshal([]byte(list[i].ContractDetail), &contractDetail)
  427. if jsonErr != nil {
  428. br.Msg = "审批合同数据转换失败!"
  429. br.ErrMsg = "审批合同数据转换失败,Err:" + jsonErr.Error()
  430. return
  431. }
  432. list[i].ContractInfo = contractDetail
  433. //校验最新审批流数据
  434. if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
  435. //审批流id
  436. list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
  437. //审批时间
  438. list[i].ApproveTime = contractApprovalRecord.ApproveTime
  439. list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
  440. //判断是否有操作权限
  441. list[i].Status = contractApprovalRecord.Status
  442. //判断是否处于待审批状态
  443. if contractApprovalRecord.Status == "待审批" {
  444. //如果不是审批者,那么不能审批操作
  445. if contractApprovalRecord.NodeType != "check" {
  446. continue
  447. }
  448. //如果没有指定审批人的话
  449. if contractApprovalRecord.ApproveUserId <= 0 {
  450. //判断是否与审批角色一致,如果一致,那么允许操作审批
  451. if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
  452. opButton.Approval = true
  453. }
  454. } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
  455. //如果指定审批人就是自己的话,那么操作审批
  456. opButton.Approval = true
  457. }
  458. }
  459. }
  460. //撤销权限(本人才有,然后没有审核操作过的才允许撤销)
  461. if item.Status == "待审批" && item.StartNodeId == item.CurrNodeId && item.ApplyUserId == sysUser.AdminId {
  462. opButton.Cancel = true
  463. }
  464. if item.CompanyProductStatus == utils.COMPANY_STATUS_FOREVER {
  465. item.CompanyProductStatus = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  466. }
  467. respTmp := &company.CompanyApprovalList{
  468. CompanyId: item.CompanyId,
  469. ProductId: item.ProductId,
  470. CompanyName: item.CompanyName,
  471. CreditCode: item.CreditCode,
  472. CompanyType: item.CompanyType,
  473. IndustryName: item.IndustryName,
  474. SellerName: item.SellerName,
  475. CreateTime: item.CreateTimeStr,
  476. ApprovalTime: item.CreateTime.Format(utils.FormatDateTime),
  477. ApproveTime: item.ApproveTimeStr,
  478. Status: item.CompanyProductStatus,
  479. ApproveContent: item.ApplyContent,
  480. ApproveStatus: item.ApproveStatus,
  481. ApplyMethod: item.ApplyMethod,
  482. ApplyReasons: item.ApplyReasons,
  483. FreezeStartDate: item.FreezeStartDate,
  484. FreezeEndDate: item.FreezeEndDate,
  485. FreezeExpireDays: item.FreezeExpireDays,
  486. Address: item.Address,
  487. Source: item.Source,
  488. ApproveRemark: item.ApproveRemark,
  489. StartDate: item.StartDate.Format(utils.FormatDate),
  490. EndDate: item.EndDate.Format(utils.FormatDate),
  491. ExpireDay: item.ExpireDay,
  492. CompanyApprovalId: item.CompanyApprovalId,
  493. //ApprovalCount int `description:"已延期审批次数"`
  494. CompanyContractId: item.CompanyContractId,
  495. //DelayPermission :
  496. ApplyRealName: item.ApplyRealName,
  497. ApplyUserId: item.ApplyUserId,
  498. OpButton: opButton,
  499. }
  500. if respTmp.FreezeStartDate != "" && respTmp.FreezeEndDate != "" && respTmp.Status == utils.COMPANY_STATUS_FREEZE {
  501. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  502. if time.Now().Before(freezeEndDate) {
  503. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  504. respTmp.FreezeExpireDays = int(expireDays)
  505. }
  506. }
  507. if respTmp.StartDate != "" && respTmp.EndDate != "" {
  508. endDate, _ := time.Parse(utils.FormatDate, respTmp.EndDate)
  509. if time.Now().Before(endDate) {
  510. expireDays := endDate.Sub(time.Now()).Hours() / 24
  511. list[i].ExpireDay = int(expireDays)
  512. }
  513. }
  514. switch respTmp.ApplyMethod {
  515. case 2:
  516. //客户冻结转试用次数
  517. approvalCount, err := company.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, respTmp.ApplyUserId)
  518. if err != nil && err.Error() != utils.ErrNoRow() {
  519. br.Msg = "获取失败"
  520. br.ErrMsg = "获取客户冻结转试用次数失败,Err:" + err.Error()
  521. return
  522. }
  523. //respTmp.S
  524. respTmp.ApprovalCount = approvalCount
  525. case 3:
  526. delayPermission, err := company.GetApplyDelayPermission(item.CompanyApprovalId)
  527. if err != nil && err.Error() != utils.ErrNoRow() {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "获取延期审批权限失败,Err:" + err.Error()
  530. return
  531. }
  532. respTmp.DelayPermission = delayPermission
  533. //客户审批试用延期次数
  534. approvalCount, err := company.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
  535. if err != nil && err.Error() != utils.ErrNoRow() {
  536. br.Msg = "获取失败"
  537. br.ErrMsg = "获取延期审批次数失败,Err:" + err.Error()
  538. return
  539. }
  540. respTmp.ApprovalCount = approvalCount
  541. }
  542. //判断是否系统合同
  543. if respTmp.CompanyContractId > 0 {
  544. companyContract, err := company.GetCompanyContractById(respTmp.CompanyContractId)
  545. if err != nil {
  546. br.Msg = "获取合同失败"
  547. br.ErrMsg = "获取合同失败,Err:" + err.Error()
  548. return
  549. }
  550. systemContract, err := contract.GetContractByCode(companyContract.ContractCode)
  551. //如果通过合同编号可以找到系统合同,那么就是标准合同
  552. if systemContract != nil {
  553. respTmp.ApplyContractType = 1
  554. }
  555. }
  556. respList = append(respList, respTmp)
  557. }
  558. }
  559. page := paging.GetPaging(currentIndex, pageSize, total)
  560. br.Ret = 200
  561. br.Success = true
  562. br.Msg = "获取成功"
  563. br.Data = company.CompanyApprovalListResp{
  564. List: respList,
  565. Paging: page,
  566. }
  567. }
  568. // @Title 获取审批单中的权限列表
  569. // @Description 获取审批单中的权限列表接口
  570. // @Param ApprovalId query int true "审批单id"
  571. // @Success 200 {object} company.CompanyPermissionResp
  572. // @router /approval/getApprovalPermissionList [get]
  573. func (this *CompanyApprovalController) GetApprovalPermissionList() {
  574. br := new(models.BaseResponse).Init()
  575. defer func() {
  576. this.Data["json"] = br
  577. this.ServeJSON()
  578. }()
  579. sysUser := this.SysUser
  580. if sysUser == nil {
  581. br.Msg = "请登录"
  582. br.ErrMsg = "请登录,SysUser Is Empty"
  583. br.Ret = 408
  584. return
  585. }
  586. //返回基础参数
  587. resp := new(company.CompanyPermissionResp)
  588. //获取审批单信息
  589. approvalId, _ := this.GetInt("ApprovalId")
  590. if approvalId <= 0 {
  591. br.Msg = "审批单参数异常"
  592. br.ErrMsg = "提交审批单参数异常"
  593. return
  594. }
  595. approvalInfo, err := company.GetCompanyApprovalByApprovalId(approvalId)
  596. if err != nil {
  597. br.Msg = "获取失败"
  598. br.ErrMsg = "获取审批单数据失败,Err:" + err.Error()
  599. return
  600. }
  601. //子权限切片集合
  602. var permissionProductId int
  603. if approvalInfo.ProductId == 1 {
  604. permissionProductId = 1
  605. } else {
  606. permissionProductId = 2
  607. }
  608. permissionClassifyArr, err := services.GetPermissionFirstArr(permissionProductId)
  609. if err != nil {
  610. br.Msg = "获取失败"
  611. br.ErrMsg = "获取权限分类失败,Err:" + err.Error()
  612. return
  613. }
  614. //获取需要审批的权限
  615. delayPermissionList, err := company.GetDelayPermissionItems(approvalInfo.CompanyId, approvalInfo.CompanyApprovalId)
  616. if err != nil && err.Error() != utils.ErrNoRow() {
  617. br.Msg = "获取失败"
  618. br.ErrMsg = "获取审批权限失败,Err:" + err.Error()
  619. return
  620. }
  621. delayPermissionIdMap := make(map[int]int)
  622. //sandoPermissionIdMap := make(map[string]int)
  623. for _, delayPermission := range delayPermissionList {
  624. delayPermissionIdMap[delayPermission.ChartPermissionId] = 0
  625. }
  626. //遍历获取
  627. for _, v := range permissionClassifyArr {
  628. checkList := make([]int, 0)
  629. plist := new(company.PermissionLookList)
  630. plist.Items = make([]*company.PermissionLookItem, 0)
  631. items, err := company.GetPermissionLookItemsByParentId(approvalInfo.ProductId, v.ChartPermissionId)
  632. if err != nil {
  633. br.Msg = "获取失败"
  634. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  635. return
  636. }
  637. if len(items) > 0 {
  638. //权益客户下,主观客观同时选择,进行合并
  639. for _, n := range items {
  640. if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
  641. //if approvalInfo.ProductId == 2 {
  642. // if sandoPermissionIdMap[n.PermissionName] == 0 {
  643. // checkList = append(checkList, n.ChartPermissionId)
  644. // }
  645. // sandoPermissionIdMap[n.PermissionName] += 1
  646. //} else {
  647. // checkList = append(checkList, n.ChartPermissionId)
  648. //}
  649. checkList = append(checkList, n.ChartPermissionId)
  650. }
  651. }
  652. plist.Items = items
  653. }
  654. //if approvalInfo.ProductId == 2 {
  655. // for i, n := range items {
  656. // if sandoPermissionIdMap[n.PermissionName] == 1 {
  657. // items[i].PermissionName = n.Remark
  658. // }
  659. // }
  660. //}
  661. plist.ClassifyName = v.PermissionName
  662. plist.CheckList = checkList
  663. if approvalInfo.ProductId == 1 {
  664. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  665. } else {
  666. rp := make([]*company.PermissionLookList, 0)
  667. rp = append(rp, plist)
  668. // CRM8.8-权限主客观合并
  669. newPermissionLookList := contractService.HandleEquityPermissionLookList(rp)
  670. resp.PermissionList = newPermissionLookList
  671. }
  672. }
  673. br.Ret = 200
  674. br.Success = true
  675. br.Msg = "获取成功"
  676. br.Data = resp
  677. }
  678. // @Title 审批
  679. // @Description 审批接口
  680. // @Param request body company.CompanyApplyApproveReq true "type json string"
  681. // @Success Ret=200 审批成功
  682. // @router /approval/approve [post]
  683. func (this *CompanyApprovalController) ApplyApprove() {
  684. br := new(models.BaseResponse).Init()
  685. defer func() {
  686. this.Data["json"] = br
  687. this.ServeJSON()
  688. }()
  689. sysUser := this.SysUser
  690. if sysUser == nil {
  691. br.Msg = "请登录"
  692. br.ErrMsg = "请登录,SysUser Is Empty"
  693. br.Ret = 408
  694. return
  695. }
  696. var req company.CompanyApplyApproveReq
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  698. if err != nil {
  699. br.Msg = "参数解析异常!"
  700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  701. return
  702. }
  703. roleTypeCode := sysUser.RoleTypeCode
  704. //productId := services.GetProductId(roleTypeCode)
  705. productId := req.ProductId
  706. if productId == 0 {
  707. br.Msg = "参数错误"
  708. br.ErrMsg = "客户类型为:" + roleTypeCode
  709. return
  710. }
  711. if req.CompanyId <= 0 {
  712. br.Msg = "参数错误"
  713. br.ErrMsg = "客户Id小于等于0:"
  714. return
  715. }
  716. if req.Status != 1 && req.Status != 2 {
  717. br.Msg = "参数错误"
  718. br.ErrMsg = "审批状态Id小于等于0:"
  719. return
  720. }
  721. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  722. if err != nil {
  723. br.Msg = "获取信息失败"
  724. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  725. return
  726. }
  727. if companyProduct == nil {
  728. br.Msg = "获取信息失败"
  729. br.ErrMsg = "获取审批信息失败,Err:companyProduct为空"
  730. return
  731. }
  732. //数据校验(校验是否具有审批权限)
  733. _, _, approvalRecord, err := company_apply.CheckApproveAuth(req.CompanyId, productId, sysUser)
  734. if err != nil {
  735. br.Msg = "审批失败"
  736. br.ErrMsg = "审批失败,Err:" + err.Error()
  737. return
  738. }
  739. //真实审核操作
  740. if req.Status == 1 {
  741. err = company_apply.Approved(approvalRecord, sysUser, req.Remark)
  742. if err != nil {
  743. br.Msg = "审核失败!"
  744. br.ErrMsg = "审核失败,Err:" + err.Error()
  745. return
  746. }
  747. } else {
  748. err = company_apply.Reject(approvalRecord, sysUser, req.Remark)
  749. if err != nil {
  750. br.Msg = "审核失败!"
  751. br.ErrMsg = "审核失败,Err:" + err.Error()
  752. return
  753. }
  754. }
  755. br.Ret = 200
  756. br.Success = true
  757. br.Msg = "审批成功"
  758. }
  759. //func (this *CompanyApprovalController) ApplyApproveOld() {
  760. // br := new(models.BaseResponse).Init()
  761. // defer func() {
  762. // this.Data["json"] = br
  763. // this.ServeJSON()
  764. // }()
  765. // sysUser := this.SysUser
  766. // if sysUser == nil {
  767. // br.Msg = "请登录"
  768. // br.ErrMsg = "请登录,SysUser Is Empty"
  769. // br.Ret = 408
  770. // return
  771. // }
  772. // var req company.CompanyApplyApproveReq
  773. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  774. // if err != nil {
  775. // br.Msg = "参数解析异常!"
  776. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  777. // return
  778. // }
  779. // roleTypeCode := sysUser.RoleTypeCode
  780. // productId := services.GetProductId(roleTypeCode)
  781. // if productId == 0 {
  782. // br.Msg = "参数错误"
  783. // br.ErrMsg = "客户类型为:" + roleTypeCode
  784. // return
  785. // }
  786. // if req.CompanyId <= 0 {
  787. // br.Msg = "参数错误"
  788. // br.ErrMsg = "客户Id小于等于0:"
  789. // return
  790. // }
  791. // if req.Status != 1 && req.Status != 2 {
  792. // br.Msg = "参数错误"
  793. // br.ErrMsg = "审批状态Id小于等于0:"
  794. // return
  795. // }
  796. // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  797. // if err != nil {
  798. // br.Msg = "获取信息失败"
  799. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  800. // return
  801. // }
  802. // if companyProduct == nil {
  803. // br.Msg = "获取信息失败"
  804. // br.ErrMsg = "获取审批信息失败,Err:companyProduct 为空"
  805. // return
  806. // }
  807. //
  808. // approvalItem, err := company.GetCompanyApprovalById(req.CompanyId, productId)
  809. // if err != nil {
  810. // if err.Error() == utils.ErrNoRow() {
  811. // br.Msg = "订单已审批,请刷新页面查看最新状态"
  812. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  813. // return
  814. // }
  815. // br.Msg = "获取信息失败"
  816. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  817. // return
  818. // }
  819. // if approvalItem == nil {
  820. // br.Msg = "订单已审批,请刷新页面查看最新状态"
  821. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  822. // return
  823. // }
  824. //
  825. // if approvalItem.ApproveRoleTypeCode != roleTypeCode {
  826. // br.Msg = "您无权审批"
  827. // br.ErrMsg = "ApproveRoleTypeCode:" + approvalItem.ApproveRoleTypeCode + ";roleTypeCode:" + roleTypeCode
  828. // return
  829. // }
  830. //
  831. // var approveStatus, approveContent string
  832. //
  833. // if req.Status == 1 { //通过
  834. // //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新
  835. // if approvalItem.ApplyMethod == 1 { //试用转正式
  836. // //获取合同信息
  837. // contract, err := company.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
  838. // if err != nil {
  839. // br.Msg = "待审批信息不存在"
  840. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId) + ";Err:" + err.Error()
  841. // return
  842. // }
  843. // if contract == nil {
  844. // br.Msg = "待审批信息不存在"
  845. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  846. // return
  847. // }
  848. //
  849. // //格式化合同开始时间
  850. // contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
  851. // if err != nil {
  852. // br.Msg = "审批失败"
  853. // br.ErrMsg = "合同开始时间转换失败,Err:" + err.Error()
  854. // return
  855. // }
  856. // //格式化合同结束日期
  857. // contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
  858. // if err != nil {
  859. // br.Msg = "审批失败"
  860. // br.ErrMsg = "合同结束时间转换失败,Err:" + err.Error()
  861. // return
  862. // }
  863. // //格式化 产品中 合同结束日期
  864. // //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
  865. // //if err != nil {
  866. // // br.Msg = "审批失败"
  867. // // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
  868. // // return
  869. // //}
  870. // //如果合同时间小于等于今天,那么立马执行合同内容
  871. // if time.Now().After(contractStartDate) {
  872. // _, err = company.TryOutToFormal(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, contract.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType)
  873. // if err != nil {
  874. // br.Msg = "审批失败"
  875. // br.ErrMsg = "审批失败,Err:" + err.Error()
  876. // return
  877. // }
  878. // } else {
  879. // err = company.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
  880. // if err != nil {
  881. // br.Msg = "审批失败"
  882. // br.ErrMsg = "审批失败,Err:" + err.Error()
  883. // return
  884. // }
  885. // }
  886. // //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
  887. // if contractEndDate.After(companyProduct.ContractEndDate) {
  888. // companyProduct.ContractEndDate = contractEndDate
  889. // cols := make([]string, 0)
  890. // cols = append(cols, "ContractEndDate")
  891. // _ = companyProduct.Update(cols)
  892. // }
  893. // } else if approvalItem.ApplyMethod == 2 { //冻结->试用
  894. // _, _, _, err = company.FreezeToTryOut(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName)
  895. // if err != nil {
  896. // br.Msg = "审批失败"
  897. // br.ErrMsg = "审批失败,Err:" + err.Error()
  898. // return
  899. // }
  900. // } else if approvalItem.ApplyMethod == 3 { //试用延期
  901. // _, _, err = company.TryOutDelay(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, sysUser.RealName, companyProduct.EndDate, companyProduct.ProductName)
  902. // if err != nil {
  903. // br.Msg = "审批失败"
  904. // br.ErrMsg = "审批失败,Err:" + err.Error()
  905. // return
  906. // }
  907. // } else if approvalItem.ApplyMethod == 4 { //原销售申请领取流失客户
  908. // sellerItem, err := system.GetSysAdminById(approvalItem.ApplyUserId)
  909. // if err != nil {
  910. // br.Msg = "审批失败"
  911. // br.ErrMsg = "找不到申请的销售,Err:" + err.Error()
  912. // return
  913. // }
  914. // _, _, _, err = company.ApplyReceive(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, sellerItem, sysUser.RealName, companyProduct.ProductName, sellerItem.RealName, sellerItem.AdminId)
  915. // if err != nil {
  916. // br.Msg = "审批失败"
  917. // br.ErrMsg = "审批失败,Err:" + err.Error()
  918. // return
  919. // }
  920. // } else if approvalItem.ApplyMethod == 5 || approvalItem.ApplyMethod == 6 { //正式客户申请服务更新
  921. // //获取合同信息
  922. // contract, err := company.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
  923. // if err != nil {
  924. // br.Msg = "待审批信息不存在"
  925. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId) + ";Err:" + err.Error()
  926. // return
  927. // }
  928. // if contract == nil {
  929. // br.Msg = "待审批信息不存在"
  930. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  931. // return
  932. // }
  933. // //格式化合同开始时间
  934. // contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
  935. // if err != nil {
  936. // br.Msg = "审批失败"
  937. // br.ErrMsg = "合同开始时间转换失败,Err:" + err.Error()
  938. // return
  939. // }
  940. //
  941. // //格式化合同结束日期
  942. // contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
  943. // if err != nil {
  944. // br.Msg = "审批失败"
  945. // br.ErrMsg = "合同结束时间转换失败,Err:" + err.Error()
  946. // return
  947. // }
  948. // //格式化 产品中 合同结束日期
  949. // //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
  950. // //if err != nil {
  951. // // br.Msg = "审批失败"
  952. // // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
  953. // // return
  954. // //}
  955. //
  956. // //如果合同时间小于等于今天,那么立马执行合同内容
  957. // if time.Now().After(contractStartDate) {
  958. // _, err = company.ApplyServiceUpdate(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, companyProduct.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType)
  959. // if err != nil {
  960. // br.Msg = "审批失败"
  961. // br.ErrMsg = "审批失败,Err:" + err.Error()
  962. // return
  963. // }
  964. // } else {
  965. // err = company.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
  966. // if err != nil {
  967. // br.Msg = "审批失败"
  968. // br.ErrMsg = "审批失败,Err:" + err.Error()
  969. // return
  970. // }
  971. // }
  972. //
  973. // //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
  974. // if contractEndDate.After(companyProduct.ContractEndDate) {
  975. // companyProduct.ContractEndDate = contractEndDate
  976. // cols := make([]string, 0)
  977. // cols = append(cols, "ContractEndDate")
  978. // _ = companyProduct.Update(cols)
  979. // }
  980. // } else {
  981. // br.Msg = "审批失败"
  982. // br.ErrMsg = "无效的审批状态,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" +
  983. // strconv.Itoa(productId) + ";ApplyMethod:" + strconv.Itoa(approvalItem.ApplyMethod) + " ApproveStatus;" + approvalItem.ApproveStatus
  984. // return
  985. // }
  986. // approveContent = "审批通过"
  987. // } else { //拒绝
  988. // approveStatus = "驳回"
  989. // err = company.ApproveRefuse(req.CompanyId, productId, approveStatus, req.Remark)
  990. // approveContent = "审批驳回"
  991. // if err != nil {
  992. // br.Msg = "审批失败"
  993. // br.ErrMsg = "审批失败,Err:" + err.Error()
  994. // return
  995. // }
  996. // }
  997. //
  998. // //新增客户产品日志
  999. // {
  1000. // productLog := new(company.CompanyProductLog)
  1001. // productLog.CompanyProductId = companyProduct.CompanyProductId
  1002. // productLog.CompanyId = companyProduct.CompanyId
  1003. // productLog.ProductId = companyProduct.ProductId
  1004. // productLog.ProductName = companyProduct.ProductName
  1005. // productLog.CompanyName = companyProduct.CompanyName
  1006. // productLog.CompanyName = companyProduct.CompanyName
  1007. // productLog.Source = companyProduct.Source
  1008. // productLog.Reasons = companyProduct.Reasons
  1009. // productLog.Status = companyProduct.Status
  1010. // productLog.IndustryId = companyProduct.IndustryId
  1011. // productLog.IndustryName = companyProduct.IndustryName
  1012. // productLog.SellerId = companyProduct.SellerId
  1013. // productLog.SellerName = companyProduct.SellerName
  1014. // productLog.GroupId = companyProduct.GroupId
  1015. // productLog.DepartmentId = companyProduct.DepartmentId
  1016. // productLog.IsSuspend = companyProduct.IsSuspend
  1017. // productLog.SuspendTime = companyProduct.SuspendTime
  1018. // productLog.ApproveStatus = companyProduct.ApproveStatus
  1019. // productLog.FreezeTime = companyProduct.FreezeTime
  1020. // productLog.Remark = companyProduct.Remark
  1021. // productLog.StartDate = companyProduct.StartDate
  1022. // productLog.EndDate = companyProduct.EndDate
  1023. // productLog.CreateTime = companyProduct.CreateTime
  1024. // productLog.ModifyTime = companyProduct.ModifyTime
  1025. // productLog.LoseReason = companyProduct.LoseReason
  1026. // productLog.LossTime = companyProduct.LossTime
  1027. // productLog.LogType = "modify"
  1028. // productLog.LogCreateTime = time.Now()
  1029. // productLog.AdminId = this.SysUser.AdminId
  1030. // go company.AddCompanyProductLog(productLog)
  1031. // }
  1032. // //新增操作记录
  1033. // {
  1034. // remark := "审批"
  1035. // operation := "approve"
  1036. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
  1037. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, req.Remark, companyProduct.Status)
  1038. // }
  1039. // //待办通知
  1040. // {
  1041. // content := companyProduct.CompanyName + " " + approvalItem.ApproveContent + approveContent
  1042. // approvalSysUser, _ := system.GetSysAdminById(approvalItem.ApplyUserId)
  1043. // if sysUser != nil {
  1044. // //审批通过
  1045. // approvalStatus := 2
  1046. // if req.Status != 1 {
  1047. // //审批驳回
  1048. // approvalStatus = 3
  1049. // }
  1050. // go services.AddCompanyApprovalMessage(sysUser.AdminId, approvalItem.ApplyUserId, req.CompanyId, approvalItem.CompanyApprovalId, 2, 1, approvalStatus, companyProduct.CompanyName, content, content, approvalSysUser.Mobile)
  1051. // }
  1052. // }
  1053. // br.Ret = 200
  1054. // br.Success = true
  1055. // br.Msg = "审批成功"
  1056. //}
  1057. // ApplyDelete
  1058. // @Title 审批列表删除
  1059. // @Description 审批列表删除接口
  1060. // @Param request body company.CompanyApplyDeleteReq true "type json string"
  1061. // @Success Ret=200 删除成功
  1062. // @router /approval/delete [post]
  1063. func (this *CompanyApprovalController) ApplyDelete() {
  1064. br := new(models.BaseResponse).Init()
  1065. defer func() {
  1066. this.Data["json"] = br
  1067. this.ServeJSON()
  1068. }()
  1069. sysUser := this.SysUser
  1070. if sysUser == nil {
  1071. br.Msg = "请登录"
  1072. br.ErrMsg = "请登录,SysUser Is Empty"
  1073. br.Ret = 408
  1074. return
  1075. }
  1076. var req company.CompanyApplyDeleteReq
  1077. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1078. if err != nil {
  1079. br.Msg = "参数解析异常!"
  1080. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1081. return
  1082. }
  1083. roleTypeCode := sysUser.RoleTypeCode
  1084. productId := services.GetProductId(roleTypeCode)
  1085. if productId == 0 {
  1086. br.Msg = "参数错误"
  1087. br.ErrMsg = "客户类型为:" + roleTypeCode
  1088. return
  1089. }
  1090. if req.CompanyId <= 0 {
  1091. br.Msg = "参数错误"
  1092. br.ErrMsg = "客户Id小于等于0:"
  1093. return
  1094. }
  1095. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1096. if err != nil {
  1097. br.Msg = "获取信息失败"
  1098. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1099. return
  1100. }
  1101. if companyProduct == nil {
  1102. br.Msg = "获取信息失败"
  1103. br.ErrMsg = "获取审批信息失败,Err:" + err.Error()
  1104. return
  1105. }
  1106. approvalItem, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId)
  1107. if err != nil {
  1108. if err.Error() == utils.ErrNoRow() {
  1109. br.Msg = "待审批信息不存在"
  1110. br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1111. return
  1112. }
  1113. br.Msg = "获取信息失败"
  1114. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1115. return
  1116. }
  1117. if approvalItem == nil {
  1118. br.Msg = "待审批信息不存在"
  1119. br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1120. return
  1121. }
  1122. if approvalItem.ApproveStatus != "已撤回" {
  1123. br.Msg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除"
  1124. br.ErrMsg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除" + ";CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1125. return
  1126. }
  1127. //删除
  1128. err = company.ApplyDelete(req.CompanyId, req.CompanyApprovalId, approvalItem.ProductId, approvalItem.CompanyContractId)
  1129. if err != nil {
  1130. br.Msg = "删除失败"
  1131. br.ErrMsg = "删除失败,Err:" + err.Error()
  1132. return
  1133. }
  1134. //新增操作记录
  1135. {
  1136. remark := "删除审批申请"
  1137. operation := "approve_delete"
  1138. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
  1139. companyProduct.ProductName, sysUser.RealName, remark, operation, remark, sysUser.RealName, "", companyProduct.Status)
  1140. }
  1141. br.Ret = 200
  1142. br.Success = true
  1143. br.Msg = "删除成功"
  1144. }