pre_register.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. package contract
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-playground/validator/v10"
  6. "hongze/fms_api/controller/resp"
  7. "hongze/fms_api/global"
  8. "hongze/fms_api/models/base"
  9. "hongze/fms_api/models/crm"
  10. "hongze/fms_api/models/fms"
  11. "hongze/fms_api/models/system"
  12. crmService "hongze/fms_api/services/crm"
  13. fmsService "hongze/fms_api/services/fms"
  14. "hongze/fms_api/utils"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // // RegisterController 合同登记
  20. type PreRegisterController struct{}
  21. // InvoiceList
  22. // @Title 开票/到款列表
  23. // @Description 开票/到款列表
  24. // @Param Keyword query string false "关键词"
  25. // @Success 200 {object} fms.ContractInvoiceItem
  26. // @router /contract/pre_register/list [get]
  27. func (rg *PreRegisterController) List(c *gin.Context) {
  28. var req fms.PreRegisterListReq
  29. if e := c.BindQuery(&req); e != nil {
  30. err, ok := e.(validator.ValidationErrors)
  31. if !ok {
  32. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  33. return
  34. }
  35. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  36. return
  37. }
  38. pageSize := req.PageSize
  39. pageIndex := req.Current
  40. if pageSize <= 0 {
  41. pageSize = utils.PageSize20
  42. }
  43. if pageIndex <= 0 {
  44. pageIndex = 1
  45. }
  46. cond := ` invoice_type IN (3, 4) `
  47. pars := make([]interface{}, 0)
  48. if req.Keyword != "" {
  49. kw := "%" + req.Keyword + "%"
  50. cond += ` AND company_name LIKE ? `
  51. pars = append(pars, kw)
  52. }
  53. // 货币列表
  54. currencyOB := new(fms.CurrencyUnit)
  55. currencyCond := `enable = 1`
  56. currencyPars := make([]interface{}, 0)
  57. currencyList, e := currencyOB.List(currencyCond, currencyPars)
  58. if e != nil {
  59. resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
  60. return
  61. }
  62. unitMap := make(map[string]string)
  63. for i := range currencyList {
  64. unitMap[currencyList[i].Code] = currencyList[i].UnitName
  65. }
  66. page := new(base.Page)
  67. page.SetPageSize(req.PageSize)
  68. page.SetCurrent(req.Current)
  69. sortTypeMap := map[int]bool{0: false, 1: true, 2: false}
  70. page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: sortTypeMap[0]})
  71. total, list, e := fms.GetContractPreRegisterItemPageList(page, cond, pars)
  72. if e != nil {
  73. resp.FailMsg("获取失败", "获取预登记列表失败, Err: "+e.Error(), c)
  74. return
  75. }
  76. serviceMap := make(map[int]string, 0)
  77. registerIds := make([]int, 0)
  78. for i := range list {
  79. list[i].UnitName = unitMap[list[i].CurrencyUnit]
  80. registerIds = append(registerIds, list[i].ContractRegisterId)
  81. }
  82. if len(registerIds) > 0 {
  83. serviceMap, _, e = fmsService.GetContractServiceNameFormat(registerIds)
  84. if e != nil {
  85. resp.FailMsg("获取失败", e.Error(), c)
  86. return
  87. }
  88. }
  89. respList := make([]*fms.ContractPreRegisterList, 0)
  90. for _, v := range list {
  91. item := new(fms.ContractPreRegisterList)
  92. item.ContractPreRegisterItem = v
  93. item.ServicesName = serviceMap[v.ContractRegisterId]
  94. respList = append(respList, item)
  95. }
  96. page.SetTotal(total)
  97. baseData := new(base.BaseData)
  98. baseData.SetPage(page)
  99. baseData.SetList(respList)
  100. resp.OkData("获取成功", baseData, c)
  101. }
  102. // Add
  103. // @Title 新增预登记
  104. // @Description 新增预登记
  105. // @Param request body fms.PrepayAddReq true "type json string"
  106. // @Success 200 string "操作成功"
  107. // @router /contract/pre_register/add [post]
  108. func (rg *PreRegisterController) Add(c *gin.Context) {
  109. req := new(fms.PreRegisterAddReq)
  110. err := c.ShouldBind(&req)
  111. if err != nil {
  112. errs, ok := err.(validator.ValidationErrors)
  113. if !ok {
  114. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  115. return
  116. }
  117. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  118. return
  119. }
  120. claims, _ := c.Get("adminInfo")
  121. adminInfo := claims.(*system.SysAdmin)
  122. // 日期校验
  123. var startDate, endDate time.Time
  124. if req.StartDate != "" && req.EndDate != "" {
  125. startDate, err = time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
  126. if err != nil {
  127. resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+err.Error(), c)
  128. return
  129. }
  130. endDate, err = time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
  131. if err != nil {
  132. resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+err.Error(), c)
  133. return
  134. }
  135. }
  136. // 获取销售分组信息
  137. sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
  138. if e != nil {
  139. resp.FailData("获取销售失败", "Err:"+e.Error(), c)
  140. return
  141. }
  142. sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
  143. for i := range sellerList {
  144. sellerMap[sellerList[i].SellerId] = sellerList[i]
  145. }
  146. admin := new(crm.Admin)
  147. sellerIds := strings.Split(req.SellerIds, ",")
  148. if len(sellerIds) > 2 {
  149. resp.Fail("最多只能选择两个销售", c)
  150. return
  151. }
  152. var sellers []*crm.Admin
  153. var pars []interface{}
  154. cond := ``
  155. if len(sellerIds) > 0 {
  156. cond = ` admin_id in (?) `
  157. pars = append(pars, sellerIds)
  158. sellers, e = admin.List(cond, pars)
  159. if e != nil {
  160. resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
  161. return
  162. }
  163. }
  164. //新增合同
  165. ob := new(fms.ContractRegister)
  166. //ob.ContractCode = req.ContractCode
  167. ob.CompanyName = req.CompanyName
  168. ob.ProductIds = req.ProductIds
  169. ob.StartDate = startDate
  170. ob.EndDate = endDate
  171. ob.Set()
  172. if req.RegisterType == fms.ContractInvoiceTypePreMake {
  173. //sellerItem := sellerMap[r.SellerId]
  174. //if sellerItem == nil {
  175. // resp.Fail("销售信息异常", c)
  176. // return
  177. //}
  178. for _, v := range sellers {
  179. if v.DepartmentId == crm.SellerDepartmentId {
  180. ob.SellerId = v.AdminId
  181. ob.SellerName = v.AdminName
  182. } else if v.DepartmentId == crm.RaiSellerDepartmentId {
  183. ob.RaiSellerId = v.AdminId
  184. ob.RaiSellerName = v.AdminName
  185. }
  186. }
  187. }
  188. // 套餐信息
  189. serviceAmountMap := make(map[int]float64)
  190. serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
  191. if e != nil {
  192. resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
  193. return
  194. }
  195. if e = fms.CreateContractRegisterAndServicesAndPayMent(ob, serviceList); e != nil {
  196. resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
  197. return
  198. }
  199. for _, r := range req.List {
  200. // 货币及汇率
  201. rateList, e := fmsService.GetTodayCurrencyRateList()
  202. if e != nil {
  203. resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
  204. return
  205. }
  206. var rate float64
  207. for i := range rateList {
  208. if r.CurrencyUnit == rateList[i].Code {
  209. rate = rateList[i].RMBRate
  210. break
  211. }
  212. }
  213. if rate <= 0 {
  214. resp.FailMsg("操作失败", "货币汇率信息有误", c)
  215. return
  216. }
  217. registerDate, e := time.Parse(utils.FormatDate, r.RegisterDate)
  218. if e != nil {
  219. resp.FailMsg("日期转换失败", "日期转换失败, Err: "+e.Error(), c)
  220. return
  221. }
  222. v := &fms.ContractInvoice{
  223. ContractRegisterId: ob.ContractRegisterId,
  224. OriginAmount: r.Amount,
  225. CurrencyUnit: r.CurrencyUnit,
  226. InvoiceType: req.RegisterType,
  227. InvoiceDate: registerDate,
  228. AdminId: int(adminInfo.AdminId),
  229. AdminName: adminInfo.AdminName,
  230. Remark: r.Remark,
  231. ServiceProductId: r.ServiceProductId,
  232. IsPrePay: 1,
  233. StartDate: startDate,
  234. EndDate: endDate,
  235. TimeBase: base.TimeBase{},
  236. }
  237. v.Set()
  238. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.OriginAmount/rate), 64)
  239. v.Amount = a
  240. if req.RegisterType == fms.ContractInvoiceTypePreMake {
  241. sellerItem := sellerMap[r.SellerId]
  242. if sellerItem == nil {
  243. resp.Fail("销售信息异常", c)
  244. return
  245. }
  246. v.SellerId = sellerItem.SellerId
  247. v.SellerName = sellerItem.SellerName
  248. v.SellerGroupId = sellerItem.GroupId
  249. v.SellerGroupName = sellerItem.GroupName
  250. v.SellerTeamId = sellerItem.TeamId
  251. v.SellerTeamName = sellerItem.TeamName
  252. }
  253. // 新增开票到款记录
  254. if e = v.Create(); e != nil {
  255. resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
  256. return
  257. }
  258. //预登记列表
  259. pp := &fms.ContractPreRegister{
  260. ContractRegisterId: ob.ContractRegisterId,
  261. CompanyName: req.CompanyName,
  262. InvoiceType: req.RegisterType,
  263. InvoiceDate: registerDate,
  264. AdminId: int(adminInfo.AdminId),
  265. AdminName: adminInfo.AdminName,
  266. Remark: r.Remark,
  267. ServiceProductId: r.ServiceProductId,
  268. IsPrePay: 1,
  269. StartDate: startDate,
  270. EndDate: endDate,
  271. TimeBase: base.TimeBase{},
  272. }
  273. pp.Set()
  274. if pp.InvoiceType == fms.ContractInvoiceTypePreMake {
  275. //开票走开票字段
  276. pp.InvoiceId = v.ContractInvoiceId
  277. pp.InvoiceDate = registerDate
  278. pp.OriginAmount = r.Amount
  279. pp.CurrencyUnit = r.CurrencyUnit
  280. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.OriginAmount/rate), 64)
  281. pp.Amount = a
  282. sellerItem := sellerMap[r.SellerId]
  283. if sellerItem == nil {
  284. resp.Fail("销售信息异常", c)
  285. return
  286. }
  287. pp.SellerId = sellerItem.SellerId
  288. pp.SellerName = sellerItem.SellerName
  289. pp.SellerGroupId = sellerItem.GroupId
  290. pp.SellerGroupName = sellerItem.GroupName
  291. pp.SellerTeamId = sellerItem.TeamId
  292. pp.SellerTeamName = sellerItem.TeamName
  293. } else {
  294. //到款
  295. pp.ArriveId = v.ContractInvoiceId
  296. pp.ArriveDate = registerDate
  297. pp.ArriveOriginAmount = r.Amount
  298. pp.ArriveCurrencyUnit = r.CurrencyUnit
  299. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.ArriveOriginAmount/rate), 64)
  300. pp.ArriveAmount = a
  301. }
  302. // 新增开票到款记录
  303. if e = pp.Create(); e != nil {
  304. resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
  305. return
  306. }
  307. }
  308. // 开票到款汇总
  309. go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
  310. resp.Ok("操作成功", c)
  311. }
  312. // Edit
  313. // @Title 编辑预登记
  314. // @Description 编辑预登记
  315. // @Param request body fms.ContractRegisterEditReq true "type json string"
  316. // @Success 200 string "操作成功"
  317. // @router /contract/pre_register/edit [post]
  318. func (rg *PreRegisterController) Edit(c *gin.Context) {
  319. req := new(fms.PreRegisterEditReq)
  320. err := c.ShouldBind(&req)
  321. if err != nil {
  322. errs, ok := err.(validator.ValidationErrors)
  323. if !ok {
  324. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  325. return
  326. }
  327. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  328. return
  329. }
  330. claims, _ := c.Get("adminInfo")
  331. adminInfo := claims.(*system.SysAdmin)
  332. // 日期校验
  333. var startDate, endDate time.Time
  334. if req.StartDate != "" && req.EndDate != "" {
  335. startDate, err = time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
  336. if err != nil {
  337. resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+err.Error(), c)
  338. return
  339. }
  340. endDate, err = time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
  341. if err != nil {
  342. resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+err.Error(), c)
  343. return
  344. }
  345. }
  346. // 获取销售分组信息
  347. sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
  348. if e != nil {
  349. resp.FailData("获取销售失败", "Err:"+e.Error(), c)
  350. return
  351. }
  352. sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
  353. for i := range sellerList {
  354. sellerMap[sellerList[i].SellerId] = sellerList[i]
  355. }
  356. admin := new(crm.Admin)
  357. sellerIds := strings.Split(req.SellerIds, ",")
  358. if len(sellerIds) > 2 {
  359. resp.Fail("最多只能选择两个销售", c)
  360. return
  361. }
  362. var pars []interface{}
  363. cond := ` admin_id in (?) `
  364. pars = append(pars, sellerIds)
  365. sellers, e := admin.List(cond, pars)
  366. if e != nil {
  367. resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
  368. return
  369. }
  370. //修改合同
  371. ob := new(fms.ContractRegister)
  372. //ob.ContractCode = req.ContractCode
  373. ob.ContractRegisterId = req.ContractRegisterId
  374. ob.CompanyName = req.CompanyName
  375. ob.ProductIds = req.ProductIds
  376. ob.StartDate = startDate
  377. ob.EndDate = endDate
  378. ob.ModifyTime = time.Now().Local()
  379. if req.RegisterType == fms.ContractInvoiceTypePreMake {
  380. //sellerItem := sellerMap[r.SellerId]
  381. //if sellerItem == nil {
  382. // resp.Fail("销售信息异常", c)
  383. // return
  384. //}
  385. for _, v := range sellers {
  386. if v.DepartmentId == crm.SellerDepartmentId {
  387. ob.SellerId = v.AdminId
  388. ob.SellerName = v.AdminName
  389. } else if v.DepartmentId == crm.RaiSellerDepartmentId {
  390. ob.RaiSellerId = v.AdminId
  391. ob.RaiSellerName = v.AdminName
  392. }
  393. }
  394. }
  395. // 套餐信息
  396. serviceAmountMap := make(map[int]float64)
  397. serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
  398. if e != nil {
  399. resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
  400. return
  401. }
  402. updateCols := []string{
  403. "ProductIds", "CompanyName", "SellerId", "SellerName", "StartDate", "EndDate",
  404. "RaiSellerId", "RaiSellerName", "ModifyTime",
  405. }
  406. invoiceList := make([]*fms.ContractInvoice, 0)
  407. ppList := make([]*fms.ContractPreRegister, 0)
  408. for _, r := range req.List {
  409. // 货币及汇率
  410. rateList, e := fmsService.GetTodayCurrencyRateList()
  411. if e != nil {
  412. resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
  413. return
  414. }
  415. var rate float64
  416. for i := range rateList {
  417. if r.CurrencyUnit == rateList[i].Code {
  418. rate = rateList[i].RMBRate
  419. break
  420. }
  421. }
  422. if rate <= 0 {
  423. resp.FailMsg("操作失败", "货币汇率信息有误", c)
  424. return
  425. }
  426. registerDate, e := time.Parse(utils.FormatDate, r.RegisterDate)
  427. if e != nil {
  428. resp.FailMsg("日期转换失败", "日期转换失败, Err: "+e.Error(), c)
  429. return
  430. }
  431. v := &fms.ContractInvoice{
  432. ContractInvoiceId: r.InvoiceId,
  433. ContractRegisterId: ob.ContractRegisterId,
  434. OriginAmount: r.Amount,
  435. CurrencyUnit: r.CurrencyUnit,
  436. InvoiceType: req.RegisterType,
  437. InvoiceDate: registerDate,
  438. AdminId: int(adminInfo.AdminId),
  439. AdminName: adminInfo.AdminName,
  440. Remark: r.Remark,
  441. ServiceProductId: r.ServiceProductId,
  442. IsPrePay: 1,
  443. StartDate: startDate,
  444. EndDate: endDate,
  445. }
  446. v.TimeBase.ModifyTime = time.Now().Local()
  447. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.OriginAmount/rate), 64)
  448. v.Amount = a
  449. if req.RegisterType == fms.ContractInvoiceTypePreMake {
  450. sellerItem := sellerMap[r.SellerId]
  451. if sellerItem == nil {
  452. resp.Fail("销售信息异常", c)
  453. return
  454. }
  455. v.SellerId = sellerItem.SellerId
  456. v.SellerName = sellerItem.SellerName
  457. v.SellerGroupId = sellerItem.GroupId
  458. v.SellerGroupName = sellerItem.GroupName
  459. v.SellerTeamId = sellerItem.TeamId
  460. v.SellerTeamName = sellerItem.TeamName
  461. }
  462. invoiceList = append(invoiceList, v)
  463. //预登记列表
  464. pp := &fms.ContractPreRegister{
  465. ContractRegisterId: ob.ContractRegisterId,
  466. CompanyName: req.CompanyName,
  467. InvoiceType: req.RegisterType,
  468. InvoiceDate: registerDate,
  469. AdminId: int(adminInfo.AdminId),
  470. AdminName: adminInfo.AdminName,
  471. Remark: r.Remark,
  472. ServiceProductId: r.ServiceProductId,
  473. IsPrePay: 1,
  474. StartDate: startDate,
  475. EndDate: endDate,
  476. TimeBase: base.TimeBase{},
  477. }
  478. pp.Set()
  479. if pp.InvoiceType == fms.ContractInvoiceTypePreMake {
  480. //开票走开票字段
  481. pp.InvoiceDate = registerDate
  482. pp.OriginAmount = r.Amount
  483. pp.CurrencyUnit = r.CurrencyUnit
  484. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.OriginAmount/rate), 64)
  485. pp.Amount = a
  486. sellerItem := sellerMap[r.SellerId]
  487. if sellerItem == nil {
  488. resp.Fail("销售信息异常", c)
  489. return
  490. }
  491. pp.SellerId = sellerItem.SellerId
  492. pp.SellerName = sellerItem.SellerName
  493. pp.SellerGroupId = sellerItem.GroupId
  494. pp.SellerGroupName = sellerItem.GroupName
  495. pp.SellerTeamId = sellerItem.TeamId
  496. pp.SellerTeamName = sellerItem.TeamName
  497. } else {
  498. //到款
  499. pp.ArriveDate = registerDate
  500. pp.ArriveOriginAmount = r.Amount
  501. pp.ArriveCurrencyUnit = r.CurrencyUnit
  502. a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.ArriveOriginAmount/rate), 64)
  503. pp.ArriveAmount = a
  504. }
  505. ppList = append(ppList, pp)
  506. }
  507. invoiceUpdateCols := []string{
  508. "CurrencyUnit", "Amount", "InvoiceDate", "AdminId", "AdminName", "Remark",
  509. "ServiceProductId", "StartDate", "EndDate", "ModifyTime",
  510. }
  511. // 更新合同登记、套餐、开票到款
  512. if e = fms.UpdateContractPreRegister(ob, updateCols, serviceList, invoiceList, invoiceUpdateCols); e != nil {
  513. resp.FailMsg("操作失败", "更新合同及套餐失败, Err: "+e.Error(), c)
  514. return
  515. }
  516. // 开票到款汇总
  517. go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
  518. resp.Ok("操作成功", c)
  519. }
  520. // Del
  521. // @Title 删除到款预登记
  522. // @Description 删除到款预登记
  523. // @Param request body fms.ContractRegisterDelReq true "type json string"
  524. // @Success 200 string "操作成功"
  525. // @router /contract/pre_register/del [post]
  526. func (rg *PreRegisterController) Del(c *gin.Context) {
  527. req := new(fms.PreRegisterDelReq)
  528. err := c.ShouldBind(&req)
  529. if err != nil {
  530. errs, ok := err.(validator.ValidationErrors)
  531. if !ok {
  532. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  533. return
  534. }
  535. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  536. return
  537. }
  538. ob := new(fms.ContractInvoice)
  539. item, e := ob.Fetch(req.InvoiceId)
  540. if e != nil {
  541. if e == utils.ErrNoRow {
  542. resp.Fail("合同登记不存在或已被删除", c)
  543. return
  544. }
  545. resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
  546. return
  547. }
  548. e = item.Delete()
  549. if e != nil {
  550. resp.FailMsg("删除记录失败", "Err:"+e.Error(), c)
  551. return
  552. }
  553. // 操作日志
  554. //go func() {
  555. // opData := ""
  556. // opDataByte, e := json.Marshal(req)
  557. // if e != nil {
  558. // return
  559. // }
  560. // opData = string(opDataByte)
  561. //
  562. // logItem := new(fms.ContractRegisterLog)
  563. // logItem.ContractRegisterId = req.ContractRegisterId
  564. // logItem.AdminId = int(adminInfo.AdminId)
  565. // logItem.AdminName = adminInfo.RealName
  566. // logItem.OpData = opData
  567. // logItem.OpType = fms.ContractRegisterOpTypeDel
  568. // logItem.CreateTime = nowTime
  569. // if e = logItem.Create(); e != nil {
  570. // return
  571. // }
  572. //}()
  573. resp.Ok("操作成功", c)
  574. }
  575. // Detail
  576. // @Title 预登记记录详情
  577. // @Description 预登记记录详情
  578. // @Param request body fms.PreRegisterDetailReq true "type json string"
  579. // @Success 200 string "操作成功"
  580. // @router /contract/pre_register/detail [post]
  581. func (rg *PreRegisterController) Detail(c *gin.Context) {
  582. req := new(fms.PreRegisterDetailReq)
  583. err := c.ShouldBind(&req)
  584. if err != nil {
  585. errs, ok := err.(validator.ValidationErrors)
  586. if !ok {
  587. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  588. return
  589. }
  590. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  591. return
  592. }
  593. ob := new(fms.ContractRegister)
  594. item, e := ob.Fetch(req.ContractRegisterId)
  595. if e != nil {
  596. if e == utils.ErrNoRow {
  597. resp.Fail("合同登记不存在或已被删除", c)
  598. return
  599. }
  600. resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
  601. return
  602. }
  603. cond := `contract_register_id = ? AND invoice_type = ? `
  604. pars := make([]interface{}, 0)
  605. pars = append(pars, req.ContractRegisterId, req.InvoiceType)
  606. list, e := fms.GetContractInvoiceItemList(cond, pars)
  607. if e != nil {
  608. err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
  609. return
  610. }
  611. respItem := fms.ContractPreRegisterDetail{
  612. ContractRegister: item,
  613. List: list,
  614. }
  615. resp.OkData("获取成功", respItem, c)
  616. }