Contract.go 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. package controllers
  2. import (
  3. "ERP_storage/Nats"
  4. "ERP_storage/Nats/NatsServer"
  5. "ERP_storage/conf"
  6. "ERP_storage/logs"
  7. "ERP_storage/models/Account"
  8. "ERP_storage/models/Basic"
  9. "ERP_storage/models/Contract"
  10. "ERP_storage/models/Stock"
  11. "fmt"
  12. "math"
  13. "net/url"
  14. "os"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "github.com/beego/beego/v2/adapter/orm"
  19. beego "github.com/beego/beego/v2/server/web"
  20. "github.com/robfig/cron/v3"
  21. "github.com/xuri/excelize/v2"
  22. natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
  23. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  24. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  25. )
  26. type ContractController struct {
  27. beego.Controller
  28. User userlibs.User
  29. }
  30. func (c *ContractController) Prepare() {
  31. c.User = *Account.User_r
  32. }
  33. func (c *ContractController) Contract_GenT_number() {
  34. o := orm.NewOrm()
  35. ContractDao := Contract.NewContract(o)
  36. T_number := ""
  37. rand_x := 1
  38. for true {
  39. T_number = fmt.Sprintf("GZBZD-%s%03d", time.Now().Format("20060102"), rand_x)
  40. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  41. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  42. break
  43. }
  44. rand_x += 1
  45. }
  46. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  47. c.ServeJSON()
  48. return
  49. }
  50. func (c *ContractController) Contract_List() {
  51. // 分页参数 初始化
  52. page, _ := c.GetInt("page")
  53. if page < 1 {
  54. page = 1
  55. }
  56. page_z, _ := c.GetInt("page_z")
  57. if page_z < 1 {
  58. page_z = conf.Page_size
  59. }
  60. // 查询
  61. T_name := c.GetString("T_name")
  62. T_state, _ := c.GetInt("T_state")
  63. userList, _ := NatsServer.Read_User_List_All()
  64. Account.Read_User_All_Map(userList)
  65. ContractDao := Contract.NewContract(orm.NewOrm())
  66. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, T_state, 0, page, page_z)
  67. var r_jsons lib.R_JSONS
  68. r_jsons.Num = R_cnt
  69. r_jsons.Data = R_List
  70. r_jsons.Page = page
  71. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  72. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  73. c.ServeJSON()
  74. return
  75. }
  76. func (c *ContractController) Contract_User_List() {
  77. // 分页参数 初始化
  78. page, _ := c.GetInt("page")
  79. if page < 1 {
  80. page = 1
  81. }
  82. page_z, _ := c.GetInt("page_z")
  83. if page_z < 1 {
  84. page_z = conf.Page_size
  85. }
  86. // 查询
  87. T_name := c.GetString("T_name")
  88. T_state, _ := c.GetInt("T_state")
  89. userList, _ := NatsServer.Read_User_List_All()
  90. Account.Read_User_All_Map(userList)
  91. ContractDao := Contract.NewContract(orm.NewOrm())
  92. R_List, R_cnt := ContractDao.Read_Contract_List(c.User.T_uuid, T_name, T_state, 0, page, page_z)
  93. var r_jsons lib.R_JSONS
  94. r_jsons.Num = R_cnt
  95. r_jsons.Data = R_List
  96. r_jsons.Page = page
  97. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  98. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  99. c.ServeJSON()
  100. return
  101. }
  102. func (c *ContractController) Contract_Get() {
  103. // 查询
  104. T_number := c.GetString("T_number")
  105. o := orm.NewOrm()
  106. ContractDao := Contract.NewContract(o)
  107. DeviceDao := Stock.NewDevice(o)
  108. ContractProductDao := Contract.NewContractProduct(o)
  109. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  110. if err != nil {
  111. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  112. c.ServeJSON()
  113. return
  114. }
  115. productList := ContractProductDao.Read_ContractProduct_List(contract.T_number)
  116. var pList []Contract.ContractProduct_R
  117. for _, v := range productList {
  118. p := Contract.ContractProductToContractProduct_R(v)
  119. p.T_device_list, _ = DeviceDao.Read_DeviceSn_List(T_number, v.T_product_id, "", "")
  120. pList = append(pList, p)
  121. }
  122. userList, _ := NatsServer.Read_User_List_All()
  123. Account.Read_User_All_Map(userList)
  124. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Contract.ContractToContract_Detail(contract, pList)}
  125. c.ServeJSON()
  126. return
  127. }
  128. func (c *ContractController) Contract_Add() {
  129. T_number := c.GetString("T_number")
  130. T_customer := c.GetString("T_customer")
  131. T_money, _ := c.GetFloat("T_money") // 总价
  132. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  133. T_date := c.GetString("T_date")
  134. T_product := c.GetString("T_product")
  135. T_remark := c.GetString("T_remark")
  136. T_pdf := c.GetString("T_pdf")
  137. T_project := c.GetString("T_project")
  138. T_recoveries := c.GetString("T_recoveries")
  139. T_invoice := c.GetString("T_invoice")
  140. T_submit := c.GetString("T_submit")
  141. if len(T_submit) == 0 {
  142. T_submit = c.User.T_uuid
  143. }
  144. var_ := Contract.Contract{
  145. T_number: T_number,
  146. T_customer: T_customer,
  147. T_money: float32(T_money),
  148. T_discount: float32(T_discount),
  149. T_project: T_project,
  150. T_type: 1, //合同类型 1-销售合同 2-验证合同
  151. T_date: T_date,
  152. T_out: 1,
  153. T_State: 3,
  154. T_remark: T_remark,
  155. T_pdf: T_pdf,
  156. T_submit: T_submit,
  157. T_recoveries: T_recoveries,
  158. T_invoice: T_invoice,
  159. }
  160. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  161. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  162. o := orm.NewOrm()
  163. o.Begin()
  164. ContractDao := Contract.NewContract(o)
  165. ContractProductDao := Contract.NewContractProduct(o)
  166. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  167. if err == nil {
  168. o.Rollback()
  169. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  170. c.ServeJSON()
  171. return
  172. }
  173. _, err = ContractDao.Add_Contract(var_)
  174. if err != nil {
  175. o.Rollback()
  176. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  177. c.ServeJSON()
  178. return
  179. }
  180. if len(T_product) == 0 {
  181. o.Rollback()
  182. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同产品明细不能为空"}
  183. c.ServeJSON()
  184. return
  185. }
  186. productList := lib.SplitString(T_product, "|")
  187. for _, v := range productList {
  188. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  189. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  190. contractProduct := Contract.ContractProduct{
  191. T_contract_number: T_number,
  192. T_product_id: product_id,
  193. T_product_total: num,
  194. T_product_out: 0, // 已出库数量
  195. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  196. }
  197. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  198. if err != nil {
  199. o.Rollback()
  200. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  201. c.ServeJSON()
  202. return
  203. }
  204. }
  205. o.Commit()
  206. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "添加", var_)
  207. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  208. c.ServeJSON()
  209. return
  210. }
  211. func (c *ContractController) Contract_Approval() {
  212. T_number := c.GetString("T_number")
  213. T_state, _ := c.GetInt("T_state")
  214. o := orm.NewOrm()
  215. ContractDao := Contract.NewContract(o)
  216. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  217. if err != nil {
  218. o.Rollback()
  219. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. // 1-已通过 2-未通过
  224. contract.T_State = T_state
  225. contract.T_approver = c.User.T_uuid
  226. err = ContractDao.Update_Contract(contract, "T_State", "T_approver")
  227. if err != nil {
  228. o.Rollback()
  229. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  230. c.ServeJSON()
  231. return
  232. }
  233. if T_state == 1 {
  234. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核已通过", T_number), conf.ContractApprovalUrl)
  235. }
  236. if T_state == 2 {
  237. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核未通过", T_number), conf.ContractApprovalUrl)
  238. }
  239. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "审核", contract)
  240. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  241. c.ServeJSON()
  242. return
  243. }
  244. func (c *ContractController) Contract_Edit() {
  245. T_number := c.GetString("T_number")
  246. T_customer := c.GetString("T_customer")
  247. T_money, _ := c.GetFloat("T_money")
  248. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  249. T_date := c.GetString("T_date")
  250. T_product := c.GetString("T_product")
  251. T_remark := c.GetString("T_remark")
  252. T_pdf := c.GetString("T_pdf")
  253. T_project := c.GetString("T_project")
  254. T_recoveries := c.GetString("T_recoveries")
  255. T_invoice := c.GetString("T_invoice")
  256. T_submit := c.GetString("T_submit")
  257. o := orm.NewOrm()
  258. o.Begin()
  259. ContractDao := Contract.NewContract(o)
  260. ContractProductDao := Contract.NewContractProduct(o)
  261. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  262. if err != nil {
  263. o.Rollback()
  264. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  265. c.ServeJSON()
  266. return
  267. }
  268. if len(T_customer) > 0 {
  269. contract.T_customer = T_customer
  270. }
  271. if T_money > 0 {
  272. contract.T_money = float32(T_money)
  273. }
  274. if T_discount > 0 {
  275. contract.T_discount = float32(T_discount)
  276. }
  277. if len(T_date) > 0 {
  278. contract.T_date = T_date
  279. }
  280. if len(T_remark) > 0 {
  281. contract.T_remark = T_remark
  282. }
  283. if len(T_pdf) > 0 {
  284. contract.T_pdf = T_pdf
  285. }
  286. if len(T_project) > 0 {
  287. contract.T_project = T_project
  288. }
  289. if len(T_recoveries) > 0 {
  290. contract.T_recoveries = T_recoveries
  291. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  292. }
  293. if len(T_invoice) > 0 {
  294. contract.T_invoice = T_invoice
  295. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  296. }
  297. if len(T_submit) > 0 {
  298. contract.T_submit = T_submit
  299. }
  300. //1-已通过 2-未通过 3-待审核 合同状态为未通过,修改之后将状态更改为待审核
  301. if contract.T_State == 2 {
  302. contract.T_State = 3
  303. }
  304. err = ContractDao.Update_Contract(contract, "T_customer", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State",
  305. "T_project", "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_submit")
  306. if err != nil {
  307. o.Rollback()
  308. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  309. c.ServeJSON()
  310. return
  311. }
  312. if len(T_product) == 0 {
  313. o.Rollback()
  314. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同产品明细不能为空"}
  315. c.ServeJSON()
  316. return
  317. }
  318. productList := lib.SplitString(T_product, "|")
  319. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(T_number)
  320. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  321. // 检查编辑时需要修改的产品
  322. for k, v := range needToDeleteList {
  323. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  324. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  325. if v > 0 {
  326. o.Rollback()
  327. product, _ := Basic.Read_Product_ById(productId)
  328. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  329. c.ServeJSON()
  330. return
  331. }
  332. cp := Contract.ContractProduct{Id: id}
  333. err = ContractProductDao.Delete_ContractProduct(cp)
  334. if err != nil {
  335. o.Rollback()
  336. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  337. c.ServeJSON()
  338. return
  339. }
  340. }
  341. for _, v := range productList {
  342. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  343. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  344. oldContractProduct, ok := allList[product_id]
  345. if !ok {
  346. contractProduct := Contract.ContractProduct{
  347. T_contract_number: T_number,
  348. T_product_id: product_id,
  349. T_product_total: num,
  350. T_product_out: 0, // 已出库数量
  351. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  352. }
  353. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  354. if err != nil {
  355. o.Rollback()
  356. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  357. c.ServeJSON()
  358. return
  359. } else {
  360. continue
  361. }
  362. }
  363. // 修改产品总数量
  364. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  365. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  366. if oldNum == num {
  367. continue
  368. }
  369. cp := Contract.ContractProduct{Id: contractProductId, T_product_total: num}
  370. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
  371. if err != nil {
  372. o.Rollback()
  373. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  374. c.ServeJSON()
  375. return
  376. }
  377. }
  378. o.Commit()
  379. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "修改", contract)
  380. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  381. c.ServeJSON()
  382. return
  383. }
  384. func (c *ContractController) Contract_Del() {
  385. T_number := c.GetString("T_number")
  386. o := orm.NewOrm()
  387. o.Begin()
  388. ContractDao := Contract.NewContract(o)
  389. ContractProductDao := Contract.NewContractProduct(o)
  390. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  391. if err != nil {
  392. o.Rollback()
  393. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  394. c.ServeJSON()
  395. return
  396. }
  397. //1-已通过 2-未通过 3-待审核 审核状态
  398. if contract.T_State == 1 {
  399. o.Rollback()
  400. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同已审核通过,禁止删除!"}
  401. c.ServeJSON()
  402. return
  403. }
  404. err = ContractDao.Delete_Contract(contract)
  405. if err != nil {
  406. o.Rollback()
  407. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  408. c.ServeJSON()
  409. return
  410. }
  411. //合同类型 1-销售合同 2-验证合同
  412. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  413. for _, v := range cpList {
  414. err = ContractProductDao.Delete_ContractProduct(v)
  415. if err != nil {
  416. o.Rollback()
  417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  418. c.ServeJSON()
  419. return
  420. }
  421. }
  422. o.Commit()
  423. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "删除", T_number)
  424. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  425. c.ServeJSON()
  426. return
  427. }
  428. func (c *ContractController) Contract_List_For_Out() {
  429. // 分页参数 初始化
  430. page, _ := c.GetInt("page")
  431. if page < 1 {
  432. page = 1
  433. }
  434. page_z, _ := c.GetInt("page_z")
  435. if page_z < 1 {
  436. page_z = conf.Page_size
  437. }
  438. // 查询
  439. T_name := c.GetString("T_name")
  440. userList, _ := NatsServer.Read_User_List_All()
  441. Account.Read_User_All_Map(userList)
  442. ContractDao := Contract.NewContract(orm.NewOrm())
  443. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 1, 1, page, page_z)
  444. var r_jsons lib.R_JSONS
  445. r_jsons.Num = R_cnt
  446. r_jsons.Data = R_List
  447. r_jsons.Page = page
  448. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  449. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  450. c.ServeJSON()
  451. return
  452. }
  453. // 合同下的产品列表 出库时使用
  454. func (c *ContractController) Contract_Product_List() {
  455. // 查询
  456. T_number := c.GetString("T_number")
  457. T_depot_id, _ := c.GetInt("T_depot_id")
  458. o := orm.NewOrm()
  459. ContractDao := Contract.NewContract(o)
  460. ContractProductDao := Contract.NewContractProduct(o)
  461. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  462. if err != nil {
  463. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  464. c.ServeJSON()
  465. return
  466. }
  467. productList := ContractProductDao.Read_ContractProduct_OutList(contract.T_number)
  468. Stock.Read_Stock_All_Map(T_depot_id)
  469. var pList []Contract.ContractProduct_Out
  470. for _, v := range productList {
  471. p := Contract.ContractProductToContractProduct_Out(v)
  472. p.T_stock_total = Stock.Read_Stock_Get(T_depot_id, p.T_product_id)
  473. pList = append(pList, p)
  474. }
  475. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: pList}
  476. c.ServeJSON()
  477. return
  478. }
  479. // 检查需要删除的合同产品列表
  480. func Check_NeedToDelete_Product_List(list []string, newList []Contract.ContractProduct) (needToDelete map[string]int, all map[int]string) {
  481. var productMap = map[int]int{}
  482. needToDelete = make(map[string]int)
  483. all = make(map[int]string)
  484. for _, v := range list {
  485. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  486. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  487. productMap[product_id] = num
  488. }
  489. for _, product := range newList {
  490. all[product.T_product_id] = fmt.Sprintf("%d-%d-%f", product.Id, product.T_product_total, product.T_price)
  491. _, ok := productMap[product.T_product_id]
  492. if !ok {
  493. id := fmt.Sprintf("%d-%d-%f", product.Id, product.T_product_id, product.T_price)
  494. needToDelete[id] = product.T_product_out
  495. }
  496. }
  497. return
  498. }
  499. // 验证合同
  500. func (c *ContractController) VerifyContract_List() {
  501. // 分页参数 初始化
  502. page, _ := c.GetInt("page")
  503. if page < 1 {
  504. page = 1
  505. }
  506. page_z, _ := c.GetInt("page_z")
  507. if page_z < 1 {
  508. page_z = conf.Page_size
  509. }
  510. T_customer_id := c.GetString("T_customer_id")
  511. T_customer_name := c.GetString("T_customer_name")
  512. // 查询
  513. T_name := c.GetString("T_name")
  514. userList, _ := NatsServer.Read_User_List_All()
  515. Account.Read_User_All_Map(userList)
  516. Contract.Read_VerifyContract_All_Map()
  517. ContractDao := Contract.NewContract(orm.NewOrm())
  518. R_List, R_cnt := ContractDao.Read_VerifyContract_List(T_name, T_customer_id, T_customer_name, page, page_z)
  519. var r_jsons lib.R_JSONS
  520. r_jsons.Num = R_cnt
  521. r_jsons.Data = R_List
  522. r_jsons.Page = page
  523. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  524. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  525. c.ServeJSON()
  526. return
  527. }
  528. // 验证合同呢添加
  529. func (c *ContractController) VerifyContract_Add() {
  530. T_number := c.GetString("T_number")
  531. T_customer_id := c.GetString("T_customer_id")
  532. T_money, _ := c.GetFloat("T_money")
  533. T_discount, _ := c.GetFloat("T_discount")
  534. T_date := c.GetString("T_date")
  535. T_product := c.GetString("T_product")
  536. T_submit := c.GetString("T_submit")
  537. T_remark := c.GetString("T_remark")
  538. T_pdf := c.GetString("T_pdf")
  539. T_project := c.GetString("T_project")
  540. T_recoveries := c.GetString("T_recoveries")
  541. T_invoice := c.GetString("T_invoice")
  542. T_start_date := c.GetString("T_start_date")
  543. T_end_date := c.GetString("T_end_date")
  544. T_stamping_date := c.GetString("T_stamping_date")
  545. T_payment_method := c.GetString("T_payment_method")
  546. var_ := Contract.Contract{
  547. T_number: T_number,
  548. T_customer_id: T_customer_id,
  549. T_money: float32(T_money),
  550. T_discount: float32(T_discount),
  551. T_project: T_project,
  552. T_type: 2, //合同类型 1-销售合同 2-验证合同
  553. T_date: T_date,
  554. T_State: 1,
  555. T_remark: T_remark,
  556. T_pdf: T_pdf,
  557. T_submit: T_submit,
  558. T_recoveries: T_recoveries,
  559. T_invoice: T_invoice,
  560. T_start_date: T_start_date,
  561. T_end_date: T_end_date,
  562. T_stamping_date: T_stamping_date,
  563. T_payment_method: T_payment_method,
  564. }
  565. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  566. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  567. o := orm.NewOrm()
  568. o.Begin()
  569. ContractDao := Contract.NewContract(o)
  570. ContractProductDao := Contract.NewContractProduct(o)
  571. // 暂时屏蔽验证合同时间检查
  572. //_, err := ContractDao.Read_Contract_ByT_date(T_customer_id, T_start_date, T_end_date)
  573. //if err == nil {
  574. // o.Rollback()
  575. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同签约时间重复!"}
  576. // c.ServeJSON()
  577. // return
  578. //}
  579. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  580. if err == nil {
  581. o.Rollback()
  582. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  583. c.ServeJSON()
  584. return
  585. }
  586. ContractID, err := ContractDao.Add_Contract(var_)
  587. if err != nil {
  588. o.Rollback()
  589. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  590. c.ServeJSON()
  591. return
  592. }
  593. if len(T_product) == 0 {
  594. o.Rollback()
  595. c.Data["json"] = lib.JSONS{Code: 202, Msg: "验证合同明细不能为空"}
  596. c.ServeJSON()
  597. return
  598. }
  599. productList := lib.SplitString(T_product, "|")
  600. ContractOut := 0
  601. for _, v := range productList {
  602. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  603. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  604. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  605. product, _ := Basic.Read_Product_ById(product_id)
  606. contractProduct := Contract.ContractProduct{
  607. T_contract_number: T_number,
  608. T_product_id: product_id,
  609. T_product_total: num,
  610. T_product_out: 0, // 已出库数量
  611. T_price: float32(price), // 价格
  612. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  613. }
  614. if product.T_class < 0 {
  615. contractProduct.T_State = 3
  616. }
  617. if product.T_class == 0 {
  618. ContractOut = 1
  619. }
  620. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  621. if err != nil {
  622. o.Rollback()
  623. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  624. c.ServeJSON()
  625. return
  626. }
  627. }
  628. o.Commit()
  629. o2 := orm.NewOrm()
  630. ContractDao2 := Contract.NewContract(o2)
  631. if ContractOut == 1 {
  632. err = ContractDao2.Update_Contract(Contract.Contract{Id: int(ContractID), T_out: ContractOut}, "T_out")
  633. if err != nil {
  634. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新合同出库状态失败"}
  635. c.ServeJSON()
  636. return
  637. }
  638. }
  639. err = Update_VerifyContract_State(T_customer_id, "ADD")
  640. if err != nil {
  641. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  642. c.ServeJSON()
  643. return
  644. }
  645. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加", var_)
  646. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  647. c.ServeJSON()
  648. return
  649. }
  650. // 验证合同呢修改
  651. func (c *ContractController) VerifyContract_Edit() {
  652. Id, _ := c.GetInt("Id")
  653. T_number := c.GetString("T_number")
  654. T_money, _ := c.GetFloat("T_money")
  655. T_discount, _ := c.GetFloat("T_discount")
  656. T_date := c.GetString("T_date")
  657. T_product := c.GetString("T_product")
  658. T_remark := c.GetString("T_remark")
  659. T_pdf := c.GetString("T_pdf")
  660. T_project := c.GetString("T_project")
  661. T_recoveries := c.GetString("T_recoveries")
  662. T_invoice := c.GetString("T_invoice")
  663. T_start_date := c.GetString("T_start_date")
  664. T_end_date := c.GetString("T_end_date")
  665. T_submit := c.GetString("T_submit")
  666. T_stamping_date := c.GetString("T_stamping_date")
  667. T_payment_method := c.GetString("T_payment_method")
  668. o := orm.NewOrm()
  669. o.Begin()
  670. ContractDao := Contract.NewContract(o)
  671. ContractProductDao := Contract.NewContractProduct(o)
  672. contract, err := ContractDao.Read_Contract_ById(Id)
  673. if err != nil || contract.T_type == 1 {
  674. o.Rollback()
  675. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  676. c.ServeJSON()
  677. return
  678. }
  679. oldT_number := contract.T_number
  680. if T_number != oldT_number {
  681. _, err1 := ContractDao.Read_Contract_ByT_number(T_number)
  682. if err1 == nil {
  683. o.Rollback()
  684. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("合同编号%s已存在!", T_number)}
  685. c.ServeJSON()
  686. return
  687. }
  688. contract.T_number = T_number
  689. }
  690. if T_money > 0 {
  691. contract.T_money = float32(T_money)
  692. }
  693. if T_discount > 0 {
  694. contract.T_discount = float32(T_discount)
  695. }
  696. if len(T_date) > 0 {
  697. contract.T_date = T_date
  698. }
  699. if len(T_remark) > 0 {
  700. contract.T_remark = T_remark
  701. }
  702. if len(T_pdf) > 0 {
  703. contract.T_pdf = T_pdf
  704. }
  705. if len(T_project) > 0 {
  706. contract.T_project = T_project
  707. }
  708. if len(T_recoveries) > 0 {
  709. contract.T_recoveries = T_recoveries
  710. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  711. }
  712. if len(T_invoice) > 0 {
  713. contract.T_invoice = T_invoice
  714. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  715. }
  716. if len(T_start_date) > 0 {
  717. contract.T_start_date = T_start_date
  718. }
  719. if len(T_end_date) > 0 {
  720. contract.T_end_date = T_end_date
  721. }
  722. if len(T_submit) > 0 {
  723. contract.T_submit = T_submit
  724. }
  725. if len(T_stamping_date) > 0 {
  726. contract.T_stamping_date = T_stamping_date
  727. }
  728. if len(T_payment_method) > 0 {
  729. contract.T_payment_method = T_payment_method
  730. }
  731. err = ContractDao.Update_Contract(contract, "T_number", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State", "T_project",
  732. "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_start_date", "T_end_date", "T_submit", "T_stamping_date", "T_payment_method")
  733. if err != nil {
  734. o.Rollback()
  735. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  736. c.ServeJSON()
  737. return
  738. }
  739. if len(T_product) == 0 {
  740. o.Rollback()
  741. c.Data["json"] = lib.JSONS{Code: 202, Msg: "产品明细不能为空"}
  742. c.ServeJSON()
  743. return
  744. }
  745. productList := lib.SplitString(T_product, "|")
  746. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(oldT_number)
  747. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  748. // 检查编辑时需要修改的产品
  749. for k, v := range needToDeleteList {
  750. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  751. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  752. if v > 0 {
  753. o.Rollback()
  754. product, _ := Basic.Read_Product_ById(productId)
  755. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  756. c.ServeJSON()
  757. return
  758. }
  759. cp := Contract.ContractProduct{Id: id}
  760. err = ContractProductDao.Delete_ContractProduct(cp)
  761. if err != nil {
  762. o.Rollback()
  763. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  764. c.ServeJSON()
  765. return
  766. }
  767. }
  768. for _, v := range productList {
  769. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  770. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  771. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  772. oldContractProduct, ok := allList[product_id]
  773. if !ok {
  774. contractProduct := Contract.ContractProduct{
  775. T_contract_number: T_number,
  776. T_product_id: product_id,
  777. T_product_total: num,
  778. T_product_out: 0, // 已出库数量
  779. T_price: float32(price), // 已出库数量
  780. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  781. }
  782. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  783. if err != nil {
  784. o.Rollback()
  785. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  786. c.ServeJSON()
  787. return
  788. } else {
  789. continue
  790. }
  791. }
  792. // 修改产品总数量
  793. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  794. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  795. oldPrice := lib.StringToFloat64TwoDecimal(strings.Split(oldContractProduct, "-")[2])
  796. if oldNum == num && T_number == oldT_number && oldPrice == price {
  797. continue
  798. }
  799. cp := Contract.ContractProduct{
  800. Id: contractProductId,
  801. T_contract_number: T_number,
  802. T_product_total: num,
  803. T_price: float32(price), // 价格
  804. }
  805. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total", "T_contract_number", "T_price")
  806. if err != nil {
  807. o.Rollback()
  808. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  809. c.ServeJSON()
  810. return
  811. }
  812. }
  813. o.Commit()
  814. err = Update_VerifyContract_State(contract.T_customer_id, "UPDATE")
  815. if err != nil {
  816. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  817. c.ServeJSON()
  818. return
  819. }
  820. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "修改", contract)
  821. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  822. c.ServeJSON()
  823. return
  824. }
  825. func (c *ContractController) VerifyContract_Del() {
  826. T_number := c.GetString("T_number")
  827. o := orm.NewOrm()
  828. o.Begin()
  829. ContractDao := Contract.NewContract(o)
  830. ContractProductDao := Contract.NewContractProduct(o)
  831. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  832. if err != nil {
  833. o.Rollback()
  834. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  835. c.ServeJSON()
  836. return
  837. }
  838. err = ContractDao.Delete_Contract(contract)
  839. if err != nil {
  840. o.Rollback()
  841. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  842. c.ServeJSON()
  843. return
  844. }
  845. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  846. for _, v := range cpList {
  847. err = ContractProductDao.Delete_ContractProduct(v)
  848. if err != nil {
  849. o.Rollback()
  850. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  851. c.ServeJSON()
  852. return
  853. }
  854. }
  855. o.Commit()
  856. err = Update_VerifyContract_State(contract.T_customer_id, "DELETE")
  857. if err != nil {
  858. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改状态失败"}
  859. c.ServeJSON()
  860. return
  861. }
  862. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "删除", T_number)
  863. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  864. c.ServeJSON()
  865. return
  866. }
  867. // 导出验证合同
  868. func (c *ContractController) VerifyContract_Excel() {
  869. // 分页参数 初始化
  870. page, _ := c.GetInt("page")
  871. if page < 1 {
  872. page = 1
  873. }
  874. page_z, _ := c.GetInt("page_z")
  875. if page_z < 1 {
  876. page_z = conf.Page_size
  877. }
  878. // 查询
  879. T_name := c.GetString("T_name") // 客户名称
  880. T_state, _ := c.GetInt("T_state") // 签约状态
  881. T_start_date := c.GetString("T_start_date") // 盖章开始时间
  882. T_end_date := c.GetString("T_end_date") // 盖章结束时间
  883. data := ""
  884. if len(T_start_date) > 0 || len(T_end_date) > 0 {
  885. data = fmt.Sprintf("%s - %s", T_start_date, T_end_date)
  886. }
  887. userList, _ := NatsServer.Read_User_List_All()
  888. Account.Read_User_All_Map(userList)
  889. Contract.Read_VerifyContract_All_Map()
  890. ContractDao := Contract.NewContract(orm.NewOrm())
  891. R_List := ContractDao.Read_VerifyContract_Excel(T_state, T_name, T_start_date, T_end_date)
  892. f := excelize.NewFile() //设置单元格值
  893. // 这里设置表头ÒÒ
  894. Style1, _ := f.NewStyle(
  895. &excelize.Style{
  896. Font: &excelize.Font{Size: 20, Family: "宋体"},
  897. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  898. })
  899. Style2, _ := f.NewStyle(
  900. &excelize.Style{
  901. Font: &excelize.Font{Size: 15, Family: "宋体"},
  902. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  903. Border: []excelize.Border{
  904. {Type: "left", Color: "000000", Style: 1},
  905. {Type: "top", Color: "000000", Style: 1},
  906. {Type: "bottom", Color: "000000", Style: 1},
  907. {Type: "right", Color: "000000", Style: 1},
  908. },
  909. Fill: excelize.Fill{Type: "pattern", Color: []string{"D9D9D9"}, Pattern: 1},
  910. })
  911. Style3, _ := f.NewStyle(
  912. &excelize.Style{
  913. Font: &excelize.Font{Size: 15, Family: "宋体"},
  914. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  915. Border: []excelize.Border{
  916. {Type: "left", Color: "000000", Style: 1},
  917. {Type: "top", Color: "000000", Style: 1},
  918. {Type: "bottom", Color: "000000", Style: 1},
  919. {Type: "right", Color: "000000", Style: 1},
  920. },
  921. })
  922. f.MergeCell("Sheet1", "A1", "T1")
  923. f.SetCellValue("Sheet1", "A1", data+"合同明细")
  924. f.SetCellStyle("Sheet1", "A1", "T1", Style1)
  925. // 写入表头
  926. headers := []string{"合同编号", "客户名称", "销售人员", "签订时间", "起始时间", "终止时间", "盖章时间", "合同名称", "验证明细",
  927. "合同金额", "优惠金额", "付款方式/预付款", "回款时间", "以往回款", "回款金额", "未回款金额", "开票时间", "已开票金额", "未开票金额",
  928. "状态"}
  929. for col, header := range headers {
  930. cell := fmt.Sprintf("%c%d", rune('A'+col), 2)
  931. f.SetCellValue("Sheet1", cell, header)
  932. }
  933. // 这里设置表头
  934. f.SetCellStyle("Sheet1", "A2", "T2", Style2)
  935. f.SetRowHeight("Sheet1", 1, 50)
  936. f.SetRowHeight("Sheet1", 2, 50)
  937. colsWidth := []float64{15, 15, 12, 12, 12, 12, 12, 15, 50, 12, 12, 12, 12, 25, 12, 10, 25, 10, 10, 10}
  938. // 冻结1-2行
  939. f.SetPanes("Sheet1", &excelize.Panes{
  940. Freeze: true,
  941. Split: false,
  942. XSplit: 0,
  943. YSplit: 2,
  944. TopLeftCell: "A1",
  945. ActivePane: "topRight",
  946. })
  947. for col, width := range colsWidth {
  948. cell := fmt.Sprintf("%c", rune('A'+col))
  949. f.SetColWidth("Sheet1", cell, cell, width)
  950. }
  951. line := 2
  952. for _, v := range R_List {
  953. valueList := []interface{}{
  954. v.T_number, v.T_customer, v.T_submit_name, v.T_date, v.T_start_date, v.T_end_date, v.T_stamping_date, "冷链验证合同",
  955. v.T_Product, v.T_money, v.T_discount, Contract.Get_Contract_payment_method(v.T_payment_method), v.T_recoveries_time, v.T_recoveries, v.T_discount - v.T_no_recoveries_money,
  956. v.T_no_recoveries_money, v.T_invoice, v.T_discount - v.T_no_invoice_money, v.T_no_invoice_money, v.T_verify_state,
  957. }
  958. line++
  959. for col, value := range valueList {
  960. cell := fmt.Sprintf("%c", rune('A'+col))
  961. if cell == "N" || cell == "Q" {
  962. ll := value.([]Contract.ContractFinance_R)
  963. var sv []string
  964. for _, info := range ll {
  965. sv = append(sv, fmt.Sprintf("%s %s", info.T_date, FormatFloat(float64(info.T_money))))
  966. }
  967. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), strings.Join(sv, "\n"))
  968. continue
  969. }
  970. if cell == "I" {
  971. ll := value.([]Contract.ContractProduct_R)
  972. var sv []string
  973. for _, info := range ll {
  974. sv = append(sv, fmt.Sprintf("%s %s*%d=%s", info.T_product_name, FormatFloat(float64(info.T_price)), info.T_product_total, FormatFloat(float64(info.T_price)*float64(info.T_product_total))))
  975. }
  976. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), strings.Join(sv, "\n"))
  977. continue
  978. }
  979. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), value)
  980. }
  981. }
  982. f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("T%d", line), Style3)
  983. timeStr := time.Now().Format("20060102150405")
  984. fileName := fmt.Sprintf("%s合同明细%v.xlsx", data, timeStr)
  985. filePath := "ofile/" + fileName
  986. // 保存文件
  987. if err := f.SaveAs(filePath); err != nil {
  988. logs.Error("保存文件失败:", err)
  989. }
  990. defer func() {
  991. os.Remove(filePath)
  992. }()
  993. c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
  994. c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
  995. c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
  996. c.Ctx.Output.Download(filePath, fileName)
  997. }
  998. func Update_VerifyContract_State(T_customer_id, flag string) error {
  999. o := orm.NewOrm()
  1000. ContractDao := Contract.NewContract(o)
  1001. VerifyContractDao := Contract.NewVerifyContract(o)
  1002. vcn := ContractDao.Read_VerifyContract_Newest(T_customer_id)
  1003. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  1004. if err != nil {
  1005. return err
  1006. }
  1007. contractList, _ := ContractDao.Read_VerifyContract_List("", T_customer_id, "", 1, 9999)
  1008. var (
  1009. earliestStart time.Time
  1010. latestEnd time.Time
  1011. earliestStartStr string
  1012. latestEndStr string
  1013. hasStart bool
  1014. hasEnd bool
  1015. )
  1016. for _, info := range contractList {
  1017. if len(info.T_start_date) > 0 {
  1018. if startTime, ok := lib.DateStrToTime(info.T_start_date); ok {
  1019. if !hasStart || startTime.Before(earliestStart) {
  1020. hasStart = true
  1021. earliestStart = startTime
  1022. earliestStartStr = info.T_start_date
  1023. }
  1024. }
  1025. }
  1026. if len(info.T_end_date) > 0 {
  1027. if endTime, ok := lib.DateStrToTime(info.T_end_date); ok {
  1028. if !hasEnd || endTime.After(latestEnd) {
  1029. hasEnd = true
  1030. latestEnd = endTime
  1031. latestEndStr = info.T_end_date
  1032. }
  1033. }
  1034. }
  1035. }
  1036. if len(earliestStartStr) > 0 {
  1037. vc.T_start_date = earliestStartStr
  1038. }
  1039. if len(latestEndStr) > 0 {
  1040. vc.T_end_date = latestEndStr
  1041. }
  1042. if vcn.Id == 0 {
  1043. vc.T_sign_times = 0
  1044. vc.T_start_date = ""
  1045. vc.T_end_date = ""
  1046. vc.T_State = 1
  1047. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  1048. return err
  1049. }
  1050. if flag == "ADD" {
  1051. vc.T_sign_times += 1
  1052. } else if flag == "DELETE" {
  1053. vc.T_sign_times -= 1
  1054. }
  1055. nowTime := time.Now()
  1056. now := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
  1057. targetEndDate := vc.T_end_date
  1058. if len(targetEndDate) == 0 {
  1059. targetEndDate = vcn.T_end_date
  1060. }
  1061. end, _ := lib.DateStrToTime(targetEndDate)
  1062. now2Month := now.AddDate(0, 2, 0)
  1063. // 1-未签约 2-已作废 3-已签约 4-即将到期
  1064. state := 1
  1065. // 结束时间<今天 已过期
  1066. if end.Before(now) {
  1067. state = 2
  1068. } else {
  1069. // 结束时间<今天+2月 即将到期 && 结束时间>今天
  1070. if end.Before(now2Month) || end.Equal(now) {
  1071. state = 4
  1072. NatsServer.AddNews(vcn.T_approver, fmt.Sprintf("【合同即将过期提醒】%s的验证合同将于%s过期!", vc.T_customer, vc.T_end_date), conf.VerifyContractUrl)
  1073. }
  1074. // 结束时间>今天+2月 已签约
  1075. if end.After(now2Month) || end.Equal(now2Month) {
  1076. state = 3
  1077. }
  1078. }
  1079. vc.T_State = state
  1080. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  1081. return err
  1082. }
  1083. // 验证合同-添加客户
  1084. func (c *ContractController) VerifyContract_Add_Customer() {
  1085. T_customer := c.GetString("T_customer")
  1086. o := orm.NewOrm()
  1087. VerifyContractDao := Contract.NewVerifyContract(o)
  1088. T_number := ""
  1089. for true {
  1090. rand_x := 1
  1091. T_number = fmt.Sprintf("YZKH-%s", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", int64(rand_x)))
  1092. _, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_number)
  1093. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  1094. break
  1095. }
  1096. rand_x += 1
  1097. }
  1098. var_ := Contract.VerifyContract{
  1099. T_customer: T_customer,
  1100. T_customer_id: T_number,
  1101. T_State: 1,
  1102. }
  1103. _, err := VerifyContractDao.Add_VerifyContract(var_)
  1104. if err != nil {
  1105. o.Rollback()
  1106. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1107. c.ServeJSON()
  1108. return
  1109. }
  1110. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加客户", var_)
  1111. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  1112. c.ServeJSON()
  1113. return
  1114. }
  1115. // 验证合同-编辑客户
  1116. func (c *ContractController) VerifyContract_Update_Customer() {
  1117. T_customer_id := c.GetString("T_customer_id")
  1118. T_customer := c.GetString("T_customer")
  1119. o := orm.NewOrm()
  1120. VerifyContractDao := Contract.NewVerifyContract(o)
  1121. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  1122. vc.T_customer = T_customer
  1123. err = VerifyContractDao.Update_VerifyContract(vc)
  1124. if err != nil {
  1125. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1126. c.ServeJSON()
  1127. return
  1128. }
  1129. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "编辑客户", vc)
  1130. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_customer_id}
  1131. c.ServeJSON()
  1132. return
  1133. }
  1134. // 验证合同-客户列表
  1135. func (c *ContractController) VerifyContract_Customer_List() {
  1136. // 分页参数 初始化
  1137. page, _ := c.GetInt("page")
  1138. if page < 1 {
  1139. page = 1
  1140. }
  1141. page_z, _ := c.GetInt("page_z")
  1142. if page_z < 1 {
  1143. page_z = conf.Page_size
  1144. }
  1145. // 查询
  1146. T_name := c.GetString("T_name")
  1147. T_state, _ := c.GetInt("T_state")
  1148. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  1149. R_List, R_cnt := VerifyContractDao.Read_VerifyContract_List(T_name, T_state, page, page_z)
  1150. var r_jsons lib.R_JSONS
  1151. r_jsons.Num = R_cnt
  1152. r_jsons.Data = R_List
  1153. r_jsons.Page = page
  1154. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1155. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1156. c.ServeJSON()
  1157. return
  1158. }
  1159. // 合同回款明细列表
  1160. func (c *ContractController) Contract_List_RecoveriesMoney() {
  1161. // 分页参数 初始化
  1162. page, _ := c.GetInt("page")
  1163. if page < 1 {
  1164. page = 1
  1165. }
  1166. page_z, _ := c.GetInt("page_z")
  1167. if page_z < 1 {
  1168. page_z = conf.Page_size
  1169. }
  1170. // 查询
  1171. T_submit := c.GetString("T_submit")
  1172. T_name := c.GetString("T_name")
  1173. T_start_date := c.GetString("T_start_date") // 回款开始日期
  1174. T_end_date := c.GetString("T_end_date") // 回款结束日期
  1175. T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
  1176. T_invoice_state, _ := c.GetInt("T_invoice_state") // 开票状态 1 未开票 2 部分开票 3 全部开票
  1177. T_percentage_state, _ := c.GetInt("T_percentage_state") // 提成状态 1-未打款 2-已打款
  1178. T_mine, _ := c.GetInt("T_mine") // 我的 用于合同提成显示
  1179. userList, _ := NatsServer.Read_User_List_All()
  1180. Account.Read_User_All_Map(userList)
  1181. Contract.Read_VerifyContract_All_Map()
  1182. ContractDao := Contract.NewContract(orm.NewOrm())
  1183. R_List, R_cnt := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(c.User.T_uuid, T_submit, T_mine, T_name, T_start_date, T_end_date, T_recoveries_state, T_invoice_state, T_percentage_state, page, page_z)
  1184. var r_jsons lib.R_JSONS
  1185. r_jsons.Num = R_cnt
  1186. r_jsons.Data = R_List
  1187. r_jsons.Page = page
  1188. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1189. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1190. c.ServeJSON()
  1191. return
  1192. }
  1193. // 导出合同回款明细列表
  1194. func (c *ContractController) Contract_List_RecoveriesMoney_Export() {
  1195. // 查询
  1196. T_submit := c.GetString("T_submit")
  1197. T_name := c.GetString("T_name")
  1198. T_start_date := c.GetString("T_start_date") // 回款开始日期
  1199. T_end_date := c.GetString("T_end_date") // 回款结束日期
  1200. T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
  1201. T_invoice_state, _ := c.GetInt("T_invoice_state") // 开票状态 1 未开票 2 部分开票 3 全部开票
  1202. T_percentage_state, _ := c.GetInt("T_percentage_state") // 提成状态 1-未打款 2-已打款
  1203. T_mine, _ := c.GetInt("T_mine") // 我的 用于合同提成显示
  1204. userList, _ := NatsServer.Read_User_List_All()
  1205. Account.Read_User_All_Map(userList)
  1206. Contract.Read_VerifyContract_All_Map()
  1207. ContractDao := Contract.NewContract(orm.NewOrm())
  1208. R_List, _ := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(c.User.T_uuid, T_submit, T_mine, T_name, T_start_date, T_end_date, T_recoveries_state, T_invoice_state, T_percentage_state, 0, 9999)
  1209. title := "销售提成明细表"
  1210. if T_mine == 1 {
  1211. title = fmt.Sprintf("%s-销售提成明细表", c.User.T_name)
  1212. }
  1213. filename := fmt.Sprintf("%s(%s)", title, lib.GetRandstring(6, "0123456789", 0))
  1214. f := excelize.NewFile() // 设置单元格的值
  1215. Style1, _ := f.NewStyle(
  1216. &excelize.Style{
  1217. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  1218. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  1219. })
  1220. Style2, _ := f.NewStyle(
  1221. &excelize.Style{
  1222. Font: &excelize.Font{Bold: true, Size: 11, Family: "宋体"},
  1223. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  1224. Border: []excelize.Border{
  1225. {Type: "left", Color: "000000", Style: 1},
  1226. {Type: "top", Color: "000000", Style: 1},
  1227. {Type: "bottom", Color: "000000", Style: 1},
  1228. {Type: "right", Color: "000000", Style: 1},
  1229. },
  1230. })
  1231. Style3, _ := f.NewStyle(
  1232. &excelize.Style{
  1233. Font: &excelize.Font{Size: 11, Family: "宋体"},
  1234. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  1235. Border: []excelize.Border{
  1236. {Type: "left", Color: "000000", Style: 1},
  1237. {Type: "top", Color: "000000", Style: 1},
  1238. {Type: "bottom", Color: "000000", Style: 1},
  1239. {Type: "right", Color: "000000", Style: 1},
  1240. },
  1241. })
  1242. f.MergeCell("Sheet1", "A1", "J1")
  1243. f.SetRowStyle("Sheet1", 1, 1, Style1)
  1244. f.SetCellValue("Sheet1", "A1", title)
  1245. f.SetRowHeight("Sheet1", 1, 30)
  1246. // 这里设置表头
  1247. f.SetCellStyle("Sheet1", "A2", "J2", Style2)
  1248. f.SetRowHeight("Sheet1", 2, 20)
  1249. f.SetCellValue("Sheet1", "A2", "公司名称")
  1250. f.SetCellValue("Sheet1", "B2", "合同编号")
  1251. f.SetCellValue("Sheet1", "C2", "签约时间")
  1252. f.SetCellValue("Sheet1", "D2", "合同金额")
  1253. f.SetCellValue("Sheet1", "E2", "回款金额")
  1254. f.SetCellValue("Sheet1", "F2", "回款比例")
  1255. f.SetCellValue("Sheet1", "G2", "销售类型")
  1256. f.SetCellValue("Sheet1", "H2", "销售提成5%")
  1257. f.SetCellValue("Sheet1", "I2", "提成金额")
  1258. f.SetCellValue("Sheet1", "J2", "提成状态")
  1259. // 设置列宽
  1260. f.SetColWidth("Sheet1", "A", "A", 25)
  1261. f.SetColWidth("Sheet1", "B", "I", 15)
  1262. line := 2
  1263. for _, contract := range R_List {
  1264. line += 1
  1265. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), line-2)
  1266. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), contract.T_customer)
  1267. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), contract.T_number)
  1268. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), contract.T_date)
  1269. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), contract.T_discount)
  1270. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), contract.T_recoveries_money)
  1271. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("%.02f%%", contract.T_recoveries_money/contract.T_discount*100))
  1272. T_type_str := "验证合同"
  1273. if contract.T_type == 1 {
  1274. T_type_str = "销售合同"
  1275. }
  1276. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), T_type_str)
  1277. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("%.02f", contract.T_discount*0.05))
  1278. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("%.02f", contract.T_discount*0.05))
  1279. T_percentage_str := "未打款"
  1280. if contract.T_percentage_state == 2 {
  1281. T_percentage_str = "已打款"
  1282. }
  1283. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), T_percentage_str)
  1284. }
  1285. f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("J%d", line), Style3)
  1286. // 保存文件
  1287. if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  1288. fmt.Println(err)
  1289. }
  1290. var url string
  1291. //// 上传 OSS
  1292. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  1293. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  1294. if !is {
  1295. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  1296. c.ServeJSON()
  1297. return
  1298. }
  1299. //删除目录
  1300. err := os.Remove("ofile/" + filename + ".xlsx")
  1301. if err != nil {
  1302. logs.Error(lib.FuncName(), err)
  1303. }
  1304. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1305. c.ServeJSON()
  1306. return
  1307. }
  1308. func (c *ContractController) Contract_Stat() {
  1309. T_type, _ := c.GetInt("T_type")
  1310. T_year, _ := c.GetInt("T_year")
  1311. type R_JSONS struct {
  1312. ContractMoneyByYear interface{}
  1313. TotalMoneyByYear float32
  1314. RecoveriesMoneyByYear float32
  1315. ContractNumByYear interface{}
  1316. TotalMumByYear int64
  1317. ContractMoneyByMonth interface{}
  1318. TotalMoneyByMonth float32
  1319. RecoveriesMoneyByMonth float32
  1320. ContractNumByMonth interface{}
  1321. TotalMumByMonth int64
  1322. TotalMoneyByThisYear float32 // 今年合同总金额
  1323. RecoveriesMoneyByThisYear float32 // 今年回款总金额
  1324. TotalMumByThisYear int64 // 今年合同总数
  1325. TotalMoneyByLastYear float32 // 去年合同总金额
  1326. RecoveriesMoneyByLastYear float32 // 去年回款总金额
  1327. TotalMumByLastYear int64 // 去年合同总数
  1328. }
  1329. var r_jsons R_JSONS
  1330. thisYear := time.Now().Year()
  1331. if T_year == 0 {
  1332. T_year = thisYear
  1333. }
  1334. ContractDao := Contract.NewContract(orm.NewOrm())
  1335. monryStat, moneyTotal, moneyRecoveries := ContractDao.Stat_ContractMoney_ByYear(T_type)
  1336. numStat, numTotal := ContractDao.Stat_ContractNum_ByYear(T_type)
  1337. monryMonthStat, moneyMonthTotal, moneyMonthRecoveries := ContractDao.Stat_ContractMoney_ByMonth(T_type, T_year)
  1338. numMonthStat, numMonthTotal := ContractDao.Stat_ContractNum_ByMonth(T_type, T_year)
  1339. // 去年
  1340. _, r_jsons.TotalMoneyByLastYear, r_jsons.RecoveriesMoneyByLastYear = ContractDao.Stat_ContractMoney_ByMonth(T_type, T_year-1)
  1341. _, r_jsons.TotalMumByLastYear = ContractDao.Stat_ContractNum_ByMonth(T_type, T_year-1)
  1342. r_jsons.ContractMoneyByYear = monryStat
  1343. r_jsons.TotalMoneyByYear = moneyTotal
  1344. r_jsons.RecoveriesMoneyByYear = moneyRecoveries
  1345. r_jsons.ContractNumByYear = numStat
  1346. r_jsons.TotalMumByYear = numTotal
  1347. r_jsons.ContractMoneyByMonth = monryMonthStat
  1348. r_jsons.TotalMoneyByMonth = moneyMonthTotal
  1349. r_jsons.RecoveriesMoneyByMonth = moneyMonthRecoveries
  1350. r_jsons.ContractNumByMonth = numMonthStat
  1351. r_jsons.TotalMumByMonth = numMonthTotal
  1352. r_jsons.TotalMoneyByThisYear = moneyMonthTotal
  1353. r_jsons.RecoveriesMoneyByThisYear = moneyMonthRecoveries
  1354. r_jsons.TotalMumByThisYear = numMonthTotal
  1355. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1356. c.ServeJSON()
  1357. return
  1358. }
  1359. func Cron_VerifyContract() {
  1360. //创建一个定时任务对象
  1361. c := cron.New(cron.WithSeconds())
  1362. //给对象增加定时任务
  1363. //c.AddFunc("0 */1 * * * ?", Cron_VerifyContract_ChangeState)
  1364. c.AddFunc("@daily", Cron_VerifyContract_ChangeState)
  1365. //启动定时任务
  1366. c.Start()
  1367. defer c.Stop()
  1368. //查询语句,阻塞,让main函数不退出,保持程序运行
  1369. select {}
  1370. }
  1371. // 修改合同状态
  1372. func Cron_VerifyContract_ChangeState() {
  1373. T_date := time.Now().Format("2006-01-02")
  1374. logs.Info("开始处理" + T_date + "验证合同状态")
  1375. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  1376. R_List, _ := VerifyContractDao.Read_VerifyContract_List("", 0, 0, 999)
  1377. for _, v := range R_List {
  1378. err := Update_VerifyContract_State(v.T_customer_id, "UPDATE")
  1379. if err != nil {
  1380. logs.Error("修改合同状态失败")
  1381. }
  1382. }
  1383. }
  1384. // 修改回款金额及开票金额
  1385. func UpdateVerifyContract_RecoveriesInvoice_Money() {
  1386. ContractDao := Contract.NewContract(orm.NewOrm())
  1387. R_List, _ := ContractDao.Read_VerifyContract_List("", "", "", 0, 9999)
  1388. for _, verify := range R_List {
  1389. R := Contract.Contract{Id: verify.Id}
  1390. _, R.T_recoveries_money = Contract.ContractToContractFinance_R(verify.T_recoveries)
  1391. _, R.T_invoice_money = Contract.ContractToContractFinance_R(verify.T_invoice)
  1392. ContractDao.Update_Contract(R, "T_recoveries_money", "T_invoice_money")
  1393. }
  1394. }
  1395. // 修改回款时间
  1396. func UpdateVerifyContract_RecoveriesInvoice_Time() {
  1397. ContractDao := Contract.NewContract(orm.NewOrm())
  1398. R_List, _ := ContractDao.Read_VerifyContract_List("", "", "", 0, 9999)
  1399. for _, verify := range R_List {
  1400. R := Contract.Contract{Id: verify.Id}
  1401. if verify.T_discount == verify.T_recoveries_money {
  1402. recoveriesList, _ := Contract.ContractToContractFinance_R(verify.T_recoveries)
  1403. if len(recoveriesList) > 0 {
  1404. R.T_recoveries_time = recoveriesList[len(recoveriesList)-1].T_date
  1405. ContractDao.Update_Contract(R, "T_recoveries_time")
  1406. }
  1407. }
  1408. }
  1409. }
  1410. // 合同提成打款
  1411. func (c *ContractController) Contract_Percentage_Remit() {
  1412. T_number := c.GetString("T_number")
  1413. o := orm.NewOrm()
  1414. ContractDao := Contract.NewContract(o)
  1415. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  1416. if err != nil {
  1417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  1418. c.ServeJSON()
  1419. return
  1420. }
  1421. if contract.T_recoveries_money != contract.T_discount {
  1422. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同未回款,不可打款!"}
  1423. c.ServeJSON()
  1424. return
  1425. }
  1426. contract.T_percentage_state = 2 // 已打款
  1427. err = ContractDao.Update_Contract(contract, "T_percentage_state")
  1428. if err != nil {
  1429. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  1430. c.ServeJSON()
  1431. return
  1432. }
  1433. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "打款", contract)
  1434. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  1435. c.ServeJSON()
  1436. return
  1437. }
  1438. func (c *ContractController) User_List() {
  1439. var r_jsons lib.R_JSONS
  1440. // 分页参数 初始化
  1441. page, _ := c.GetInt("page")
  1442. if page < 1 {
  1443. page = 1
  1444. }
  1445. page_z, _ := c.GetInt("page_z")
  1446. if page_z < 1 {
  1447. page_z = conf.Page_size
  1448. }
  1449. T_name := c.GetString("T_name")
  1450. ContractDao := Contract.NewContract(orm.NewOrm())
  1451. uuidList := ContractDao.Read_T_submit_List()
  1452. if len(uuidList) == 0 {
  1453. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1454. c.ServeJSON()
  1455. return
  1456. }
  1457. R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
  1458. if err != nil {
  1459. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
  1460. c.ServeJSON()
  1461. return
  1462. }
  1463. var U_List []userlibs.User
  1464. for _, user := range R_List {
  1465. U_List = append(U_List, user)
  1466. }
  1467. r_jsons.Num = R_cnt
  1468. r_jsons.Data = U_List
  1469. r_jsons.Page = page
  1470. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1471. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1472. c.ServeJSON()
  1473. return
  1474. }
  1475. func FormatFloat(f float64) string {
  1476. // 先判断是否为整数
  1477. if f == math.Trunc(f) {
  1478. return strconv.FormatFloat(f, 'f', 0, 64)
  1479. }
  1480. // 否则保留2位小数
  1481. return strconv.FormatFloat(f, 'f', 2, 64)
  1482. }