Contract.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. package controllers
  2. import (
  3. "ERP_storage/Nats/NatsServer"
  4. "ERP_storage/conf"
  5. "ERP_storage/logs"
  6. "ERP_storage/models/Account"
  7. "ERP_storage/models/Basic"
  8. "ERP_storage/models/Contract"
  9. "ERP_storage/models/Stock"
  10. "fmt"
  11. userlibs "git.baozhida.cn/ERP_libs/User"
  12. "git.baozhida.cn/ERP_libs/lib"
  13. "github.com/beego/beego/v2/adapter/orm"
  14. beego "github.com/beego/beego/v2/server/web"
  15. "github.com/robfig/cron/v3"
  16. "math"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. type ContractController struct {
  22. beego.Controller
  23. User userlibs.User
  24. }
  25. func (c *ContractController) Prepare() {
  26. c.User = *Account.User_r
  27. }
  28. func (c *ContractController) Contract_GenT_number() {
  29. o := orm.NewOrm()
  30. ContractDao := Contract.NewContract(o)
  31. T_number := ""
  32. rand_x := 1
  33. for true {
  34. T_number = fmt.Sprintf("GZBZD-%s%03d", time.Now().Format("20060102"), rand_x)
  35. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  36. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  37. break
  38. }
  39. rand_x += 1
  40. }
  41. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  42. c.ServeJSON()
  43. return
  44. }
  45. func (c *ContractController) Contract_List() {
  46. // 分页参数 初始化
  47. page, _ := c.GetInt("page")
  48. if page < 1 {
  49. page = 1
  50. }
  51. page_z, _ := c.GetInt("page_z")
  52. if page_z < 1 {
  53. page_z = conf.Page_size
  54. }
  55. // 查询
  56. T_name := c.GetString("T_name")
  57. T_state, _ := c.GetInt("T_state")
  58. userList, _ := NatsServer.Read_User_List_All()
  59. Account.Read_User_All_Map(userList)
  60. ContractDao := Contract.NewContract(orm.NewOrm())
  61. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, T_state, 0, page, page_z)
  62. var r_jsons lib.R_JSONS
  63. r_jsons.Num = R_cnt
  64. r_jsons.Data = R_List
  65. r_jsons.Page = page
  66. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  67. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  68. c.ServeJSON()
  69. return
  70. }
  71. func (c *ContractController) Contract_User_List() {
  72. // 分页参数 初始化
  73. page, _ := c.GetInt("page")
  74. if page < 1 {
  75. page = 1
  76. }
  77. page_z, _ := c.GetInt("page_z")
  78. if page_z < 1 {
  79. page_z = conf.Page_size
  80. }
  81. // 查询
  82. T_name := c.GetString("T_name")
  83. T_state, _ := c.GetInt("T_state")
  84. userList, _ := NatsServer.Read_User_List_All()
  85. Account.Read_User_All_Map(userList)
  86. ContractDao := Contract.NewContract(orm.NewOrm())
  87. R_List, R_cnt := ContractDao.Read_Contract_List(c.User.T_uuid, T_name, T_state, 0, page, page_z)
  88. var r_jsons lib.R_JSONS
  89. r_jsons.Num = R_cnt
  90. r_jsons.Data = R_List
  91. r_jsons.Page = page
  92. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  93. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  94. c.ServeJSON()
  95. return
  96. }
  97. func (c *ContractController) Contract_Get() {
  98. // 查询
  99. T_number := c.GetString("T_number")
  100. o := orm.NewOrm()
  101. ContractDao := Contract.NewContract(o)
  102. DeviceDao := Stock.NewDevice(o)
  103. ContractProductDao := Contract.NewContractProduct(o)
  104. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  105. if err != nil {
  106. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  107. c.ServeJSON()
  108. return
  109. }
  110. productList := ContractProductDao.Read_ContractProduct_List(contract.T_number)
  111. var pList []Contract.ContractProduct_R
  112. for _, v := range productList {
  113. p := Contract.ContractProductToContractProduct_R(v)
  114. p.T_device_list, _ = DeviceDao.Read_DeviceSn_List(T_number, v.T_product_id, "", "")
  115. pList = append(pList, p)
  116. }
  117. userList, _ := NatsServer.Read_User_List_All()
  118. Account.Read_User_All_Map(userList)
  119. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Contract.ContractToContract_Detail(contract, pList)}
  120. c.ServeJSON()
  121. return
  122. }
  123. func (c *ContractController) Contract_Add() {
  124. T_number := c.GetString("T_number")
  125. T_customer := c.GetString("T_customer")
  126. T_money, _ := c.GetFloat("T_money") // 总价
  127. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  128. T_date := c.GetString("T_date")
  129. T_product := c.GetString("T_product")
  130. T_remark := c.GetString("T_remark")
  131. T_pdf := c.GetString("T_pdf")
  132. T_project := c.GetString("T_project")
  133. T_recoveries := c.GetString("T_recoveries")
  134. T_invoice := c.GetString("T_invoice")
  135. T_submit := c.GetString("T_submit")
  136. if len(T_submit) == 0 {
  137. T_submit = c.User.T_uuid
  138. }
  139. var_ := Contract.Contract{
  140. T_number: T_number,
  141. T_customer: T_customer,
  142. T_money: float32(T_money),
  143. T_discount: float32(T_discount),
  144. T_project: T_project,
  145. T_type: 1, //合同类型 1-销售合同 2-验证合同
  146. T_date: T_date,
  147. T_out: 1,
  148. T_State: 3,
  149. T_remark: T_remark,
  150. T_pdf: T_pdf,
  151. T_submit: T_submit,
  152. T_recoveries: T_recoveries,
  153. T_invoice: T_invoice,
  154. }
  155. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  156. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  157. o := orm.NewOrm()
  158. o.Begin()
  159. ContractDao := Contract.NewContract(o)
  160. ContractProductDao := Contract.NewContractProduct(o)
  161. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  162. if err == nil {
  163. o.Rollback()
  164. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  165. c.ServeJSON()
  166. return
  167. }
  168. _, err = ContractDao.Add_Contract(var_)
  169. if err != nil {
  170. o.Rollback()
  171. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  172. c.ServeJSON()
  173. return
  174. }
  175. if len(T_product) == 0 {
  176. o.Rollback()
  177. c.Data["json"] = lib.JSONS{Code: 202, Msg: "销售合同产品明细不能为空"}
  178. c.ServeJSON()
  179. return
  180. }
  181. productList := lib.SplitString(T_product, "|")
  182. for _, v := range productList {
  183. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  184. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  185. contractProduct := Contract.ContractProduct{
  186. T_contract_number: T_number,
  187. T_product_id: product_id,
  188. T_product_total: num,
  189. T_product_out: 0, // 已出库数量
  190. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  191. }
  192. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  193. if err != nil {
  194. o.Rollback()
  195. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  196. c.ServeJSON()
  197. return
  198. }
  199. }
  200. o.Commit()
  201. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "添加", var_)
  202. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  203. c.ServeJSON()
  204. return
  205. }
  206. func (c *ContractController) Contract_Approval() {
  207. T_number := c.GetString("T_number")
  208. T_state, _ := c.GetInt("T_state")
  209. o := orm.NewOrm()
  210. ContractDao := Contract.NewContract(o)
  211. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  212. if err != nil {
  213. o.Rollback()
  214. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  215. c.ServeJSON()
  216. return
  217. }
  218. // 1-已通过 2-未通过
  219. contract.T_State = T_state
  220. contract.T_approver = c.User.T_uuid
  221. err = ContractDao.Update_Contract(contract, "T_State", "T_approver")
  222. if err != nil {
  223. o.Rollback()
  224. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  225. c.ServeJSON()
  226. return
  227. }
  228. if T_state == 1 {
  229. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核已通过", T_number), conf.ContractApprovalUrl)
  230. }
  231. if T_state == 2 {
  232. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核未通过", T_number), conf.ContractApprovalUrl)
  233. }
  234. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "审核", contract)
  235. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  236. c.ServeJSON()
  237. return
  238. }
  239. func (c *ContractController) Contract_Edit() {
  240. T_number := c.GetString("T_number")
  241. T_customer := c.GetString("T_customer")
  242. T_money, _ := c.GetFloat("T_money")
  243. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  244. T_date := c.GetString("T_date")
  245. T_product := c.GetString("T_product")
  246. T_remark := c.GetString("T_remark")
  247. T_pdf := c.GetString("T_pdf")
  248. T_project := c.GetString("T_project")
  249. T_recoveries := c.GetString("T_recoveries")
  250. T_invoice := c.GetString("T_invoice")
  251. T_submit := c.GetString("T_submit")
  252. o := orm.NewOrm()
  253. o.Begin()
  254. ContractDao := Contract.NewContract(o)
  255. ContractProductDao := Contract.NewContractProduct(o)
  256. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  257. if err != nil {
  258. o.Rollback()
  259. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  260. c.ServeJSON()
  261. return
  262. }
  263. if len(T_customer) > 0 {
  264. contract.T_customer = T_customer
  265. }
  266. if T_money > 0 {
  267. contract.T_money = float32(T_money)
  268. }
  269. if T_discount > 0 {
  270. contract.T_discount = float32(T_discount)
  271. }
  272. if len(T_date) > 0 {
  273. contract.T_date = T_date
  274. }
  275. if len(T_remark) > 0 {
  276. contract.T_remark = T_remark
  277. }
  278. if len(T_pdf) > 0 {
  279. contract.T_pdf = T_pdf
  280. }
  281. if len(T_project) > 0 {
  282. contract.T_project = T_project
  283. }
  284. if len(T_recoveries) > 0 {
  285. contract.T_recoveries = T_recoveries
  286. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  287. }
  288. if len(T_invoice) > 0 {
  289. contract.T_invoice = T_invoice
  290. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  291. }
  292. if len(T_submit) > 0 {
  293. contract.T_submit = T_submit
  294. }
  295. //1-已通过 2-未通过 3-待审核 合同状态为未通过,修改之后将状态更改为待审核
  296. if contract.T_State == 2 {
  297. contract.T_State = 3
  298. }
  299. err = ContractDao.Update_Contract(contract, "T_customer", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State",
  300. "T_project", "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_submit")
  301. if err != nil {
  302. o.Rollback()
  303. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  304. c.ServeJSON()
  305. return
  306. }
  307. //合同类型 1-销售合同 2-验证合同
  308. if contract.T_type == 2 {
  309. o.Commit()
  310. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "修改", contract)
  311. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  312. c.ServeJSON()
  313. return
  314. }
  315. if len(T_product) == 0 {
  316. o.Rollback()
  317. c.Data["json"] = lib.JSONS{Code: 202, Msg: "销售合同产品明细不能为空"}
  318. c.ServeJSON()
  319. return
  320. }
  321. productList := lib.SplitString(T_product, "|")
  322. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(T_number)
  323. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  324. // 检查编辑时需要修改的产品
  325. for k, v := range needToDeleteList {
  326. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  327. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  328. if v > 0 {
  329. o.Rollback()
  330. product, _ := Basic.Read_Product_ById(productId)
  331. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  332. c.ServeJSON()
  333. return
  334. }
  335. cp := Contract.ContractProduct{Id: id}
  336. err = ContractProductDao.Delete_ContractProduct(cp)
  337. if err != nil {
  338. o.Rollback()
  339. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  340. c.ServeJSON()
  341. return
  342. }
  343. }
  344. //for _, v := range productList {
  345. // product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  346. // num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  347. //
  348. // var cp Contract.ContractProduct
  349. // cp, err = ContractProductDao.Read_ContractProduct_ByT_number_T_product_id(T_number, product_id)
  350. // if err != nil {
  351. // if err.Error() == orm.ErrNoRows.Error() {
  352. // contractProduct := Contract.ContractProduct{
  353. // T_contract_number: T_number,
  354. // T_product_id: product_id,
  355. // T_product_total: num,
  356. // T_product_out: 0, // 已出库数量
  357. // T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  358. // }
  359. // _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  360. // if err != nil {
  361. // o.Rollback()
  362. // c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  363. // c.ServeJSON()
  364. // return
  365. // }
  366. //
  367. // } else {
  368. // o.Rollback()
  369. // c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  370. // c.ServeJSON()
  371. // return
  372. // }
  373. // }
  374. // // 修改产品总数量
  375. // if cp.T_product_total == num {
  376. // continue
  377. // }
  378. // cp.T_product_total = num
  379. // err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
  380. // if err != nil {
  381. // o.Rollback()
  382. // c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  383. // c.ServeJSON()
  384. // return
  385. // }
  386. //
  387. //}
  388. for _, v := range productList {
  389. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  390. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  391. oldContractProduct, ok := allList[product_id]
  392. if !ok {
  393. contractProduct := Contract.ContractProduct{
  394. T_contract_number: T_number,
  395. T_product_id: product_id,
  396. T_product_total: num,
  397. T_product_out: 0, // 已出库数量
  398. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  399. }
  400. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  401. if err != nil {
  402. o.Rollback()
  403. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  404. c.ServeJSON()
  405. return
  406. } else {
  407. continue
  408. }
  409. }
  410. // 修改产品总数量
  411. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  412. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  413. if oldNum == num {
  414. continue
  415. }
  416. cp := Contract.ContractProduct{Id: contractProductId, T_product_total: num}
  417. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
  418. if err != nil {
  419. o.Rollback()
  420. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  421. c.ServeJSON()
  422. return
  423. }
  424. }
  425. o.Commit()
  426. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "修改", contract)
  427. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  428. c.ServeJSON()
  429. return
  430. }
  431. func (c *ContractController) Contract_Del() {
  432. T_number := c.GetString("T_number")
  433. o := orm.NewOrm()
  434. o.Begin()
  435. ContractDao := Contract.NewContract(o)
  436. ContractProductDao := Contract.NewContractProduct(o)
  437. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  438. if err != nil {
  439. o.Rollback()
  440. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  441. c.ServeJSON()
  442. return
  443. }
  444. //1-已通过 2-未通过 3-待审核 审核状态
  445. if contract.T_State == 1 {
  446. o.Rollback()
  447. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同已审核通过,禁止删除!"}
  448. c.ServeJSON()
  449. return
  450. }
  451. err = ContractDao.Delete_Contract(contract)
  452. if err != nil {
  453. o.Rollback()
  454. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  455. c.ServeJSON()
  456. return
  457. }
  458. //合同类型 1-销售合同 2-验证合同
  459. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  460. for _, v := range cpList {
  461. err = ContractProductDao.Delete_ContractProduct(v)
  462. if err != nil {
  463. o.Rollback()
  464. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  465. c.ServeJSON()
  466. return
  467. }
  468. }
  469. o.Commit()
  470. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "删除", T_number)
  471. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  472. c.ServeJSON()
  473. return
  474. }
  475. func (c *ContractController) Contract_List_For_Out() {
  476. // 分页参数 初始化
  477. page, _ := c.GetInt("page")
  478. if page < 1 {
  479. page = 1
  480. }
  481. page_z, _ := c.GetInt("page_z")
  482. if page_z < 1 {
  483. page_z = conf.Page_size
  484. }
  485. // 查询
  486. T_name := c.GetString("T_name")
  487. userList, _ := NatsServer.Read_User_List_All()
  488. Account.Read_User_All_Map(userList)
  489. ContractDao := Contract.NewContract(orm.NewOrm())
  490. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 1, 1, page, page_z)
  491. var r_jsons lib.R_JSONS
  492. r_jsons.Num = R_cnt
  493. r_jsons.Data = R_List
  494. r_jsons.Page = page
  495. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  496. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  497. c.ServeJSON()
  498. return
  499. }
  500. // 合同下的产品列表 出库时使用
  501. func (c *ContractController) Contract_Product_List() {
  502. // 查询
  503. T_number := c.GetString("T_number")
  504. T_depot_id, _ := c.GetInt("T_depot_id")
  505. o := orm.NewOrm()
  506. ContractDao := Contract.NewContract(o)
  507. ContractProductDao := Contract.NewContractProduct(o)
  508. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  509. if err != nil {
  510. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  511. c.ServeJSON()
  512. return
  513. }
  514. productList := ContractProductDao.Read_ContractProduct_OutList(contract.T_number)
  515. Stock.Read_Stock_All_Map(T_depot_id)
  516. var pList []Contract.ContractProduct_Out
  517. for _, v := range productList {
  518. p := Contract.ContractProductToContractProduct_Out(v)
  519. p.T_stock_total = Stock.Read_Stock_Get(T_depot_id, p.T_product_id)
  520. pList = append(pList, p)
  521. }
  522. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: pList}
  523. c.ServeJSON()
  524. return
  525. }
  526. // 检查需要删除的合同产品列表
  527. func Check_NeedToDelete_Product_List(list []string, newList []Contract.ContractProduct) (needToDelete map[string]int, all map[int]string) {
  528. var productMap = map[int]int{}
  529. needToDelete = make(map[string]int)
  530. all = make(map[int]string)
  531. for _, v := range list {
  532. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  533. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  534. productMap[product_id] = num
  535. }
  536. for _, product := range newList {
  537. all[product.T_product_id] = fmt.Sprintf("%d-%d", product.Id, product.T_product_total)
  538. _, ok := productMap[product.T_product_id]
  539. if !ok {
  540. id := fmt.Sprintf("%d-%d", product.Id, product.T_product_id)
  541. needToDelete[id] = product.T_product_out
  542. }
  543. }
  544. return
  545. }
  546. // 验证合同
  547. func (c *ContractController) VerifyContract_List() {
  548. // 分页参数 初始化
  549. page, _ := c.GetInt("page")
  550. if page < 1 {
  551. page = 1
  552. }
  553. page_z, _ := c.GetInt("page_z")
  554. if page_z < 1 {
  555. page_z = conf.Page_size
  556. }
  557. T_customer_id := c.GetString("T_customer_id")
  558. // 查询
  559. T_name := c.GetString("T_name")
  560. userList, _ := NatsServer.Read_User_List_All()
  561. Account.Read_User_All_Map(userList)
  562. ContractDao := Contract.NewContract(orm.NewOrm())
  563. R_List, R_cnt := ContractDao.Read_VerifyContract_List(T_name, T_customer_id, page, page_z)
  564. var r_jsons lib.R_JSONS
  565. r_jsons.Num = R_cnt
  566. r_jsons.Data = R_List
  567. r_jsons.Page = page
  568. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  569. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  570. c.ServeJSON()
  571. return
  572. }
  573. // 验证合同呢添加
  574. func (c *ContractController) VerifyContract_Add() {
  575. T_number := c.GetString("T_number")
  576. T_customer_id := c.GetString("T_customer_id")
  577. T_money, _ := c.GetFloat("T_money")
  578. T_discount, _ := c.GetFloat("T_discount")
  579. T_date := c.GetString("T_date")
  580. T_product := c.GetString("T_product")
  581. T_submit := c.GetString("T_submit")
  582. T_remark := c.GetString("T_remark")
  583. T_pdf := c.GetString("T_pdf")
  584. T_project := c.GetString("T_project")
  585. T_recoveries := c.GetString("T_recoveries")
  586. T_invoice := c.GetString("T_invoice")
  587. T_start_date := c.GetString("T_start_date")
  588. T_end_date := c.GetString("T_end_date")
  589. var_ := Contract.Contract{
  590. T_number: T_number,
  591. T_customer_id: T_customer_id,
  592. T_money: float32(T_money),
  593. T_discount: float32(T_discount),
  594. T_project: T_project,
  595. T_type: 2, //合同类型 1-销售合同 2-验证合同
  596. T_date: T_date,
  597. T_State: 1,
  598. T_remark: T_remark,
  599. T_pdf: T_pdf,
  600. T_submit: T_submit,
  601. T_recoveries: T_recoveries,
  602. T_invoice: T_invoice,
  603. T_start_date: T_start_date,
  604. T_end_date: T_end_date,
  605. }
  606. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  607. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  608. o := orm.NewOrm()
  609. o.Begin()
  610. ContractDao := Contract.NewContract(o)
  611. ContractProductDao := Contract.NewContractProduct(o)
  612. _, err := ContractDao.Read_Contract_ByT_date(T_customer_id, T_start_date, T_end_date)
  613. if err == nil {
  614. o.Rollback()
  615. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同签约时间重复!"}
  616. c.ServeJSON()
  617. return
  618. }
  619. _, err = ContractDao.Read_Contract_ByT_number(T_number)
  620. if err == nil {
  621. o.Rollback()
  622. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  623. c.ServeJSON()
  624. return
  625. }
  626. ContractID, err := ContractDao.Add_Contract(var_)
  627. if err != nil {
  628. o.Rollback()
  629. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  630. c.ServeJSON()
  631. return
  632. }
  633. if len(T_product) == 0 {
  634. o.Rollback()
  635. c.Data["json"] = lib.JSONS{Code: 202, Msg: "验证合同明细不能为空"}
  636. c.ServeJSON()
  637. return
  638. }
  639. productList := lib.SplitString(T_product, "|")
  640. ContractOut := 0
  641. for _, v := range productList {
  642. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  643. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  644. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  645. product, _ := Basic.Read_Product_ById(product_id)
  646. contractProduct := Contract.ContractProduct{
  647. T_contract_number: T_number,
  648. T_product_id: product_id,
  649. T_product_total: num,
  650. T_product_out: 0, // 已出库数量
  651. T_price: float32(price), // 价格
  652. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  653. }
  654. if product.T_class < 0 {
  655. contractProduct.T_State = 3
  656. }
  657. if product.T_class == 0 {
  658. ContractOut = 1
  659. }
  660. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  661. if err != nil {
  662. o.Rollback()
  663. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  664. c.ServeJSON()
  665. return
  666. }
  667. }
  668. o.Commit()
  669. o2 := orm.NewOrm()
  670. ContractDao2 := Contract.NewContract(o2)
  671. if ContractOut == 1 {
  672. err = ContractDao2.Update_Contract(Contract.Contract{Id: int(ContractID), T_out: ContractOut}, "T_out")
  673. if err != nil {
  674. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新合同出库状态失败"}
  675. c.ServeJSON()
  676. return
  677. }
  678. }
  679. err = Update_VerifyContract_State(T_customer_id, "ADD")
  680. if err != nil {
  681. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  682. c.ServeJSON()
  683. return
  684. }
  685. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加", var_)
  686. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  687. c.ServeJSON()
  688. return
  689. }
  690. // 验证合同呢修改
  691. func (c *ContractController) VerifyContract_Edit() {
  692. T_number := c.GetString("T_number")
  693. T_money, _ := c.GetFloat("T_money")
  694. T_date := c.GetString("T_date")
  695. T_product := c.GetString("T_product")
  696. T_remark := c.GetString("T_remark")
  697. T_pdf := c.GetString("T_pdf")
  698. T_project := c.GetString("T_project")
  699. T_recoveries := c.GetString("T_recoveries")
  700. T_invoice := c.GetString("T_invoice")
  701. T_start_date := c.GetString("T_start_date")
  702. T_end_date := c.GetString("T_end_date")
  703. T_submit := c.GetString("T_submit")
  704. o := orm.NewOrm()
  705. o.Begin()
  706. ContractDao := Contract.NewContract(o)
  707. ContractProductDao := Contract.NewContractProduct(o)
  708. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  709. if err != nil || contract.T_type == 1 {
  710. o.Rollback()
  711. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  712. c.ServeJSON()
  713. return
  714. }
  715. if T_money > 0 {
  716. contract.T_money = float32(T_money)
  717. }
  718. if len(T_date) > 0 {
  719. contract.T_date = T_date
  720. }
  721. if len(T_remark) > 0 {
  722. contract.T_remark = T_remark
  723. }
  724. if len(T_pdf) > 0 {
  725. contract.T_pdf = T_pdf
  726. }
  727. if len(T_project) > 0 {
  728. contract.T_project = T_project
  729. }
  730. if len(T_recoveries) > 0 {
  731. contract.T_recoveries = T_recoveries
  732. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  733. }
  734. if len(T_invoice) > 0 {
  735. contract.T_invoice = T_invoice
  736. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  737. }
  738. if len(T_start_date) > 0 {
  739. contract.T_start_date = T_start_date
  740. }
  741. if len(T_end_date) > 0 {
  742. contract.T_end_date = T_end_date
  743. }
  744. if len(T_submit) > 0 {
  745. contract.T_submit = T_submit
  746. }
  747. err = ContractDao.Update_Contract(contract, "T_money", "T_date", "T_remark", "T_pdf", "T_State", "T_project",
  748. "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_start_date", "T_end_date", "T_submit")
  749. if err != nil {
  750. o.Rollback()
  751. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  752. c.ServeJSON()
  753. return
  754. }
  755. if len(T_product) == 0 {
  756. o.Rollback()
  757. c.Data["json"] = lib.JSONS{Code: 202, Msg: "产品明细不能为空"}
  758. c.ServeJSON()
  759. return
  760. }
  761. productList := lib.SplitString(T_product, "|")
  762. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(T_number)
  763. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  764. // 检查编辑时需要修改的产品
  765. for k, v := range needToDeleteList {
  766. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  767. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  768. if v > 0 {
  769. o.Rollback()
  770. product, _ := Basic.Read_Product_ById(productId)
  771. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  772. c.ServeJSON()
  773. return
  774. }
  775. cp := Contract.ContractProduct{Id: id}
  776. err = ContractProductDao.Delete_ContractProduct(cp)
  777. if err != nil {
  778. o.Rollback()
  779. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  780. c.ServeJSON()
  781. return
  782. }
  783. }
  784. for _, v := range productList {
  785. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  786. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  787. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  788. oldContractProduct, ok := allList[product_id]
  789. if !ok {
  790. contractProduct := Contract.ContractProduct{
  791. T_contract_number: T_number,
  792. T_product_id: product_id,
  793. T_product_total: num,
  794. T_product_out: 0, // 已出库数量
  795. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  796. }
  797. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  798. if err != nil {
  799. o.Rollback()
  800. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  801. c.ServeJSON()
  802. return
  803. } else {
  804. continue
  805. }
  806. }
  807. // 修改产品总数量
  808. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  809. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  810. if oldNum == num {
  811. continue
  812. }
  813. cp := Contract.ContractProduct{
  814. Id: contractProductId,
  815. T_product_total: num,
  816. T_price: float32(price), // 价格
  817. }
  818. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
  819. if err != nil {
  820. o.Rollback()
  821. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  822. c.ServeJSON()
  823. return
  824. }
  825. }
  826. o.Commit()
  827. err = Update_VerifyContract_State(contract.T_customer_id, "UPDATE")
  828. if err != nil {
  829. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  830. c.ServeJSON()
  831. return
  832. }
  833. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "修改", contract)
  834. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  835. c.ServeJSON()
  836. return
  837. }
  838. func (c *ContractController) VerifyContract_Del() {
  839. T_number := c.GetString("T_number")
  840. o := orm.NewOrm()
  841. o.Begin()
  842. ContractDao := Contract.NewContract(o)
  843. ContractProductDao := Contract.NewContractProduct(o)
  844. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  845. if err != nil {
  846. o.Rollback()
  847. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  848. c.ServeJSON()
  849. return
  850. }
  851. err = ContractDao.Delete_Contract(contract)
  852. if err != nil {
  853. o.Rollback()
  854. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  855. c.ServeJSON()
  856. return
  857. }
  858. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  859. for _, v := range cpList {
  860. err = ContractProductDao.Delete_ContractProduct(v)
  861. if err != nil {
  862. o.Rollback()
  863. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  864. c.ServeJSON()
  865. return
  866. }
  867. }
  868. o.Commit()
  869. err = Update_VerifyContract_State(contract.T_customer_id, "DELETE")
  870. if err != nil {
  871. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改状态失败"}
  872. c.ServeJSON()
  873. return
  874. }
  875. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "删除", T_number)
  876. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  877. c.ServeJSON()
  878. return
  879. }
  880. func Update_VerifyContract_State(T_customer_id, flag string) error {
  881. o := orm.NewOrm()
  882. ContractDao := Contract.NewContract(o)
  883. VerifyContractDao := Contract.NewVerifyContract(o)
  884. vcn := ContractDao.Read_VerifyContract_Newest(T_customer_id)
  885. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  886. if err != nil {
  887. return err
  888. }
  889. if vcn.Id == 0 {
  890. vc.T_sign_times = 0
  891. vc.T_start_date = ""
  892. vc.T_end_date = ""
  893. vc.T_State = 1
  894. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  895. return err
  896. }
  897. if flag == "ADD" {
  898. vc.T_sign_times += 1
  899. } else if flag == "DELETE" {
  900. vc.T_sign_times -= 1
  901. }
  902. if len(vc.T_start_date) == 0 {
  903. vc.T_start_date = vcn.T_start_date
  904. }
  905. if vc.T_end_date != vcn.T_end_date {
  906. vc.T_end_date = vcn.T_end_date
  907. }
  908. nowTime := time.Now()
  909. now := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
  910. end, _ := lib.DateStrToTime(vcn.T_end_date)
  911. now2Month := now.AddDate(0, 2, 0)
  912. // 1-未签约 2-已作废 3-已签约 4-即将到期
  913. state := 1
  914. // 结束时间<今天 已过期
  915. if end.Before(now) {
  916. state = 2
  917. } else {
  918. // 结束时间<今天+2月 即将到期 && 结束时间>今天
  919. if end.Before(now2Month) || end.Equal(now) {
  920. state = 4
  921. NatsServer.AddNews(vcn.T_approver, fmt.Sprintf("【合同即将过期提醒】%s的验证合同将于%s过期!", vc.T_customer, vc.T_end_date), conf.VerifyContractUrl)
  922. }
  923. // 结束时间>今天+2月 已签约
  924. if end.After(now2Month) || end.Equal(now2Month) {
  925. state = 3
  926. }
  927. }
  928. vc.T_State = state
  929. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  930. return err
  931. }
  932. // 验证合同-添加客户
  933. func (c *ContractController) VerifyContract_Add_Customer() {
  934. T_customer := c.GetString("T_customer")
  935. o := orm.NewOrm()
  936. VerifyContractDao := Contract.NewVerifyContract(o)
  937. T_number := ""
  938. for true {
  939. rand_x := 1
  940. T_number = fmt.Sprintf("YZKH-%s", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", int64(rand_x)))
  941. _, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_number)
  942. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  943. break
  944. }
  945. rand_x += 1
  946. }
  947. var_ := Contract.VerifyContract{
  948. T_customer: T_customer,
  949. T_customer_id: T_number,
  950. T_State: 1,
  951. }
  952. _, err := VerifyContractDao.Add_VerifyContract(var_)
  953. if err != nil {
  954. o.Rollback()
  955. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  956. c.ServeJSON()
  957. return
  958. }
  959. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加客户", var_)
  960. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  961. c.ServeJSON()
  962. return
  963. }
  964. // 验证合同-编辑客户
  965. func (c *ContractController) VerifyContract_Update_Customer() {
  966. T_customer_id := c.GetString("T_customer_id")
  967. T_customer := c.GetString("T_customer")
  968. o := orm.NewOrm()
  969. VerifyContractDao := Contract.NewVerifyContract(o)
  970. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  971. vc.T_customer = T_customer
  972. err = VerifyContractDao.Update_VerifyContract(vc)
  973. if err != nil {
  974. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  975. c.ServeJSON()
  976. return
  977. }
  978. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "编辑客户", vc)
  979. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_customer_id}
  980. c.ServeJSON()
  981. return
  982. }
  983. // 验证合同-客户列表
  984. func (c *ContractController) VerifyContract_Customer_List() {
  985. // 分页参数 初始化
  986. page, _ := c.GetInt("page")
  987. if page < 1 {
  988. page = 1
  989. }
  990. page_z, _ := c.GetInt("page_z")
  991. if page_z < 1 {
  992. page_z = conf.Page_size
  993. }
  994. // 查询
  995. T_name := c.GetString("T_name")
  996. T_state, _ := c.GetInt("T_state")
  997. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  998. R_List, R_cnt := VerifyContractDao.Read_VerifyContract_List(T_name, T_state, page, page_z)
  999. var r_jsons lib.R_JSONS
  1000. r_jsons.Num = R_cnt
  1001. r_jsons.Data = R_List
  1002. r_jsons.Page = page
  1003. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1004. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1005. c.ServeJSON()
  1006. return
  1007. }
  1008. // 合同回款明细列表
  1009. func (c *ContractController) Contract_List_RecoveriesMoney() {
  1010. // 分页参数 初始化
  1011. page, _ := c.GetInt("page")
  1012. if page < 1 {
  1013. page = 1
  1014. }
  1015. page_z, _ := c.GetInt("page_z")
  1016. if page_z < 1 {
  1017. page_z = conf.Page_size
  1018. }
  1019. // 查询
  1020. T_name := c.GetString("T_name")
  1021. T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
  1022. T_invoice_state, _ := c.GetInt("T_invoice_state") // 开票状态 1 未开票 2 部分开票 3 全部开票
  1023. userList, _ := NatsServer.Read_User_List_All()
  1024. Account.Read_User_All_Map(userList)
  1025. ContractDao := Contract.NewContract(orm.NewOrm())
  1026. R_List, R_cnt := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(T_name, T_recoveries_state, T_invoice_state, page, page_z)
  1027. var r_jsons lib.R_JSONS
  1028. r_jsons.Num = R_cnt
  1029. r_jsons.Data = R_List
  1030. r_jsons.Page = page
  1031. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1032. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1033. c.ServeJSON()
  1034. return
  1035. }
  1036. func Cron_VerifyContract() {
  1037. //创建一个定时任务对象
  1038. c := cron.New(cron.WithSeconds())
  1039. //给对象增加定时任务
  1040. //c.AddFunc("0 */1 * * * ?", Cron_VerifyContract_ChangeState)
  1041. c.AddFunc("@daily", Cron_VerifyContract_ChangeState)
  1042. //启动定时任务
  1043. c.Start()
  1044. defer c.Stop()
  1045. //查询语句,阻塞,让main函数不退出,保持程序运行
  1046. select {}
  1047. }
  1048. // 修改合同状态
  1049. func Cron_VerifyContract_ChangeState() {
  1050. T_date := time.Now().Format("2006-01-02")
  1051. logs.Info("开始处理" + T_date + "验证合同状态")
  1052. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  1053. R_List, _ := VerifyContractDao.Read_VerifyContract_List("", 0, 0, 999)
  1054. for _, v := range R_List {
  1055. err := Update_VerifyContract_State(v.T_customer_id, "UPDATE")
  1056. if err != nil {
  1057. logs.Error("修改合同状态失败")
  1058. }
  1059. }
  1060. }
  1061. // 修改回款金额及开票金额
  1062. func UpdateVerifyContract_RecoveriesInvoice_Money() {
  1063. ContractDao := Contract.NewContract(orm.NewOrm())
  1064. R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
  1065. for _, verify := range R_List {
  1066. R := Contract.Contract{Id: verify.Id}
  1067. _, R.T_recoveries_money = Contract.ContractToContractFinance_R(verify.T_recoveries)
  1068. _, R.T_invoice_money = Contract.ContractToContractFinance_R(verify.T_invoice)
  1069. ContractDao.Update_Contract(R, "T_recoveries_money", "T_invoice_money")
  1070. }
  1071. }