contract_approval.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. package contract
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // 合同审批单
  8. type ContractApproval struct {
  9. ContractApprovalId int `orm:"column(contract_approval_id);pk"`
  10. ApprovalType string `description:"审批单类型,枚举值,合同:contract;用印:sale;默认:contract"`
  11. ContractId int `orm:"column(contract_id)" description:"合同id"`
  12. Status string `description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  13. ApplyContent string `description:"待审内容,长度255位"`
  14. ContractDetail string `description:"审批单详情,完整的合同json数据"`
  15. ApplyUserId int `description:"申请人id"`
  16. ApplyUserName string `description:"申请人名称"`
  17. ApproveRemark string `description:"审批人备注,可以是驳回理由,长度128位"`
  18. FlowId int `description:"审批流程id"`
  19. FlowVersion int `description:"审批流程版本"`
  20. CurrNodeId int `description:"当前审批节点id"`
  21. StartNodeId int `description:"开始审批节点id"`
  22. ModifyTime time.Time `description:"发起申请时间"`
  23. CreateTime time.Time `description:"最近一次审批单修改时间"`
  24. }
  25. // 根据合同审批单id获取合同审批单信息
  26. func GetContractApprovalById(contractApprovalId int) (contractApprovalInfo *ContractApproval, err error) {
  27. o := orm.NewOrm()
  28. sql := `select * from contract_approval where contract_approval_id = ? `
  29. err = o.Raw(sql, contractApprovalId).QueryRow(&contractApprovalInfo)
  30. return
  31. }
  32. // 根据合同id获取最近一次待审批的合同审批单信息
  33. func GetLastPendingContractApprovalByContractId(contractId int, approvalType string) (contractApprovalInfo *ContractApproval, err error) {
  34. o := orm.NewOrm()
  35. sql := `select * from contract_approval where status = "待审批" AND contract_id=? AND approval_type=?`
  36. err = o.Raw(sql, contractId, approvalType).QueryRow(&contractApprovalInfo)
  37. return
  38. }
  39. // 根据合同id获取最近一次提交的合同审批单信息
  40. func GetLastContractApprovalByContractId(contractId int, approvalType string) (contractApprovalInfo *ContractApproval, err error) {
  41. o := orm.NewOrm()
  42. sql := `select * from contract_approval where contract_id=? and approval_type =? order by contract_approval_id desc`
  43. err = o.Raw(sql, contractId, approvalType).QueryRow(&contractApprovalInfo)
  44. return
  45. }
  46. // GetRejectContractCountByContractId 根据合同id获取总共被驳回的次数
  47. func GetRejectContractCountByContractId(contractId int, approvalType string) (total int64, err error) {
  48. o := orm.NewOrm()
  49. sql := `select count(1) total from contract_approval where status = "已驳回" AND contract_id=? and approval_type =? `
  50. err = o.Raw(sql, contractId, approvalType).QueryRow(&total)
  51. return
  52. }
  53. // GetLastContractApprovalByContractIdAndStatus 根据合同id获取最近已驳回、已审批的审批单
  54. func GetLastContractApprovalByContractIdAndStatus(contractId int, approvalType string) (item *ContractApproval, err error) {
  55. o := orm.NewOrm()
  56. sql := `select * from contract_approval where status in ("已驳回","已审批") AND contract_id=? and approval_type =? order by contract_approval_id desc`
  57. err = o.Raw(sql, contractId, approvalType).QueryRow(&item)
  58. return
  59. }
  60. // 获取审批列表数据数量
  61. func GetContractApprovalListCount(condition string, pars []interface{}) (count int, err error) {
  62. o := orm.NewOrm()
  63. sql := `
  64. SELECT a.* from contract_approval a
  65. JOIN contract c ON a.contract_id = c.contract_id
  66. WHERE
  67. c.is_delete = 0 and a.approval_type = "contract" `
  68. sql += condition
  69. sql += ` GROUP BY a.contract_id `
  70. sql = `select count(*) count from (` + sql + `) b`
  71. err = o.Raw(sql, pars).QueryRow(&count)
  72. return
  73. }
  74. // 审批列表
  75. type ContractApprovalList struct {
  76. ContractApprovalId int `description:"审批单id"`
  77. ContractId int `description:"合同id"`
  78. ContractApprovalRecordId int `description:"审批流id"`
  79. ContractCode string `description:"合同编号"`
  80. Status string `description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  81. ContractStatus string `json:"-" description:"合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回','已解约',默认待审批"`
  82. ApplyContent string `description:"待审内容"`
  83. ContractDetail string `json:"-" description:"提交审批时的合同信息;合同快照"`
  84. ContractInfo ContractDetail `description:"提交审批时的合同信息;合同快照"`
  85. ApproveRemark string `description:"审核备注"`
  86. ContractType string `description:"合同类型"`
  87. ContractBusinessType string `description:"合同业务类型"`
  88. PayChannel string `description:"支付渠道"`
  89. Price float64 `description:"合同金额"`
  90. OriginalPrice float64 `json:"-" description:"合同金额"`
  91. CompanyName string `description:"客户名称"`
  92. FileUrl string `description:"合同下载地址"`
  93. CheckBackFileUrl string `description:"签回合同下载地址"`
  94. RescindFileUrl string `description:"解约合同下载地址"`
  95. SellerId int `description:"销售id"`
  96. ProductId int `description:"产品id,1:ficc;2:权益"`
  97. SellerName string `description:"销售名称"`
  98. StartDate time.Time `description:"合同开始日期"`
  99. EndDate time.Time `description:"合同结束日期"`
  100. CreateTime time.Time `description:"发起审批的时间"`
  101. ModifyTime time.Time `description:"最后一次修改的时间"`
  102. ApproveTime time.Time `description:"审批时间"`
  103. InvalidTime time.Time `description:"作废时间"`
  104. CheckBackFileTime time.Time `description:"合同签回时间"`
  105. RescindTime time.Time `description:"解约时间"`
  106. StartDateStr string `description:"合同开始日期(字符串类型)"`
  107. EndDateStr string `description:"合同结束日期(字符串类型)"`
  108. CreateTimeStr string `description:"发起审批的时间(字符串类型)"`
  109. ModifyTimeStr string `description:"最后一次修改的时间(字符串类型)"`
  110. ApproveTimeStr string `description:"审批时间(字符串类型)"`
  111. InvalidTimeStr string `description:"作废时间(字符串类型)"`
  112. CheckBackFileTimeStr string `description:"合同签回时间(字符串类型)"`
  113. RescindTimeStr string `description:"解约时间(字符串类型)"`
  114. OpButton ContractButton `description:"按钮操作权限"`
  115. Remark string `json:"-" description:"备注"`
  116. }
  117. // 合同权限
  118. type ContractButton struct {
  119. Approval bool `description:"是否具有审核操作权限,true才允许审核操作"`
  120. CheckBackFile bool `description:"是否具有文件签回权限,true才允许操作"`
  121. RescindFile bool `description:"是否具有文件解约权限,true才允许操作"`
  122. }
  123. // 获取审批列表数据
  124. func GetContractApprovalList(childCondition, condition string, childPars, pars []interface{}, startSize, pageSize int) (list []*ContractApprovalList, err error) {
  125. o := orm.NewOrm()
  126. sql := `
  127. SELECT
  128. a.contract_approval_id,a.contract_id,a.apply_content,a.contract_detail,a.approve_remark,a.create_time,a.modify_time,a.status,c.status contract_status,c.product_id,
  129. c.contract_type,c.contract_business_type,c.pay_channel,c.start_date,c.end_date,c.price,c.original_price,c.remark,c.company_name,c.seller_id,c.seller_name,c.file_url,c.contract_code,c.approve_time,c.invalid_time,c.check_back_file_url,c.rescind_file_url,c.check_back_file_time,c.rescind_time from contract_approval a
  130. join ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type="contract"`
  131. sql += childCondition
  132. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  133. JOIN contract c ON a.contract_id = c.contract_id
  134. WHERE c.is_delete = 0 and a.approval_type="contract" `
  135. sql += condition
  136. sql += ` group by contract_id order by modify_time desc LIMIT ?,? `
  137. _, err = o.Raw(sql, childPars, pars, startSize, pageSize).QueryRows(&list)
  138. return
  139. }
  140. // 根据合同id获取合同审批单信息
  141. func (ContractApproval) CheckPendingByContractId(contractId int, approvalType string) (has bool, err error) {
  142. o := orm.NewOrm()
  143. var contractApprovalInfo ContractApproval
  144. sql := `select * from contract_approval where contract_id = ? AND approval_type =? AND status="待审批" limit 1`
  145. err = o.Raw(sql, contractId, approvalType).QueryRow(&contractApprovalInfo)
  146. if err != nil {
  147. if err.Error() == utils.ErrNoRow() {
  148. //如果不存在待审批记录,那么报错信息置空,存在与否直接返回false
  149. err = nil
  150. return
  151. }
  152. //系统异常,返回错误信息
  153. return
  154. }
  155. //存在待审批的审批单
  156. has = true
  157. return
  158. }
  159. // 根据审批单id获取所有审批流列表信息
  160. func GetContractApprovalRecordListByContractApprovalIdAndNodeId(contractApprovalId, nodeId int) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  161. o := orm.NewOrm()
  162. sql := `select * from contract_approval_record where contract_approval_id=? and node_id=? order by node_id,contract_approval_record_id asc`
  163. _, err = o.Raw(sql, contractApprovalId, nodeId).QueryRows(&contractApprovalRecordList)
  164. return
  165. }
  166. // 发起审批
  167. func (ContractApproval) Apply(contractApprovalInfo *ContractApproval, contractApprovalRecord *ContractApprovalRecord) (err error) {
  168. o := orm.NewOrm()
  169. to, err := o.Begin()
  170. if err != nil {
  171. return
  172. }
  173. defer func() {
  174. if err != nil {
  175. _ = to.Rollback()
  176. } else {
  177. _ = to.Commit()
  178. }
  179. }()
  180. //审批单记录
  181. ContractApprovalId, err := to.Insert(contractApprovalInfo)
  182. if err != nil {
  183. return
  184. }
  185. //审批单id
  186. contractApprovalInfo.ContractApprovalId = int(ContractApprovalId)
  187. //审批流记录
  188. contractApprovalRecord.ContractApprovalId = contractApprovalInfo.ContractApprovalId
  189. contractApprovalRecordId, err := to.Insert(contractApprovalRecord)
  190. if err != nil {
  191. return
  192. }
  193. //审批流id
  194. contractApprovalRecord.ContractApprovalRecordId = int(contractApprovalRecordId)
  195. //修改合同状态为待审批
  196. sql := `UPDATE contract SET status="待审批",modify_time=NOW() WHERE contract_id = ?`
  197. _, err = to.Raw(sql, contractApprovalInfo.ContractId).Exec()
  198. return
  199. }
  200. // 发起审批(工作流)
  201. func (ContractApproval) Apply2(contractApprovalInfo *ContractApproval, contractApprovalRecordList []*ContractApprovalRecord) (err error) {
  202. o := orm.NewOrm()
  203. to, err := o.Begin()
  204. if err != nil {
  205. return
  206. }
  207. defer func() {
  208. if err != nil {
  209. _ = to.Rollback()
  210. } else {
  211. _ = to.Commit()
  212. }
  213. }()
  214. //审批单记录
  215. ContractApprovalId, err := to.Insert(contractApprovalInfo)
  216. if err != nil {
  217. return
  218. }
  219. //审批单id
  220. contractApprovalInfo.ContractApprovalId = int(ContractApprovalId)
  221. for _, contractApprovalRecord := range contractApprovalRecordList {
  222. //审批流记录
  223. contractApprovalRecord.ContractApprovalId = contractApprovalInfo.ContractApprovalId
  224. contractApprovalRecordId, tmpErr := to.Insert(contractApprovalRecord)
  225. if tmpErr != nil {
  226. err = tmpErr
  227. return
  228. }
  229. //审批流id
  230. contractApprovalRecord.ContractApprovalRecordId = int(contractApprovalRecordId)
  231. }
  232. switch contractApprovalInfo.ApprovalType {
  233. case "contract":
  234. //修改合同状态为待审批
  235. sql := `UPDATE contract SET status="待审批",modify_time=NOW() WHERE contract_id = ?`
  236. _, err = to.Raw(sql, contractApprovalInfo.ContractId).Exec()
  237. case "seal":
  238. //修改用印状态为待审批
  239. sql := `UPDATE seal SET status="待审批",modify_time=NOW() WHERE seal_id = ?`
  240. _, err = to.Raw(sql, contractApprovalInfo.ContractId).Exec()
  241. case "company":
  242. //修改客户单状态为待审批
  243. //因为本身就是待审批,所以不需要
  244. }
  245. return
  246. }
  247. // 撤回审核单
  248. func (ContractApproval) Cancel(contractApprovalInfo *ContractApproval, contractApprovalRecordList []*ContractApprovalRecord) (err error) {
  249. o := orm.NewOrm()
  250. to, err := o.Begin()
  251. if err != nil {
  252. return
  253. }
  254. defer func() {
  255. if err != nil {
  256. _ = to.Rollback()
  257. } else {
  258. _ = to.Commit()
  259. }
  260. }()
  261. //变更审批单记录
  262. contractApprovalInfo.Status = "已撤回"
  263. contractApprovalInfo.ModifyTime = time.Now()
  264. _, err = to.Update(contractApprovalInfo, "Status", "ModifyTime")
  265. if err != nil {
  266. return
  267. }
  268. //变更所有审批流记录
  269. for _, contractApprovalRecord := range contractApprovalRecordList {
  270. contractApprovalRecord.Status = "已撤回"
  271. contractApprovalRecord.ModifyTime = time.Now()
  272. _, tmpErr := to.Update(contractApprovalRecord, "Status", "ModifyTime")
  273. if tmpErr != nil {
  274. err = tmpErr
  275. return
  276. }
  277. }
  278. //撤回审批单
  279. switch contractApprovalInfo.ApprovalType {
  280. case "contract":
  281. //修改合同状态为已撤回
  282. sql := `UPDATE contract SET status="已撤回",modify_time=NOW() WHERE contract_id = ?`
  283. _, err = to.Raw(sql, contractApprovalInfo.ContractId).Exec()
  284. return
  285. case "seal":
  286. // 修改用印审批状态为已撤回
  287. sql := `UPDATE seal SET status="已撤回",modify_time=NOW() WHERE seal_id = ?`
  288. _, err = to.Raw(sql, contractApprovalInfo.ContractId).Exec()
  289. return
  290. }
  291. return
  292. }
  293. // 审核驳回
  294. func (ContractApproval) Reject(contractApprovalInfo *ContractApproval, contractApprovalRecord *ContractApprovalRecord, approveUserId int, approveUserName, remark string) (err error) {
  295. o := orm.NewOrm()
  296. to, err := o.Begin()
  297. if err != nil {
  298. return
  299. }
  300. defer func() {
  301. if err != nil {
  302. _ = to.Rollback()
  303. } else {
  304. _ = to.Commit()
  305. }
  306. }()
  307. //变更审批单记录
  308. contractApprovalInfo.Status = "已驳回"
  309. contractApprovalInfo.ApproveRemark = remark //审核失败理由
  310. contractApprovalInfo.ModifyTime = time.Now()
  311. //contractApprovalInfo.CurrNodeId = 0 //当前节点变更为0,代表当前审批流程已经结束了
  312. _, err = to.Update(contractApprovalInfo, "Status", "ApproveRemark", "ModifyTime")
  313. if err != nil {
  314. return
  315. }
  316. //变更审批流记录
  317. contractApprovalRecord.Status = "已驳回"
  318. contractApprovalRecord.ApproveRemark = remark //审核失败理由
  319. contractApprovalRecord.ApproveUserId = approveUserId //审批人id
  320. contractApprovalRecord.ApproveUserName = approveUserName //审批人名称
  321. contractApprovalRecord.ApproveTime = time.Now() //审批时间
  322. contractApprovalRecord.ModifyTime = time.Now()
  323. _, err = to.Update(contractApprovalRecord, "Status", "ApproveRemark", "ApproveUserId", "ApproveUserName", "ApproveTime", "ModifyTime")
  324. if err != nil {
  325. return
  326. }
  327. //修改合同状态为已驳回
  328. switch contractApprovalInfo.ApprovalType {
  329. case "contract":
  330. //修改合同状态为已驳回
  331. sql := `UPDATE contract SET status="已驳回",modify_content="",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE contract_id = ?`
  332. _, err = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  333. case "seal":
  334. //修改用印状态为已驳回
  335. sql := `UPDATE seal SET status="已驳回",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE seal_id = ?`
  336. _, err = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  337. }
  338. return
  339. }
  340. // 下级审批人信息
  341. type NextApproval struct {
  342. ApproveRoleTypeCode string
  343. ApproveUserId int
  344. ApproveUserName string
  345. }
  346. // 审核通过
  347. func (ContractApproval) ApprovedOld(contractApprovalInfo *ContractApproval, contractApprovalRecord *ContractApprovalRecord, approveUserId int, approveUserName, remark string, nextApproval NextApproval) (err error) {
  348. o := orm.NewOrm()
  349. to, err := o.Begin()
  350. if err != nil {
  351. return
  352. }
  353. defer func() {
  354. if err != nil {
  355. _ = to.Rollback()
  356. } else {
  357. _ = to.Commit()
  358. }
  359. }()
  360. //变更审批流记录
  361. contractApprovalRecord.Status = "已审批"
  362. contractApprovalRecord.ApproveRemark = remark //审核失败理由
  363. contractApprovalRecord.ApproveUserId = approveUserId //审批人id
  364. contractApprovalRecord.ApproveUserName = approveUserName //审批人名称
  365. contractApprovalRecord.ApproveTime = time.Now() //审批人名称
  366. contractApprovalRecord.ModifyTime = time.Now()
  367. _, err = to.Update(contractApprovalRecord, "Status", "ApproveRemark", "ApproveUserId", "ApproveUserName", "ApproveTime", "ModifyTime")
  368. if err != nil {
  369. return
  370. }
  371. //判断是否存在下一级的审批人,如果不存在,那么就去变更审批单和合同的状态
  372. if nextApproval.ApproveRoleTypeCode == "" && nextApproval.ApproveUserId == 0 {
  373. //变更审批单记录
  374. contractApprovalInfo.Status = "已审批"
  375. contractApprovalInfo.ApproveRemark = remark //审核理由
  376. contractApprovalInfo.ModifyTime = time.Now()
  377. _, tmpErr := to.Update(contractApprovalInfo, "Status", "ApproveRemark", "ModifyTime")
  378. if tmpErr != nil {
  379. err = tmpErr
  380. return
  381. }
  382. //修改合同状态为已审批
  383. sql := `UPDATE contract SET status="已审批",approval_remark=?,modify_time=NOW() WHERE contract_id = ?`
  384. _, tmpErr = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  385. if tmpErr != nil {
  386. err = tmpErr
  387. return
  388. }
  389. } else {
  390. //如果还存在下一级审批人,那么进入下级审批流
  391. nextContractApprovalRecord := &ContractApprovalRecord{
  392. ContractApprovalId: contractApprovalInfo.ContractApprovalId,
  393. Status: "待审批",
  394. ApproveRoleTypeCode: nextApproval.ApproveRoleTypeCode,
  395. ApproveUserId: nextApproval.ApproveUserId,
  396. ApproveUserName: nextApproval.ApproveUserName,
  397. ModifyTime: time.Now(),
  398. CreateTime: time.Now(),
  399. }
  400. nextContractApprovalRecordId, tmpErr := to.Insert(nextContractApprovalRecord)
  401. if tmpErr != nil {
  402. err = tmpErr
  403. return
  404. }
  405. nextContractApprovalRecord.ContractApprovalRecordId = int(nextContractApprovalRecordId)
  406. }
  407. return
  408. }
  409. func (ContractApproval) Approved(contractApprovalInfo *ContractApproval, contractApprovalRecord *ContractApprovalRecord, remark string) (err error) {
  410. o := orm.NewOrm()
  411. to, err := o.Begin()
  412. if err != nil {
  413. return
  414. }
  415. defer func() {
  416. if err != nil {
  417. _ = to.Rollback()
  418. } else {
  419. _ = to.Commit()
  420. }
  421. }()
  422. //变更审批流记录
  423. contractApprovalRecord.Status = "已审批"
  424. contractApprovalRecord.ApproveRemark = remark //审核失败理由
  425. contractApprovalRecord.ApproveTime = time.Now() //审批时间
  426. contractApprovalRecord.ModifyTime = time.Now()
  427. _, err = to.Update(contractApprovalRecord, "Status", "ApproveRemark", "ApproveTime", "ModifyTime")
  428. if err != nil {
  429. return
  430. }
  431. //如果没有下级节点了,那么完成该审批单
  432. if contractApprovalRecord.NextNodeId <= 0 {
  433. //变更审批单记录
  434. contractApprovalInfo.Status = "已审批"
  435. contractApprovalInfo.ApproveRemark = remark //审核理由
  436. //contractApprovalInfo.CurrNodeId = contractApprovalRecord.NextNodeId //下级审批节点id
  437. contractApprovalInfo.ModifyTime = time.Now()
  438. _, tmpErr := to.Update(contractApprovalInfo, "Status", "ApproveRemark", "ModifyTime")
  439. if tmpErr != nil {
  440. err = tmpErr
  441. return
  442. }
  443. //修改合同状态为已审批
  444. switch contractApprovalInfo.ApprovalType {
  445. case "contract":
  446. //修改合同状态为已审批
  447. sql := `UPDATE contract SET status="已审批",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE contract_id = ?`
  448. _, tmpErr = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  449. if tmpErr != nil {
  450. err = tmpErr
  451. return
  452. }
  453. case "seal":
  454. //修改用印状态为已审批
  455. sql := `UPDATE seal SET status="已审批",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE seal_id = ?`
  456. _, tmpErr = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  457. if tmpErr != nil {
  458. err = tmpErr
  459. return
  460. }
  461. }
  462. } else {
  463. //变更审批单记录
  464. contractApprovalInfo.ApproveRemark = remark //审核理由
  465. contractApprovalInfo.CurrNodeId = contractApprovalRecord.NextNodeId //下级审批节点id
  466. contractApprovalInfo.ModifyTime = time.Now()
  467. _, tmpErr := to.Update(contractApprovalInfo, "ApproveRemark", "CurrNodeId", "ModifyTime")
  468. if tmpErr != nil {
  469. err = tmpErr
  470. return
  471. }
  472. }
  473. return
  474. }
  475. // 抄送
  476. func (ContractApproval) ApprovedByCc(contractApprovalInfo *ContractApproval, contractApprovalRecordList []*ContractApprovalRecord, remark string, nextNodeId int) (err error) {
  477. o := orm.NewOrm()
  478. to, err := o.Begin()
  479. if err != nil {
  480. return
  481. }
  482. defer func() {
  483. if err != nil {
  484. _ = to.Rollback()
  485. } else {
  486. _ = to.Commit()
  487. }
  488. }()
  489. for _, contractApprovalRecord := range contractApprovalRecordList {
  490. //变更审批流记录
  491. contractApprovalRecord.Status = "已审批"
  492. contractApprovalRecord.ApproveTime = time.Now() //审批时间
  493. contractApprovalRecord.ModifyTime = time.Now()
  494. _, err = to.Update(contractApprovalRecord, "Status", "ApproveTime", "ModifyTime")
  495. if err != nil {
  496. return
  497. }
  498. }
  499. if err != nil {
  500. return
  501. }
  502. //如果没有下级节点了,那么完成该审批单
  503. if nextNodeId <= 0 {
  504. //变更审批单记录
  505. contractApprovalInfo.Status = "已审批"
  506. //contractApprovalInfo.CurrNodeId = nextNodeId //下级审批节点id
  507. contractApprovalInfo.ModifyTime = time.Now()
  508. _, tmpErr := to.Update(contractApprovalInfo, "Status", "ModifyTime")
  509. if tmpErr != nil {
  510. err = tmpErr
  511. return
  512. }
  513. //修改合同状态为已审批
  514. switch contractApprovalInfo.ApprovalType {
  515. case "contract":
  516. //修改合同状态为已审批
  517. sql := `UPDATE contract SET status="已审批",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE contract_id = ?`
  518. _, tmpErr = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  519. if tmpErr != nil {
  520. err = tmpErr
  521. return
  522. }
  523. case "seal":
  524. //修改用印状态为已审批
  525. sql := `UPDATE seal SET status="已审批",approval_remark=?,approve_time=NOW(),modify_time=NOW() WHERE seal_id = ?`
  526. _, tmpErr = to.Raw(sql, remark, contractApprovalInfo.ContractId).Exec()
  527. if tmpErr != nil {
  528. err = tmpErr
  529. return
  530. }
  531. }
  532. } else {
  533. //变更审批单记录
  534. contractApprovalInfo.CurrNodeId = nextNodeId //下级审批节点id
  535. contractApprovalInfo.ModifyTime = time.Now()
  536. _, tmpErr := to.Update(contractApprovalInfo, "CurrNodeId", "ModifyTime")
  537. if tmpErr != nil {
  538. err = tmpErr
  539. return
  540. }
  541. }
  542. return
  543. }