approval.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. approval2 "hongze/hongze_mobile_admin/models/request/approval"
  7. "hongze/hongze_mobile_admin/models/response/approval"
  8. "hongze/hongze_mobile_admin/models/tables/admin"
  9. "hongze/hongze_mobile_admin/models/tables/company_approval"
  10. "hongze/hongze_mobile_admin/models/tables/company_contract"
  11. "hongze/hongze_mobile_admin/models/tables/company_delay_permission"
  12. "hongze/hongze_mobile_admin/models/tables/company_product"
  13. "hongze/hongze_mobile_admin/models/tables/company_product_log"
  14. "hongze/hongze_mobile_admin/models/tables/company_report_permission"
  15. "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
  16. "hongze/hongze_mobile_admin/services"
  17. "hongze/hongze_mobile_admin/services/flow"
  18. "hongze/hongze_mobile_admin/utils"
  19. "strconv"
  20. "time"
  21. )
  22. // 客户审批列表
  23. type ApprovalCommon struct {
  24. BaseAuth
  25. }
  26. // ListOld
  27. // @Title 获取审批列表接口
  28. // @Description 获取审批列表接口
  29. // @Param PageSize query int true "每页数据条数"
  30. // @Param CurrentIndex query int true "当前页页码,从1开始"
  31. // @Param Status query string true "状态:'待审批','已审批','驳回','已撤回'"
  32. // @Param KeyWord query string true "搜索关键词"
  33. // @Param Keyword query string true "搜索关键词"
  34. // @Param KeywordEq query string true "搜索关键词(全等)"
  35. // @Success 200 {object} approval.CompanyApprovalListResp
  36. // @router /list_old [get]
  37. func (c *ApprovalCommon) ListOld() {
  38. sysUser := c.AdminWx
  39. roleTypeCode := sysUser.RoleTypeCode
  40. pageSize, _ := c.GetInt("PageSize")
  41. currentIndex, _ := c.GetInt("CurrentIndex")
  42. status := c.GetString("Status")
  43. keyword := c.GetString("Keyword")
  44. keywordEq := c.GetString("KeywordEq")
  45. keyWord := c.GetString("KeyWord")
  46. if keyword == "" {
  47. keyword = keyWord
  48. }
  49. var startSize int
  50. if pageSize <= 0 {
  51. pageSize = utils.PageSize20
  52. }
  53. if currentIndex <= 0 {
  54. currentIndex = 1
  55. }
  56. startSize = paging.StartIndex(currentIndex, pageSize)
  57. var condition string
  58. var pars []interface{}
  59. if status != "" {
  60. if status == "已审批" {
  61. condition += ` AND c.approve_status IN('已审批','驳回') `
  62. } else {
  63. condition += ` AND c.approve_status=? `
  64. pars = append(pars, status)
  65. }
  66. }
  67. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
  68. condition += ` AND c.approve_role_type_code=? `
  69. pars = append(pars, roleTypeCode)
  70. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE { //超管或者合规
  71. } else { //销售
  72. condition += ` AND c.apply_user_id=? `
  73. pars = append(pars, sysUser.AdminId)
  74. }
  75. if keyword != "" {
  76. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%') `
  77. }
  78. if keywordEq != "" {
  79. condition += ` AND a.company_name = ? `
  80. pars = append(pars, keywordEq)
  81. }
  82. total, err := company_approval.GetApprovalCount(condition, pars)
  83. if err != nil {
  84. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  85. return
  86. }
  87. list, err := company_approval.GetApprovalList(condition, pars, startSize, pageSize)
  88. if err != nil {
  89. c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
  90. return
  91. }
  92. listLen := len(list)
  93. for i := 0; i < listLen; i++ {
  94. item := list[i]
  95. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  96. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  97. if time.Now().Before(freezeEndDate) {
  98. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  99. list[i].FreezeExpireDays = int(expireDays)
  100. }
  101. }
  102. if item.StartDate != "" && item.EndDate != "" {
  103. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  104. if time.Now().Before(endDate) {
  105. expireDays := endDate.Sub(time.Now()).Hours() / 24
  106. list[i].ExpireDay = int(expireDays)
  107. }
  108. }
  109. switch item.ApplyMethod {
  110. case 2:
  111. //客户冻结转试用次数
  112. approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
  113. if err != nil && err.Error() != utils.ErrNoRow() {
  114. c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error())
  115. return
  116. }
  117. list[i].ApprovalCount = approvalCount
  118. case 3:
  119. //延迟试用权限列表
  120. delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId)
  121. if err != nil && err.Error() != utils.ErrNoRow() {
  122. c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error())
  123. return
  124. }
  125. list[i].DelayPermission = delayPermission
  126. //客户审批试用延期次数
  127. approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
  128. if err != nil && err.Error() != utils.ErrNoRow() {
  129. c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error())
  130. return
  131. }
  132. list[i].ApprovalCount = approvalCount
  133. }
  134. if item.ApproveRoleTypeCode == roleTypeCode {
  135. list[i].OpButton = true
  136. }
  137. }
  138. page := paging.GetPaging(currentIndex, pageSize, total)
  139. resp := approval.CompanyApprovalListResp{
  140. Paging: page,
  141. List: list,
  142. }
  143. c.OkDetailed(resp, "获取成功")
  144. }
  145. // @Title 获取审批单详情接口
  146. // @Description 获取审批单详情接口
  147. // @Param ApprovalId query int true "审批单id"
  148. // @Success 200 {object} approval.CompanyApprovalDetailResp
  149. // @router /detail_old [get]
  150. func (c *ApprovalCommon) DetailOld() {
  151. sysUser := c.AdminWx
  152. roleTypeCode := sysUser.RoleTypeCode
  153. companyApprovalId, _ := c.GetInt("ApprovalId")
  154. var condition string
  155. var pars []interface{}
  156. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
  157. condition += ` AND c.approve_role_type_code=? `
  158. pars = append(pars, roleTypeCode)
  159. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售
  160. condition += ` AND c.apply_user_id=? `
  161. pars = append(pars, sysUser.AdminId)
  162. }
  163. item, err := company_approval.GetApprovalInfoByApprovalId(condition, pars, companyApprovalId)
  164. if err != nil {
  165. c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
  166. return
  167. }
  168. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  169. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  170. if time.Now().Before(freezeEndDate) {
  171. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  172. item.FreezeExpireDays = int(expireDays)
  173. }
  174. }
  175. if item.StartDate != "" && item.EndDate != "" {
  176. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  177. if time.Now().Before(endDate) {
  178. expireDays := endDate.Sub(time.Now()).Hours() / 24
  179. item.ExpireDay = int(expireDays)
  180. }
  181. }
  182. switch item.ApplyMethod {
  183. case 2:
  184. //客户冻结转试用次数
  185. approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
  186. if err != nil && err.Error() != utils.ErrNoRow() {
  187. c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error())
  188. return
  189. }
  190. item.ApprovalCount = approvalCount
  191. case 3:
  192. //客户审批试用延期次数
  193. approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
  194. if err != nil && err.Error() != utils.ErrNoRow() {
  195. c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error())
  196. return
  197. }
  198. item.ApprovalCount = approvalCount
  199. }
  200. //if item.ApplyMethod == 3 {
  201. // delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId)
  202. // if err != nil && err.Error() != utils.ErrNoRow() {
  203. // c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error())
  204. // return
  205. // }
  206. // item.DelayPermission = delayPermission
  207. //}
  208. if item.ApproveRoleTypeCode == roleTypeCode {
  209. item.OpButton = true
  210. }
  211. resp := approval.CompanyApprovalDetailResp{
  212. CompanyApprovalDetail: item,
  213. }
  214. //获取权限列表
  215. //子权限切片集合
  216. var permissionClassifyArr []string
  217. if item.ProductId == 1 {
  218. for _, v := range utils.PermissionFiccClassifyArr {
  219. permissionClassifyArr = append(permissionClassifyArr, v)
  220. }
  221. } else {
  222. permissionClassifyArr = append(permissionClassifyArr, "权益")
  223. }
  224. //获取需要审批的权限
  225. delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(item.CompanyId, item.CompanyApprovalId)
  226. if err != nil && err.Error() != utils.ErrNoRow() {
  227. c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error())
  228. return
  229. }
  230. delayPermissionIdMap := make(map[int]int)
  231. for _, delayPermission := range delayPermissionList {
  232. delayPermissionIdMap[delayPermission.ChartPermissionId] = 0
  233. }
  234. //遍历获取
  235. for _, v := range permissionClassifyArr {
  236. checkList := make([]int, 0)
  237. plist := new(company_report_permission.PermissionLookList)
  238. items, err := company_report_permission.GetPermissionLookItems(item.ProductId, v)
  239. if err != nil {
  240. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  241. return
  242. }
  243. for _, n := range items {
  244. if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
  245. checkList = append(checkList, n.ChartPermissionId)
  246. }
  247. }
  248. plist.Items = items
  249. plist.ClassifyName = v
  250. plist.CheckList = checkList
  251. if item.ProductId == 1 {
  252. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  253. } else {
  254. resp.PermissionList = append(resp.PermissionList, plist)
  255. }
  256. }
  257. //审批流
  258. flowId := 1
  259. if item.ProductId == 2 {
  260. flowId = 2
  261. }
  262. flowItem, err := flow.GetApprovalFlow(flowId)
  263. if err != nil {
  264. c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
  265. return
  266. }
  267. approveTime, err := time.Parse(utils.FormatDateTime, item.ApproveTime)
  268. if err != nil {
  269. c.FailWithMessage("获取失败", "审批时间转换失败,Err:"+err.Error())
  270. return
  271. }
  272. approvalTime, err := time.Parse(utils.FormatDateTime, item.ApprovalTime)
  273. if err != nil {
  274. c.FailWithMessage("获取失败", "发起时间转换失败,Err:"+err.Error())
  275. return
  276. }
  277. //当前审批流程id
  278. flowNodeListResp := make([][]contract_approval_record.ContractApprovalRecord, 0)
  279. for _, node := range flowItem.NodeList {
  280. flowNodeResp := make([]contract_approval_record.ContractApprovalRecord, 0)
  281. for _, user := range node.UserList {
  282. approveStatus := item.ApproveStatus
  283. if approveStatus == "驳回" {
  284. approveStatus = "已驳回"
  285. }
  286. approvalRecord := contract_approval_record.ContractApprovalRecord{
  287. //ContractApprovalRecordId int `orm:"column(contract_approval_record_id);pk"`
  288. //ContractApprovalId int `orm:"column(contract_approval_id)" description:"审批单id"`
  289. Status: approveStatus,
  290. ApproveRemark: item.ApproveRemark,
  291. ApproveRoleTypeCode: user.RoleTypeCode,
  292. ApproveUserId: user.AdminId,
  293. ApproveUserName: user.Name,
  294. NodeId: node.NodeId,
  295. NodeType: node.NodeType,
  296. //PrevNodeId int `description:"上级节点id"`
  297. //NextNodeId int `description:"下级节点id"`
  298. AuditType: node.AuditType,
  299. ApproveTime: approveTime,
  300. //ModifyTime time.Time `description:"发起申请时间"`
  301. CreateTime: approvalTime,
  302. }
  303. flowNodeResp = append(flowNodeResp, approvalRecord)
  304. if user.AdminId == item.ApproveUserId {
  305. resp.CompanyApprovalDetail.CurrNodeId = node.NodeId
  306. }
  307. }
  308. flowNodeListResp = append(flowNodeListResp, flowNodeResp)
  309. }
  310. resp.FlowNodeList = flowNodeListResp
  311. c.OkDetailed(resp, "获取成功")
  312. }
  313. // @Title 获取审批单中的权限列表
  314. // @Description 获取审批单中的权限列表接口
  315. // @Param ApprovalId query int true "审批单id"
  316. // @Success 200 {object} approval.CompanyPermissionResp
  317. // @router /getApprovalPermissionList [get]
  318. func (c *ApprovalCommon) GetApprovalPermissionList() {
  319. //c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  320. //返回基础参数
  321. resp := new(approval.CompanyPermissionResp)
  322. //获取审批单信息
  323. approvalId, _ := c.GetInt("ApprovalId")
  324. if approvalId <= 0 {
  325. c.FailWithMessage("审批单参数异常", "提交审批单参数异常")
  326. return
  327. }
  328. approvalInfo, err := company_approval.GetCompanyApprovalByApprovalId(approvalId)
  329. if err != nil {
  330. c.FailWithMessage("获取失败", "获取审批单数据失败,Err:"+err.Error())
  331. return
  332. }
  333. //子权限切片集合
  334. var permissionClassifyArr []string
  335. if approvalInfo.ProductId == 1 {
  336. for _, v := range utils.PermissionFiccClassifyArr {
  337. permissionClassifyArr = append(permissionClassifyArr, v)
  338. }
  339. } else {
  340. permissionClassifyArr = append(permissionClassifyArr, "权益")
  341. }
  342. //获取需要审批的权限
  343. delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(approvalInfo.CompanyId, approvalInfo.CompanyApprovalId)
  344. if err != nil && err.Error() != utils.ErrNoRow() {
  345. c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error())
  346. return
  347. }
  348. delayPermissionIdMap := make(map[int]int)
  349. for _, delayPermission := range delayPermissionList {
  350. delayPermissionIdMap[delayPermission.ChartPermissionId] = 0
  351. }
  352. //遍历获取
  353. for _, v := range permissionClassifyArr {
  354. checkList := make([]int, 0)
  355. plist := new(company_report_permission.PermissionLookList)
  356. items, err := company_report_permission.GetPermissionLookItems(approvalInfo.ProductId, v)
  357. if err != nil {
  358. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  359. return
  360. }
  361. for _, n := range items {
  362. if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
  363. checkList = append(checkList, n.ChartPermissionId)
  364. }
  365. }
  366. plist.Items = items
  367. plist.ClassifyName = v
  368. plist.CheckList = checkList
  369. if approvalInfo.ProductId == 1 {
  370. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  371. } else {
  372. resp.PermissionList = append(resp.PermissionList, plist)
  373. }
  374. }
  375. c.OkDetailed(resp, "获取成功")
  376. }
  377. // @Title 审批
  378. // @Description 审批接口
  379. // @Param request body approval.CompanyApplyApproveReq true "type json string"
  380. // @Success Ret=200 审批成功
  381. // @router /approve_old [post]
  382. func (c *ApprovalCommon) ApplyApproveOld() {
  383. sysUser := c.AdminWx
  384. var req approval2.CompanyApplyApproveReq
  385. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  386. if err != nil {
  387. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  388. return
  389. }
  390. roleTypeCode := sysUser.RoleTypeCode
  391. productId := services.GetProductId(roleTypeCode)
  392. if productId == 0 {
  393. c.FailWithMessage("参数错误", "参数解析失败,Err:"+"客户类型为:"+roleTypeCode)
  394. return
  395. }
  396. if req.CompanyId <= 0 {
  397. c.FailWithMessage("参数错误", "客户Id小于等于0")
  398. return
  399. }
  400. if req.Status != 1 && req.Status != 2 {
  401. c.FailWithMessage("参数错误", "审批状态Id小于等于0")
  402. return
  403. }
  404. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  405. if err != nil {
  406. c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
  407. return
  408. }
  409. if companyProduct == nil {
  410. c.FailWithMessage("获取审批信息失败", "获取信息失败,Err:"+err.Error())
  411. return
  412. }
  413. approvalItem, err := company_approval.GetCompanyApprovalByCompanyId(req.CompanyId, productId)
  414. if err != nil {
  415. if err.Error() == utils.ErrNoRow() {
  416. c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
  417. } else {
  418. c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
  419. }
  420. return
  421. }
  422. if approvalItem == nil {
  423. c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
  424. return
  425. }
  426. if approvalItem.ApproveRoleTypeCode != roleTypeCode {
  427. c.FailWithMessage("您无权审批", "ApproveRoleTypeCode:"+approvalItem.ApproveRoleTypeCode+";roleTypeCode:"+roleTypeCode)
  428. return
  429. }
  430. var approveStatus, approveContent string
  431. if req.Status == 1 { //通过
  432. //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
  433. if approvalItem.ApplyMethod == 1 { //试用转正式
  434. //获取合同信息
  435. contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
  436. if err != nil {
  437. c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)+";Err:"+err.Error())
  438. return
  439. }
  440. if contract == nil {
  441. c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
  442. return
  443. }
  444. //格式化合同开始时间
  445. contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
  446. if err != nil {
  447. c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error())
  448. return
  449. }
  450. //格式化合同结束日期
  451. contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
  452. if err != nil {
  453. c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error())
  454. return
  455. }
  456. //格式化 产品中 合同结束日期
  457. //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
  458. //if err != nil {
  459. // br.Msg = "审批失败"
  460. // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
  461. // return
  462. //}
  463. //如果合同时间小于等于今天,那么立马执行合同内容
  464. if time.Now().After(contractStartDate) {
  465. _, err = company_approval.TryOutToFormal(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, contract.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType)
  466. if err != nil {
  467. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  468. return
  469. }
  470. } else {
  471. err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
  472. if err != nil {
  473. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  474. return
  475. }
  476. }
  477. //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
  478. if contractEndDate.After(companyProduct.ContractEndDate) {
  479. companyProduct.ContractEndDate = contractEndDate
  480. cols := make([]string, 0)
  481. cols = append(cols, "ContractEndDate")
  482. _ = companyProduct.Update(cols)
  483. }
  484. } else if approvalItem.ApplyMethod == 2 { //冻结->试用
  485. _, _, _, err = company_approval.FreezeToTryOut(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName)
  486. if err != nil {
  487. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  488. return
  489. }
  490. } else if approvalItem.ApplyMethod == 3 { //试用延期
  491. _, _, err = company_approval.TryOutDelay(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, sysUser.RealName, companyProduct.EndDate, companyProduct.ProductName)
  492. if err != nil {
  493. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  494. return
  495. }
  496. } else if approvalItem.ApplyMethod == 4 { //原销售申请领取流失客户
  497. _, _, _, err = company_approval.ApplyReceive(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName)
  498. if err != nil {
  499. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  500. return
  501. }
  502. } else if approvalItem.ApplyMethod == 5 || approvalItem.ApplyMethod == 6 { //正式客户申请服务更新
  503. //获取合同信息
  504. contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
  505. if err != nil {
  506. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  507. return
  508. }
  509. if contract == nil {
  510. c.FailWithMessage("审批失败", "审批失败")
  511. return
  512. }
  513. //格式化合同开始时间
  514. contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
  515. if err != nil {
  516. c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error())
  517. return
  518. }
  519. //格式化合同结束日期
  520. contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
  521. if err != nil {
  522. c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error())
  523. return
  524. }
  525. //格式化 产品中 合同结束日期
  526. //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
  527. //if err != nil {
  528. // br.Msg = "审批失败"
  529. // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
  530. // return
  531. //}
  532. //如果合同时间小于等于今天,那么立马执行合同内容
  533. if time.Now().After(contractStartDate) {
  534. _, err = company_approval.ApplyServiceUpdate(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, companyProduct.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType)
  535. if err != nil {
  536. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  537. return
  538. }
  539. } else {
  540. err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
  541. if err != nil {
  542. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  543. return
  544. }
  545. }
  546. //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
  547. if contractEndDate.After(companyProduct.ContractEndDate) {
  548. companyProduct.ContractEndDate = contractEndDate
  549. cols := make([]string, 0)
  550. cols = append(cols, "ContractEndDate")
  551. _ = companyProduct.Update(cols)
  552. }
  553. } else {
  554. c.FailWithMessage("审批失败", "无效的审批状态,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+
  555. strconv.Itoa(productId)+";ApplyMethod:"+strconv.Itoa(approvalItem.ApplyMethod)+" ApproveStatus;"+approvalItem.ApproveStatus)
  556. return
  557. }
  558. approveContent = "审批通过"
  559. } else { //拒绝
  560. if req.Remark == "" {
  561. c.FailWithMessage("请填写驳回理由", "请填写驳回理由")
  562. return
  563. }
  564. approveStatus = "驳回"
  565. err = company_approval.ApproveRefuse(req.CompanyId, productId, approveStatus, req.Remark)
  566. approveContent = "审批驳回"
  567. if err != nil {
  568. c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
  569. return
  570. }
  571. }
  572. //新增客户产品日志
  573. {
  574. productLog := new(company_product_log.CompanyProductLog)
  575. productLog.CompanyProductId = companyProduct.CompanyProductId
  576. productLog.CompanyId = companyProduct.CompanyId
  577. productLog.ProductId = companyProduct.ProductId
  578. productLog.ProductName = companyProduct.ProductName
  579. productLog.CompanyName = companyProduct.CompanyName
  580. productLog.CompanyName = companyProduct.CompanyName
  581. productLog.Source = companyProduct.Source
  582. productLog.Reasons = companyProduct.Reasons
  583. productLog.Status = companyProduct.Status
  584. productLog.IndustryId = companyProduct.IndustryId
  585. productLog.IndustryName = companyProduct.IndustryName
  586. productLog.SellerId = companyProduct.SellerId
  587. productLog.SellerName = companyProduct.SellerName
  588. productLog.GroupId = companyProduct.GroupId
  589. productLog.DepartmentId = companyProduct.DepartmentId
  590. productLog.IsSuspend = companyProduct.IsSuspend
  591. productLog.SuspendTime = companyProduct.SuspendTime
  592. productLog.ApproveStatus = companyProduct.ApproveStatus
  593. productLog.FreezeTime = companyProduct.FreezeTime
  594. productLog.Remark = companyProduct.Remark
  595. productLog.StartDate = companyProduct.StartDate
  596. productLog.EndDate = companyProduct.EndDate
  597. productLog.CreateTime = companyProduct.CreateTime
  598. productLog.ModifyTime = companyProduct.ModifyTime
  599. productLog.LoseReason = companyProduct.LoseReason
  600. productLog.LossTime = companyProduct.LossTime
  601. productLog.LogType = "modify"
  602. productLog.LogCreateTime = time.Now()
  603. productLog.AdminId = c.AdminWx.AdminId
  604. go company_product_log.AddCompanyProductLog(productLog)
  605. }
  606. //新增操作记录
  607. {
  608. remark := "审批"
  609. operation := "approve"
  610. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
  611. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, req.Remark, companyProduct.Status)
  612. }
  613. //待办通知
  614. {
  615. content := companyProduct.CompanyName + " " + approvalItem.ApproveContent + approveContent
  616. approvalSysUser, _ := admin.GetAdminById(approvalItem.ApplyUserId)
  617. if sysUser != nil {
  618. approvalStatus := 1
  619. if req.Status == 1 {
  620. approvalStatus = 2
  621. } else {
  622. approvalStatus = 3
  623. }
  624. go services.AddCompanyApprovalMessage(sysUser.AdminId, approvalItem.ApplyUserId, req.CompanyId, approvalItem.CompanyApprovalId, 2, 1, approvalStatus, companyProduct.CompanyName, content, content, approvalSysUser.Mobile, "")
  625. }
  626. }
  627. c.OkWithMessage("审批操作成功")
  628. }
  629. // @Title 获取审批流详情接口
  630. // @Description 获取审批流详情接口
  631. // @Param FlowId query int true "审批流程id;1:ficc客户审批;2:权益客户审批;3:ficc合同审批,4:权益合同审批,5:用印审批(合同章),6:用印审批(公章、法人章)"
  632. // @Success 200 {object} approval_flow.ApprovalFlowItem
  633. // @router /flowDetail [get]
  634. func (c *ApprovalCommon) GetFlowDetail() {
  635. //sysUser := c.AdminWx
  636. flowId, _ := c.GetInt("FlowId", 0)
  637. if flowId <= 0 {
  638. c.FailWithMessage("参数异常", fmt.Sprint("审批流程id异常,FlowId:", flowId))
  639. return
  640. }
  641. flowItem, err := flow.GetApprovalFlow(flowId)
  642. if err != nil {
  643. c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
  644. return
  645. }
  646. formatFlowItem, err := flow.FormatApprovalFlow(flowItem)
  647. c.OkDetailed(formatFlowItem, "获取成功")
  648. }
  649. // CompanyList
  650. // @Title 根据客户名称获取已存在合同系统中客户名称列表
  651. // @Description 获取合同详情接口
  652. // @Param Keyword query string true "搜索关键字:客户名称、组织社会信用码"
  653. // @Success 200 {object} []string
  654. // @router /company_list [get]
  655. func (c *ApprovalCommon) CompanyList() {
  656. keyword := c.GetString("Keyword")
  657. //合同id
  658. if keyword == "" {
  659. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  660. return
  661. }
  662. companyNameList := make([]string, 0)
  663. list, err := company_approval.GetCompanyNameList(c.AdminWx.AdminId, keyword)
  664. if err != nil {
  665. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  666. return
  667. }
  668. for _, v := range list {
  669. companyNameList = append(companyNameList, v.CompanyName)
  670. }
  671. c.OkDetailed(companyNameList, "获取成功")
  672. }
  673. //// @Title 审批列表删除
  674. //// @Description 审批列表删除接口
  675. //// @Param request body company.CompanyApplyDeleteReq true "type json string"
  676. //// @Success Ret=200 删除成功
  677. //// @router /approval/delete [post]
  678. //func (c *CompanyApprovalController) ApplyDelete() {
  679. // br := new(models.BaseResponse).Init()
  680. // defer func() {
  681. // c.Data["json"] = br
  682. // c.ServeJSON()
  683. // }()
  684. // sysUser := c.SysUser
  685. // if sysUser == nil {
  686. // br.Msg = "请登录"
  687. // br.ErrMsg = "请登录,SysUser Is Empty"
  688. // br.Ret = 408
  689. // return
  690. // }
  691. // var req company.CompanyApplyDeleteReq
  692. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  693. // if err != nil {
  694. // br.Msg = "参数解析异常!"
  695. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  696. // return
  697. // }
  698. // roleTypeCode := sysUser.RoleTypeCode
  699. // productId := services.GetProductId(roleTypeCode)
  700. // if productId == 0 {
  701. // br.Msg = "参数错误"
  702. // br.ErrMsg = "客户类型为:" + roleTypeCode
  703. // return
  704. // }
  705. // if req.CompanyId <= 0 {
  706. // br.Msg = "参数错误"
  707. // br.ErrMsg = "客户Id小于等于0:"
  708. // return
  709. // }
  710. // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  711. // if err != nil {
  712. // br.Msg = "获取信息失败"
  713. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  714. // return
  715. // }
  716. // if companyProduct == nil {
  717. // br.Msg = "获取信息失败"
  718. // br.ErrMsg = "获取审批信息失败,Err:" + err.Error()
  719. // return
  720. // }
  721. // approvalItem, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId)
  722. // if err != nil {
  723. // if err.Error() == utils.ErrNoRow() {
  724. // br.Msg = "待审批信息不存在"
  725. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  726. // return
  727. // }
  728. // br.Msg = "获取信息失败"
  729. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  730. // return
  731. // }
  732. // if approvalItem == nil {
  733. // br.Msg = "待审批信息不存在"
  734. // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  735. // return
  736. // }
  737. // if approvalItem.ApproveStatus != "待审批" && approvalItem.ApproveStatus != "已撤回" {
  738. // br.Msg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除"
  739. // br.ErrMsg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除" + ";CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  740. // return
  741. // }
  742. // //删除
  743. // err = company.ApplyDelete(req.CompanyId, req.CompanyApprovalId, approvalItem.ProductId)
  744. // if err != nil {
  745. // br.Msg = "删除失败"
  746. // br.ErrMsg = "删除失败,Err:" + err.Error()
  747. // return
  748. // }
  749. // //新增操作记录
  750. // {
  751. // remark := "删除审批申请"
  752. // operation := "approve_delete"
  753. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
  754. // companyProduct.ProductName, sysUser.RealName, remark, operation, remark, sysUser.RealName, "", companyProduct.Status)
  755. // }
  756. // br.Ret = 200
  757. // br.Success = true
  758. // br.Msg = "删除成功"
  759. //}