ctr_contract.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "encoding/base64"
  6. "encoding/json"
  7. "fmt"
  8. "io"
  9. "net/http"
  10. "strconv"
  11. "strings"
  12. "time"
  13. basedao "dashoo.cn/micro/app/dao/base"
  14. dao "dashoo.cn/micro/app/dao/contract"
  15. custdao "dashoo.cn/micro/app/dao/cust"
  16. projdao "dashoo.cn/micro/app/dao/proj"
  17. workflowdao "dashoo.cn/micro/app/dao/workflow"
  18. model "dashoo.cn/micro/app/model/contract"
  19. proj "dashoo.cn/micro/app/model/proj"
  20. workflowModel "dashoo.cn/micro/app/model/workflow"
  21. "dashoo.cn/micro/app/service"
  22. baseService "dashoo.cn/micro/app/service/base"
  23. projsrv "dashoo.cn/micro/app/service/proj"
  24. worksrv "dashoo.cn/micro/app/service/work"
  25. workflowService "dashoo.cn/micro/app/service/workflow"
  26. "dashoo.cn/opms_libary/micro_srv"
  27. "dashoo.cn/opms_libary/multipart"
  28. "dashoo.cn/opms_libary/myerrors"
  29. "dashoo.cn/opms_libary/plugin/dingtalk"
  30. "dashoo.cn/opms_libary/plugin/dingtalk/message"
  31. "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
  32. "dashoo.cn/opms_libary/request"
  33. "dashoo.cn/opms_libary/utils"
  34. "github.com/gogf/gf/database/gdb"
  35. "github.com/gogf/gf/frame/g"
  36. "github.com/gogf/gf/os/gcron"
  37. "github.com/gogf/gf/os/glog"
  38. "github.com/gogf/gf/os/gtime"
  39. "github.com/gogf/gf/util/gvalid"
  40. )
  41. type CtrContractService struct {
  42. Dao *dao.CtrContractDao
  43. ProjBusinessDao *projdao.ProjBusinessDao
  44. CustomerDao *custdao.CustCustomerDao
  45. CtrProductDao *dao.CtrContractProductDao
  46. ProductDao *basedao.BaseProductDao
  47. DynamicsDao *dao.CtrContractDynamicsDao
  48. WorkflowDao *workflowdao.PlatWorkflowDao
  49. AppendDao *dao.CtrContractAppendDao
  50. GoalDao *dao.CtrContractGoalDao
  51. Tenant string
  52. userInfo request.UserInfo
  53. DataScope g.Map `json:"dataScope"`
  54. }
  55. func NewCtrContractService(ctx context.Context) (*CtrContractService, error) {
  56. tenant, err := micro_srv.GetTenant(ctx)
  57. if err != nil {
  58. err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
  59. return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
  60. }
  61. // 获取用户信息
  62. userInfo, err := micro_srv.GetUserInfo(ctx)
  63. if err != nil {
  64. return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
  65. }
  66. return &CtrContractService{
  67. Dao: dao.NewCtrContractDao(tenant),
  68. ProjBusinessDao: projdao.NewProjBusinessDao(tenant),
  69. CustomerDao: custdao.NewCustCustomerDao(tenant),
  70. CtrProductDao: dao.NewCtrContractProductDao(tenant),
  71. ProductDao: basedao.NewBaseProductDao(tenant),
  72. DynamicsDao: dao.NewCtrContractDynamicsDao(tenant),
  73. WorkflowDao: workflowdao.NewPlatWorkflowDao(tenant),
  74. AppendDao: dao.NewCtrContractAppendDao(tenant),
  75. GoalDao: dao.NewCtrContractGoalDao(tenant),
  76. Tenant: tenant,
  77. userInfo: userInfo,
  78. DataScope: userInfo.DataScope,
  79. }, nil
  80. }
  81. func (s CtrContractService) Get(ctx context.Context, id int) (*model.CtrContractGetRsp, error) {
  82. ent, err := s.Dao.Where("Id = ?", id).One()
  83. if err != nil {
  84. return nil, err
  85. }
  86. if ent == nil {
  87. return nil, myerrors.TipsError("合同不存在")
  88. }
  89. product, err := s.CtrProductDao.Where("contract_id = ?", id).All()
  90. if err != nil {
  91. return nil, err
  92. }
  93. if product == nil {
  94. product = []*model.CtrContractProduct{}
  95. }
  96. return &model.CtrContractGetRsp{
  97. CtrContract: *ent,
  98. Product: product,
  99. }, nil
  100. }
  101. func (s CtrContractService) DynamicsList(ctx context.Context, req *model.CtrContractDynamicsListReq) (int, interface{}, error) {
  102. dao := &s.DynamicsDao.CtrContractDynamicsDao
  103. if req.SearchText != "" {
  104. likestr := fmt.Sprintf("%%%s%%", req.SearchText)
  105. dao = dao.Where("(opn_people LIKE ? || opn_content LIKE ?)", likestr, likestr)
  106. }
  107. if req.ContractId != 0 {
  108. dao = dao.Where("contract_id = ?", req.ContractId)
  109. }
  110. if req.OpnPeopleId != 0 {
  111. dao = dao.Where("opn_people_id = ?", req.OpnPeopleId)
  112. }
  113. if req.OpnPeople != "" {
  114. likestr := fmt.Sprintf("%%%s%%", req.OpnPeople)
  115. dao = dao.Where("opn_people like ?", likestr)
  116. }
  117. if req.OpnType != "" {
  118. dao = dao.Where("opn_type = ?", req.OpnType)
  119. }
  120. // if req.OpnContent != "" {
  121. // likestr := fmt.Sprintf("%%%s%%", req.OpnContent)
  122. // dao = dao.Where("opn_content like ?", likestr)
  123. // }
  124. if req.BeginTime != "" {
  125. dao = dao.Where("created_time > ?", req.BeginTime)
  126. }
  127. if req.EndTime != "" {
  128. dao = dao.Where("created_time < ?", req.EndTime)
  129. }
  130. total, err := dao.Count()
  131. if err != nil {
  132. return 0, nil, err
  133. }
  134. if req.PageNum != 0 {
  135. dao = dao.Page(req.GetPage())
  136. }
  137. orderby := "created_time desc"
  138. if req.OrderBy != "" {
  139. orderby = req.OrderBy
  140. }
  141. dao = dao.Order(orderby)
  142. ents := []*model.CtrContractDynamics{}
  143. err = dao.Structs(&ents)
  144. if err != nil && err != sql.ErrNoRows {
  145. return 0, nil, err
  146. }
  147. ret := map[string][]*model.CtrContractDynamics{}
  148. for _, ent := range ents {
  149. date := ent.OpnDate.Format("Y-m-d")
  150. ret[date] = append(ret[date], ent)
  151. }
  152. return total, ret, err
  153. }
  154. func (s CtrContractService) List(ctx context.Context, req *model.CtrContractListReq) (int, []*model.CtrContractListRsp, error) {
  155. ctx = context.WithValue(ctx, "contextService", s)
  156. dao := s.Dao.DataScope(ctx, "incharge_id").As("a")
  157. if req.SearchText != "" {
  158. likestr := fmt.Sprintf("%%%s%%", req.SearchText)
  159. dao = dao.Where("(a.contract_code LIKE ? || a.contract_name LIKE ? || a.cust_name LIKE ? || a.nbo_name LIKE ?)", likestr, likestr, likestr, likestr)
  160. }
  161. if req.ContractCode != "" {
  162. likestr := fmt.Sprintf("%%%s%%", req.ContractCode)
  163. dao = dao.Where("a.contract_code like ?", likestr)
  164. }
  165. if req.ContractName != "" {
  166. likestr := fmt.Sprintf("%%%s%%", req.ContractName)
  167. dao = dao.Where("a.contract_name like ?", likestr)
  168. }
  169. if req.CustId != 0 {
  170. dao = dao.Where("a.cust_id = ?", req.CustId)
  171. }
  172. if req.CustName != "" {
  173. likestr := fmt.Sprintf("%%%s%%", req.CustName)
  174. dao = dao.Where("a.cust_name like ?", likestr)
  175. }
  176. if req.NboId != 0 {
  177. dao = dao.Where("a.nbo_id = ?", req.NboId)
  178. }
  179. if req.NboName != "" {
  180. likestr := fmt.Sprintf("%%%s%%", req.NboName)
  181. dao = dao.Where("a.nbo_name like ?", likestr)
  182. }
  183. if req.ApproStatus != "" {
  184. dao = dao.Where("a.appro_status = ?", req.ApproStatus)
  185. }
  186. if req.ContractType != "" {
  187. dao = dao.Where("a.contract_type = ?", req.ContractType)
  188. }
  189. // if req.ContractStartTime != nil {
  190. // dao = dao.Where("a.contract_start_time > ?", req.ContractStartTime)
  191. // }
  192. // if req.ContractEndTime != nil {
  193. // dao = dao.Where("a.contract_end_time < ?", req.ContractEndTime)
  194. // }
  195. if req.InchargeId != 0 {
  196. dao = dao.Where("a.incharge_id = ?", req.InchargeId)
  197. }
  198. if req.InchargeName != "" {
  199. likestr := fmt.Sprintf("%%%s%%", req.InchargeName)
  200. dao = dao.Where("a.incharge_name like ?", likestr)
  201. }
  202. if req.SignatoryId != 0 {
  203. dao = dao.Where("a.signatory_id = ?", req.SignatoryId)
  204. }
  205. if req.SignatoryName != "" {
  206. likestr := fmt.Sprintf("%%%s%%", req.SignatoryName)
  207. dao = dao.Where("a.signatory_name like ?", likestr)
  208. }
  209. if req.DistributorId != 0 {
  210. dao = dao.Where("a.distributor_id = ?", req.DistributorId)
  211. }
  212. if req.DistributorName != "" {
  213. likestr := fmt.Sprintf("%%%s%%", req.DistributorName)
  214. dao = dao.Where("a.distributor_name like ?", likestr)
  215. }
  216. if req.BeginTime != "" {
  217. dao = dao.Where("a.created_time > ?", req.BeginTime)
  218. }
  219. if req.EndTime != "" {
  220. dao = dao.Where("a.created_time < ?", req.EndTime)
  221. }
  222. if req.ContractSignTimeStart != "" {
  223. dao = dao.Where("a.contract_sign_time >= ?", req.ContractSignTimeStart)
  224. }
  225. if req.ContractSignTimeEnd != "" {
  226. dao = dao.Where("a.contract_sign_time <= ?", req.ContractSignTimeEnd)
  227. }
  228. if req.CustProvinceId != 0 {
  229. dao = dao.Where("a.cust_province_id = ?", req.CustProvinceId)
  230. }
  231. if req.CustCityId != 0 {
  232. dao = dao.Where("a.cust_city_id = ?", req.CustCityId)
  233. }
  234. total, err := dao.Count()
  235. if err != nil {
  236. return 0, nil, err
  237. }
  238. if req.PageNum != 0 {
  239. dao = dao.Page(req.GetPage())
  240. }
  241. orderby := "a.contract_sign_time desc"
  242. if req.OrderBy != "" {
  243. orderby = req.OrderBy
  244. }
  245. dao = dao.Order(orderby)
  246. ents := []*model.CtrContractListRsp{}
  247. err = dao.Structs(&ents)
  248. if err != nil && err != sql.ErrNoRows {
  249. return 0, nil, err
  250. }
  251. return total, ents, err
  252. }
  253. func (s CtrContractService) BindProduct(tx *gdb.TX, id int, code string, product []model.CtrAddProduct) error {
  254. var amount float64
  255. for _, p := range product {
  256. amount += (p.TranPrice * float64(p.ProdNum))
  257. }
  258. _, err := tx.Delete("ctr_contract_product", "contract_id = ?", id)
  259. if err != nil {
  260. return err
  261. }
  262. tocreate := []model.CtrContractProduct{}
  263. for _, p := range product {
  264. product, err := s.ProductDao.Where("id = ?", p.ProdId).One()
  265. if err != nil {
  266. return err
  267. }
  268. if product == nil {
  269. return myerrors.TipsError(fmt.Sprintf("产品: %d 不存在", p.ProdId))
  270. }
  271. tocreate = append(tocreate, model.CtrContractProduct{
  272. ContractId: id,
  273. ContractCode: code,
  274. ProdId: p.ProdId,
  275. ProdCode: product.ProdCode,
  276. ProdName: product.ProdName,
  277. ProdClass: product.ProdClass,
  278. ProdNum: p.ProdNum,
  279. MaintTerm: p.MaintTerm,
  280. SugSalesPrice: p.SugSalesPrice,
  281. TranPrice: p.TranPrice,
  282. ContractPrive: amount,
  283. Remark: p.Remark,
  284. CreatedBy: int(s.userInfo.Id),
  285. CreatedName: s.userInfo.NickName,
  286. CreatedTime: gtime.Now(),
  287. UpdatedBy: int(s.userInfo.Id),
  288. UpdatedName: s.userInfo.NickName,
  289. UpdatedTime: gtime.Now(),
  290. })
  291. }
  292. if len(tocreate) != 0 {
  293. _, err = tx.Insert("ctr_contract_product", tocreate)
  294. if err != nil {
  295. return err
  296. }
  297. }
  298. return nil
  299. }
  300. func (s CtrContractService) AddDynamicsByCurrentUser(tx *gdb.TX, contractId int, opnType string, content map[string]interface{}) error {
  301. contentByte, err := json.Marshal(content)
  302. if err != nil {
  303. return err
  304. }
  305. _, err = tx.InsertAndGetId("ctr_contract_dynamics", model.CtrContractDynamics{
  306. ContractId: contractId,
  307. OpnPeopleId: s.userInfo.Id,
  308. OpnPeople: s.userInfo.NickName,
  309. OpnDate: gtime.Now(),
  310. OpnType: opnType,
  311. OpnContent: string(contentByte),
  312. Remark: "",
  313. CreatedBy: s.userInfo.Id,
  314. CreatedName: s.userInfo.NickName,
  315. CreatedTime: gtime.Now(),
  316. UpdatedBy: s.userInfo.Id,
  317. UpdatedName: s.userInfo.NickName,
  318. UpdatedTime: gtime.Now(),
  319. })
  320. return err
  321. }
  322. func (s CtrContractService) Add(ctx context.Context, req *model.CtrContractAddReq) (int, error) {
  323. validErr := gvalid.CheckStruct(ctx, req, nil)
  324. if validErr != nil {
  325. return 0, myerrors.TipsError(validErr.Current().Error())
  326. }
  327. if len(req.Product) == 0 {
  328. return 0, myerrors.TipsError("产品不能为空")
  329. }
  330. for _, p := range req.Product {
  331. if p.ProdNum < 1 {
  332. return 0, myerrors.TipsError("产品数量必须大于 0")
  333. }
  334. }
  335. c, err := s.Dao.Where("contract_name = ?", req.ContractName).One()
  336. if err != nil {
  337. return 0, err
  338. }
  339. if c != nil {
  340. return 0, myerrors.TipsError(fmt.Sprintf("合同名称:%s 已存在", req.ContractName))
  341. }
  342. nbo, err := s.ProjBusinessDao.Where("id = ?", req.NboId).One()
  343. if err != nil {
  344. return 0, err
  345. }
  346. if nbo == nil {
  347. return 0, myerrors.TipsError("项目不存在")
  348. }
  349. // c, err = s.Dao.Where("nbo_id = ?", req.NboId).One()
  350. // if err != nil {
  351. // return 0, err
  352. // }
  353. // if c != nil {
  354. // return 0, myerrors.TipsError("所选项目已添加合同")
  355. // }
  356. var sequence int
  357. if req.ContractType == "XS" { // 销售合同
  358. sequence, err = service.SequenceYearRest(s.Dao.DB, "contract_code_xs")
  359. if err != nil {
  360. return 0, err
  361. }
  362. } else if req.ContractType == "JS" { // 技术合同
  363. sequence, err = service.SequenceYearRest(s.Dao.DB, "contract_code_js")
  364. if err != nil {
  365. return 0, err
  366. }
  367. } else {
  368. return 0, myerrors.TipsError("不支持的合同类型")
  369. }
  370. if req.ContractCode == "" {
  371. req.ContractCode = fmt.Sprintf("DH%s%s-%03d", req.ContractType, time.Now().Format("0601"), sequence)
  372. }
  373. c, err = s.Dao.Where("contract_code = ?", req.ContractCode).One()
  374. if err != nil {
  375. return 0, err
  376. }
  377. if c != nil {
  378. return 0, myerrors.TipsError(fmt.Sprintf("合同编号:%s 已存在", req.ContractCode))
  379. }
  380. var contractAmount float64
  381. for _, p := range req.Product {
  382. contractAmount += (p.TranPrice * float64(p.ProdNum))
  383. }
  384. ctr := model.CtrContract{
  385. ContractCode: req.ContractCode,
  386. ContractName: req.ContractName,
  387. CustId: nbo.CustId,
  388. CustName: nbo.CustName,
  389. NboId: nbo.Id,
  390. NboName: nbo.NboName,
  391. IsBig: nbo.IsBig,
  392. ProductLine: nbo.ProductLine,
  393. CustProvinceId: nbo.CustProvinceId,
  394. CustProvince: nbo.CustProvince,
  395. CustCityId: nbo.CustCityId,
  396. CustCity: nbo.CustCity,
  397. ApproStatus: "10",
  398. ContractType: req.ContractType,
  399. ContractAmount: contractAmount,
  400. InvoiceAmount: 0,
  401. CollectedAmount: 0,
  402. ContractStartTime: req.ContractStartTime,
  403. ContractEndTime: req.ContractEndTime,
  404. ContractSignTime: req.ContractSignTime,
  405. InchargeId: req.InchargeId,
  406. InchargeName: req.InchargeName,
  407. SignatoryId: req.SignatoryId,
  408. SignatoryName: req.SignatoryName,
  409. SignatoryType: req.SignatoryType,
  410. SignatoryUnit: req.SignatoryUnit,
  411. EarnestMoney: req.EarnestMoney,
  412. CustSignatoryId: req.CustSignatoryId,
  413. CustSignatoryName: req.CustSignatoryName,
  414. DistributorId: req.DistributorId,
  415. DistributorName: req.DistributorName,
  416. Remark: req.Remark,
  417. ServiceFeeAgreement: req.ServiceFeeAgreement,
  418. CreatedBy: int(s.userInfo.Id),
  419. CreatedName: s.userInfo.NickName,
  420. CreatedTime: gtime.Now(),
  421. UpdatedBy: int(s.userInfo.Id),
  422. UpdatedName: s.userInfo.NickName,
  423. UpdatedTime: gtime.Now(),
  424. }
  425. var id int
  426. txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  427. ctrid, err := tx.InsertAndGetId("ctr_contract", ctr)
  428. if err != nil {
  429. return err
  430. }
  431. err = s.BindProduct(tx, int(ctrid), ctr.ContractCode, req.Product)
  432. if err != nil {
  433. return err
  434. }
  435. err = s.AddDynamicsByCurrentUser(tx, int(ctrid), "创建合同", map[string]interface{}{})
  436. if err != nil {
  437. return err
  438. }
  439. _, err = tx.Update("proj_business", map[string]interface{}{
  440. "nbo_type": projsrv.StatusDeal,
  441. }, "id = ?", nbo.Id)
  442. if err != nil {
  443. return err
  444. }
  445. id = int(ctrid)
  446. return nil
  447. })
  448. return id, txerr
  449. }
  450. var ContractApplyProcessCode = "PROC-7057E20A-2066-4644-9B35-9331E4DA912C" // 创建合同
  451. func (s CtrContractService) Commit(ctx context.Context, req *model.CtrContractCommitReq) (int64, error) {
  452. validErr := gvalid.CheckStruct(ctx, req, nil)
  453. if validErr != nil {
  454. return 0, myerrors.TipsError(validErr.Current().Error())
  455. }
  456. if !(req.ContractModel == "大数模板" || req.ContractModel == "客户模板") {
  457. return 0, myerrors.TipsError("合同模板不合法")
  458. }
  459. if !(req.Terms == "接纳全部条款" || req.Terms == "不接纳全部条款") {
  460. return 0, myerrors.TipsError("条款情况不合法")
  461. }
  462. if req.PayTerms == "" {
  463. return 0, myerrors.TipsError("付款条件不能为空")
  464. }
  465. if len(req.File) == 0 {
  466. return 0, myerrors.TipsError("附件不能为空")
  467. }
  468. ent, err := s.Dao.Where("id = ?", req.Id).One()
  469. if err != nil {
  470. return 0, err
  471. }
  472. if ent == nil {
  473. return 0, myerrors.TipsError(fmt.Sprintf("合同不存在: %d", req.Id))
  474. }
  475. fileinfoByte, err := json.Marshal(req.File)
  476. if err != nil {
  477. return 0, err
  478. }
  479. workflowSrv, err := workflowService.NewFlowService(ctx)
  480. if err != nil {
  481. return 0, err
  482. }
  483. bizCode := strconv.Itoa(ent.Id)
  484. workflowId, err := workflowSrv.StartProcessInstance(bizCode, "30", "", &workflow.StartProcessInstanceRequest{
  485. ProcessCode: &ContractApplyProcessCode,
  486. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  487. {
  488. Id: utils.String("DDSelectField_ESX8H30W3VK0"),
  489. Name: utils.String("合同模板"),
  490. Value: utils.String(req.ContractModel),
  491. },
  492. {
  493. Id: utils.String("DDSelectField_13IQX96C2KAK0"),
  494. Name: utils.String("条款情况"),
  495. Value: utils.String(req.Terms),
  496. },
  497. {
  498. Id: utils.String("TextField_1A5SA7VOG5TS0"),
  499. Name: utils.String("合同编号"),
  500. Value: utils.String(ent.ContractCode),
  501. },
  502. {
  503. Id: utils.String("TextField_1EX61DPS3LA80"),
  504. Name: utils.String("客户名称"),
  505. Value: utils.String(ent.CustName),
  506. },
  507. {
  508. Id: utils.String("MoneyField_X1XV4KIR0GW0"),
  509. Name: utils.String("合同金额(元)"),
  510. Value: utils.String(strconv.FormatFloat(ent.ContractAmount, 'f', 2, 64)),
  511. },
  512. {
  513. Id: utils.String("TextareaField_1WZ5ILKBUVSW0"),
  514. Name: utils.String("付款条件"),
  515. Value: utils.String(req.PayTerms),
  516. },
  517. {
  518. Id: utils.String("DDAttachment_1051KJYC3MBK0"),
  519. Name: utils.String("附件"),
  520. // Details: productForm,
  521. Value: utils.String(string(fileinfoByte)),
  522. },
  523. },
  524. })
  525. if err != nil {
  526. return 0, err
  527. }
  528. _, err = s.Dao.Where("id = ?", ent.Id).Data(map[string]interface{}{
  529. "appro_status": 20,
  530. }).Update()
  531. return workflowId, err
  532. }
  533. // var spaceId = "21042518430"
  534. var spaceId = "21077726250"
  535. func (s CtrContractService) CommitWithFile(ctx context.Context, formData *multipart.Form) error {
  536. if s.userInfo.DingtalkUid == "" {
  537. return fmt.Errorf("该用户钉钉 uid 为空")
  538. }
  539. if len(formData.File) == 0 {
  540. return myerrors.TipsError("文件不能为空")
  541. }
  542. if _, ok := formData.File["file"]; !ok {
  543. return myerrors.TipsError("文件不能为空")
  544. }
  545. if formData.File["file"].FileName == "" {
  546. return fmt.Errorf("文件名称不能为空")
  547. }
  548. if formData.File["file"].File == nil {
  549. return fmt.Errorf("文件不能为空")
  550. }
  551. if formData.File["file"].File.Name() == "" {
  552. return fmt.Errorf("文件路径不能为空")
  553. }
  554. contractId, err := strconv.Atoi(formData.Value["contractId"])
  555. if err != nil {
  556. return fmt.Errorf("合同 Id 不合法 %s", formData.Value["contractId"])
  557. }
  558. //fmt.Println(args.File.Name(), args.FileName, args.FileSize, args.Meta)
  559. //fmt.Println(spaceId, s.userInfo.DingtalkId, args.FileName, args.File.Name())
  560. // resp, err := s.UploadFile("21042518430", "8xljy04PZiS9iPxp5PhDnUzQiEiE", "引物导入模板-000000.xlsx", "/Users/chengjian/Downloads/引物导入模板.xlsx")
  561. resp, err := dingtalk.Client.GetStorage().UploadFile(spaceId, s.userInfo.DingtalkId, formData.File["file"].FileName, formData.File["file"].File.Name())
  562. if err != nil {
  563. return fmt.Errorf("钉钉上传文件异常 %s", err.Error())
  564. }
  565. _, err = s.Commit(ctx, &model.CtrContractCommitReq{
  566. Id: contractId,
  567. ContractModel: formData.Value["contractModel"],
  568. Terms: formData.Value["terms"],
  569. PayTerms: formData.Value["payTerms"],
  570. File: []model.DingFileInfo{
  571. {
  572. SpaceId: resp.Dentry.SpaceId,
  573. FileId: resp.Dentry.Id,
  574. FileName: resp.Dentry.Name,
  575. FileSize: resp.Dentry.Size,
  576. FileType: resp.Dentry.Extension,
  577. },
  578. },
  579. })
  580. if err != nil {
  581. return err
  582. }
  583. // workflow, err := s.WorkflowDao.Where("id = ?", workflowId).One()
  584. // if err != nil {
  585. // return err
  586. // }
  587. // instance, err := dingtalk.Client.GetWorkflow().QueryProcessInstanceDetail(workflow.ProcessInstId)
  588. // if err != nil {
  589. // return fmt.Errorf("查询审批实例详情错误: %s", err.Error())
  590. // }
  591. // fmt.Println(workflow.ProcessInstId, instance.Result.ApproverUserIds)
  592. // approverUserIds := g.Config().GetStrings("dingtalk.approver-user-ids")
  593. // fmt.Println(approverUserIds)
  594. // for _, uid := range approverUserIds {
  595. // resp, err := dingtalk.Client.GetStorage().AddPermission(
  596. // dingtalk.Client.Context.CorpId, spaceId, uid, "DOWNLOADER", "USER")
  597. // if err != nil {
  598. // return fmt.Errorf("添加审核附件权限异常: %s", err.Error())
  599. // }
  600. // fmt.Println(uid, resp)
  601. // }
  602. appendSrv, err := NewCtrContractAppendService(ctx)
  603. if err != nil {
  604. return err
  605. }
  606. _, err = appendSrv.Add(ctx, &model.CtrContractAppendAddReq{
  607. ContractId: contractId,
  608. FileName: resp.Dentry.Name,
  609. FileType: resp.Dentry.Extension,
  610. FileUrl: strings.Join([]string{"dingtalk", resp.Dentry.SpaceId, resp.Dentry.Id}, ":"),
  611. Remark: "",
  612. })
  613. if err != nil {
  614. return err
  615. }
  616. return nil
  617. }
  618. func (s CtrContractService) CommitWithFileUrl(ctx context.Context, req *model.CtrContractCommitWithFileUrlReq) error {
  619. validErr := gvalid.CheckStruct(ctx, req, nil)
  620. if validErr != nil {
  621. return myerrors.TipsError(validErr.Current().Error())
  622. }
  623. fileinfoByte, err := baseService.UploadDingtalk(s.userInfo.DingtalkId, req.FileUrl, req.FileName)
  624. if err != nil {
  625. return err
  626. }
  627. var fileinfo = []model.DingFileInfo{}
  628. err = json.Unmarshal(fileinfoByte, &fileinfo)
  629. if err != nil {
  630. return err
  631. }
  632. _, err = s.Commit(ctx, &model.CtrContractCommitReq{
  633. Id: req.Id,
  634. ContractModel: req.ContractModel,
  635. Terms: req.Terms,
  636. PayTerms: req.PayTerms,
  637. File: fileinfo,
  638. })
  639. if err != nil {
  640. return err
  641. }
  642. appendSrv, err := NewCtrContractAppendService(ctx)
  643. if err != nil {
  644. return err
  645. }
  646. _, err = appendSrv.Add(ctx, &model.CtrContractAppendAddReq{
  647. ContractId: req.Id,
  648. FileName: fileinfo[0].FileName,
  649. FileType: fileinfo[0].FileType,
  650. FileUrl: strings.Join([]string{"dingtalk", fileinfo[0].SpaceId, fileinfo[0].FileId}, ":"),
  651. Remark: "",
  652. })
  653. if err != nil {
  654. return err
  655. }
  656. return nil
  657. }
  658. func (s CtrContractService) DownloadDingtalkFile(ctx context.Context, id int) (string, error) {
  659. ent, err := s.AppendDao.Where("id= ?", id).One()
  660. if err != nil {
  661. return "", err
  662. }
  663. if ent == nil {
  664. return "", myerrors.TipsError("附件不存在")
  665. }
  666. if !strings.HasPrefix(ent.FileUrl, "dingtalk") {
  667. return "", myerrors.TipsError("此附件不是钉钉附件")
  668. }
  669. fileInfo := strings.Split(ent.FileUrl, ":")
  670. if len(fileInfo) != 3 {
  671. return "", myerrors.TipsError("钉钉附件地址不合法")
  672. }
  673. spaceId := fileInfo[1]
  674. fileId := fileInfo[2]
  675. // res, err := dingtalk.Client.GetStorage().AddPermission(dingtalk.Client.Context.CorpId, spaceId, s.userInfo.DingtalkId, "EDITOR", "USER")
  676. // fmt.Println(res, err)
  677. // if err != nil {
  678. // return "", fmt.Errorf("设置权限异常 %s", err.Error())
  679. // }
  680. resp, err := dingtalk.Client.GetStorage().QueryFileDownloadInfo(spaceId, fileId, s.userInfo.DingtalkId)
  681. if err != nil {
  682. return "", myerrors.TipsError("获取文件下载信息异常")
  683. }
  684. fmt.Println(resp, err)
  685. req, err := http.NewRequest("GET", resp.HeaderSignatureInfo.ResourceUrls[0], nil)
  686. if err != nil {
  687. return "", fmt.Errorf("构建文件下载请求异常 %s", err.Error())
  688. }
  689. for k, v := range resp.HeaderSignatureInfo.Headers {
  690. req.Header.Add(k, v)
  691. }
  692. fileresp, err := http.DefaultClient.Do(req)
  693. if err != nil {
  694. return "", fmt.Errorf("文件下载异常 %s", err.Error())
  695. }
  696. data, err := io.ReadAll(fileresp.Body)
  697. if err != nil {
  698. return "", fmt.Errorf("读取下载内容异常 %s", err.Error())
  699. }
  700. return base64.StdEncoding.EncodeToString(data), nil
  701. }
  702. func ContractApplyApproval(ctx context.Context, flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
  703. tenant, err := micro_srv.GetTenant(ctx)
  704. if err != nil {
  705. return fmt.Errorf("获取租户码异常:%s", err.Error())
  706. }
  707. contractDao := dao.NewCtrContractDao(tenant)
  708. contractId, err := strconv.Atoi(flow.BizCode)
  709. if err != nil {
  710. return fmt.Errorf("创建合同审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
  711. }
  712. contract, err := contractDao.Where("id = ?", contractId).One()
  713. if err != nil {
  714. return err
  715. }
  716. if contract == nil {
  717. return fmt.Errorf("合同不存在:%s Id: %d", flow.BizCode, flow.Id)
  718. }
  719. if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
  720. return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
  721. }
  722. if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
  723. return fmt.Errorf("无法识别的 Result :%s", msg.Result)
  724. }
  725. var status string
  726. if msg.ProcessType == "terminate" {
  727. status = "50"
  728. } else {
  729. pass := msg.Result == "agree"
  730. if !pass {
  731. status = "40"
  732. } else {
  733. status = "30"
  734. }
  735. }
  736. _, err = contractDao.Where("id = ?", contractId).Data(map[string]interface{}{
  737. "appro_status": status,
  738. }).Update()
  739. if err != nil {
  740. return err
  741. }
  742. if status != "30" {
  743. return nil
  744. }
  745. return contractDao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  746. _, err = worksrv.DeliverOrderAdd(tx, contractId, request.UserInfo{})
  747. return err
  748. })
  749. }
  750. func (s CtrContractService) Update(ctx context.Context, req *model.CtrContractUpdateReq) error {
  751. validErr := gvalid.CheckStruct(ctx, req, nil)
  752. if validErr != nil {
  753. return myerrors.TipsError(validErr.Current().Error())
  754. }
  755. ent, err := s.Dao.Where("id = ?", req.Id).One()
  756. if err != nil {
  757. return err
  758. }
  759. if ent == nil {
  760. return myerrors.TipsError(fmt.Sprintf("合同不存在: %d", req.Id))
  761. }
  762. // if req.ContractCode != "" {
  763. // exist, err := s.Dao.Where("contract_code = ?", req.ContractCode).One()
  764. // if err != nil {
  765. // return err
  766. // }
  767. // if exist != nil && exist.Id != req.Id {
  768. // return myerrors.NewMsgError(nil, fmt.Sprintf("合同编号:%s 已存在", req.ContractCode))
  769. // }
  770. // }
  771. if req.ContractName != "" {
  772. exist, err := s.Dao.Where("contract_name = ?", req.ContractName).One()
  773. if err != nil {
  774. return err
  775. }
  776. if exist != nil && exist.Id != req.Id {
  777. return myerrors.TipsError(fmt.Sprintf("合同名称:%s 已存在", req.ContractName))
  778. }
  779. }
  780. var nbo *proj.ProjBusiness
  781. if req.NboId != 0 {
  782. nbo, err = s.ProjBusinessDao.Where("id = ?", req.NboId).One()
  783. if err != nil {
  784. return err
  785. }
  786. if nbo == nil {
  787. return myerrors.TipsError("项目不存在")
  788. }
  789. }
  790. toupdate := map[string]interface{}{}
  791. // if req.ContractCode != "" {
  792. // toupdate["contract_code"] = req.ContractCode
  793. // }
  794. if req.ContractName != "" {
  795. toupdate["contract_name"] = req.ContractName
  796. }
  797. if req.NboId != 0 {
  798. toupdate["cust_id"] = nbo.CustId
  799. toupdate["cust_name"] = nbo.CustName
  800. toupdate["nbo_id"] = nbo.Id
  801. toupdate["nbo_name"] = nbo.NboName
  802. toupdate["is_big"] = nbo.IsBig
  803. toupdate["product_line"] = nbo.ProductLine
  804. toupdate["cust_province_id"] = nbo.CustProvinceId
  805. toupdate["cust_province"] = nbo.CustProvince
  806. toupdate["cust_city_id"] = nbo.CustCityId
  807. toupdate["cust_city"] = nbo.CustCity
  808. }
  809. // if req.ApproStatus != "" {
  810. // toupdate["appro_status"] = req.ApproStatus
  811. // }
  812. if req.ContractType != "" {
  813. toupdate["contract_type"] = req.ContractType
  814. }
  815. // if req.ContractAmount != 0 {
  816. // toupdate["contract_amount"] = req.ContractAmount
  817. // }
  818. // if req.InvoiceAmount != 0 {
  819. // toupdate["invoice_amount"] = req.InvoiceAmount
  820. // }
  821. // if req.CollectedAmount != 0 {
  822. // toupdate["collected_amount"] = req.CollectedAmount
  823. // }
  824. if req.ContractStartTime != nil {
  825. toupdate["contract_start_time"] = req.ContractStartTime
  826. }
  827. if req.ContractEndTime != nil {
  828. toupdate["contract_end_time"] = req.ContractEndTime
  829. }
  830. if req.ContractSignTime != nil {
  831. toupdate["contract_sign_time"] = req.ContractSignTime
  832. }
  833. //if req.InchargeId != 0 {
  834. // toupdate["incharge_id"] = req.InchargeId
  835. //}
  836. //if req.InchargeName != "" {
  837. // toupdate["incharge_name"] = req.InchargeName
  838. //}
  839. if req.SignatoryId != 0 {
  840. toupdate["signatory_id"] = req.SignatoryId
  841. }
  842. if req.SignatoryName != "" {
  843. toupdate["signatory_name"] = req.SignatoryName
  844. }
  845. if req.SignatoryType != "" {
  846. toupdate["signatory_type"] = req.SignatoryType
  847. }
  848. if req.SignatoryUnit != "" {
  849. toupdate["signatory_unit"] = req.SignatoryUnit
  850. }
  851. if req.EarnestMoney != nil {
  852. toupdate["earnest_money"] = req.EarnestMoney
  853. }
  854. if req.CustSignatoryId != 0 {
  855. toupdate["cust_signatory_id"] = req.CustSignatoryId
  856. }
  857. if req.CustSignatoryName != "" {
  858. toupdate["cust_signatory_name"] = req.CustSignatoryName
  859. }
  860. if req.DistributorId != 0 {
  861. toupdate["distributor_id"] = req.DistributorId
  862. }
  863. if req.DistributorName != "" {
  864. toupdate["distributor_name"] = req.DistributorName
  865. }
  866. if req.Remark != nil {
  867. toupdate["remark"] = *req.Remark
  868. }
  869. if req.Product != nil {
  870. var contractAmount float64
  871. for _, p := range *req.Product {
  872. contractAmount += (p.TranPrice * float64(p.ProdNum))
  873. }
  874. toupdate["contract_amount"] = contractAmount
  875. }
  876. if len(toupdate) != 0 {
  877. toupdate["updated_by"] = int(s.userInfo.Id)
  878. toupdate["updated_name"] = s.userInfo.NickName
  879. toupdate["updated_time"] = gtime.Now()
  880. txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  881. _, err = tx.Update("ctr_contract", toupdate, "id = ?", req.Id)
  882. if err != nil {
  883. return err
  884. }
  885. if req.Product != nil {
  886. err = s.BindProduct(tx, req.Id, ent.ContractCode, *req.Product)
  887. if err != nil {
  888. return err
  889. }
  890. }
  891. return nil
  892. })
  893. if txerr != nil {
  894. return txerr
  895. }
  896. }
  897. return nil
  898. }
  899. func (s CtrContractService) UpdateProduct(ctx context.Context, req *model.CtrContractUpdateProductReq) error {
  900. validErr := gvalid.CheckStruct(ctx, req, nil)
  901. if validErr != nil {
  902. return myerrors.TipsError(validErr.Current().Error())
  903. }
  904. ent, err := s.CtrProductDao.Where("id = ?", req.Id).One()
  905. if err != nil {
  906. return err
  907. }
  908. if ent == nil {
  909. return myerrors.TipsError(fmt.Sprintf("合同产品记录不存在: %d", req.Id))
  910. }
  911. toupdate := map[string]interface{}{}
  912. if req.MaintainPeriod != nil {
  913. toupdate["maintain_period"] = req.MaintainPeriod
  914. }
  915. if req.WarrantPeriod != nil {
  916. toupdate["warrant_period"] = req.WarrantPeriod
  917. }
  918. if req.MaintainStartTime != nil {
  919. toupdate["maintain_start_time"] = req.MaintainStartTime
  920. }
  921. if req.MaintainRemark != nil {
  922. toupdate["maintain_remark"] = req.MaintainRemark
  923. }
  924. if req.AcceptTime != nil {
  925. toupdate["accept_time"] = req.AcceptTime
  926. }
  927. if req.PurchaseCost != nil {
  928. toupdate["purchase_cost"] = req.PurchaseCost
  929. }
  930. if req.DevCost != nil {
  931. toupdate["dev_cost"] = req.DevCost
  932. }
  933. if req.MaintainCost != nil {
  934. toupdate["maintain_cost"] = req.MaintainCost
  935. }
  936. if req.DirectCost != nil {
  937. toupdate["direct_cost"] = req.DirectCost
  938. }
  939. if len(toupdate) != 0 {
  940. toupdate["updated_by"] = int(s.userInfo.Id)
  941. toupdate["updated_name"] = s.userInfo.NickName
  942. toupdate["updated_time"] = gtime.Now()
  943. txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  944. _, err = tx.Update("ctr_contract_product", toupdate, "id = ?", req.Id)
  945. if err != nil {
  946. return err
  947. }
  948. err = s.AddDynamicsByCurrentUser(tx, ent.ContractId, "更新合同产品信息", toupdate)
  949. if err != nil {
  950. return err
  951. }
  952. return nil
  953. })
  954. if txerr != nil {
  955. return txerr
  956. }
  957. }
  958. return nil
  959. }
  960. func (s CtrContractService) Transfer(ctx context.Context, req *model.CtrContractTransferReq) error {
  961. if len(req.Id) == 0 {
  962. return nil
  963. }
  964. ents := map[int]*model.CtrContract{}
  965. for _, i := range req.Id {
  966. ent, err := s.Dao.Where("id = ?", i).One()
  967. if err != nil {
  968. return err
  969. }
  970. if ent == nil {
  971. return myerrors.TipsError(fmt.Sprintf("合同不存在: %d", req.Id))
  972. }
  973. ents[ent.Id] = ent
  974. }
  975. txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  976. toupdate := map[string]interface{}{
  977. "incharge_id": req.InchargeId,
  978. "incharge_name": req.InchargeName,
  979. }
  980. _, err := tx.Update("ctr_contract", toupdate, "id in (?)", req.Id)
  981. if err != nil {
  982. return err
  983. }
  984. for _, ent := range ents {
  985. err = s.AddDynamicsByCurrentUser(tx, ent.Id, "转移合同", map[string]interface{}{
  986. "toInchargeId": req.InchargeId,
  987. "toInchargeName": req.InchargeName,
  988. "fromInchargeId": ent.InchargeId,
  989. "fromInchargeName": ent.InchargeName,
  990. "operatedId": s.userInfo.Id,
  991. "operatedName": s.userInfo.NickName,
  992. })
  993. if err != nil {
  994. return err
  995. }
  996. }
  997. return nil
  998. })
  999. if txerr != nil {
  1000. return txerr
  1001. }
  1002. return nil
  1003. }
  1004. func (s CtrContractService) UpdateInvoiceAmount(tx *gdb.TX, id int) error {
  1005. ctr := model.CtrContract{}
  1006. err := tx.GetStruct(&ctr, "select * from ctr_contract where id = ?", id)
  1007. if err == sql.ErrNoRows {
  1008. return myerrors.TipsError(fmt.Sprintf("合同不存在 %d", id))
  1009. }
  1010. if err != nil {
  1011. return err
  1012. }
  1013. v, err := tx.GetValue("select sum(invoice_amount) from ctr_contract_invoice where contract_id=? and appro_status='30' and deleted_time is null", id)
  1014. if err != nil {
  1015. return err
  1016. }
  1017. amount := v.Float64()
  1018. _, err = tx.Update("ctr_contract",
  1019. map[string]interface{}{
  1020. "invoice_amount": amount,
  1021. }, "id = ?", id)
  1022. if err != nil {
  1023. return err
  1024. }
  1025. return nil
  1026. }
  1027. func (s CtrContractService) UpdateCollectedAmount(tx *gdb.TX, id int) error {
  1028. ctr := model.CtrContract{}
  1029. err := tx.GetStruct(&ctr, "select * from ctr_contract where id = ?", id)
  1030. if err == sql.ErrNoRows {
  1031. return myerrors.TipsError(fmt.Sprintf("合同不存在 %d", id))
  1032. }
  1033. if err != nil {
  1034. return err
  1035. }
  1036. v, err := tx.GetValue("select sum(collection_amount) from ctr_contract_collection where contract_id=? and appro_status='20' and deleted_time is null", id)
  1037. if err != nil {
  1038. return err
  1039. }
  1040. amount := v.Float64()
  1041. _, err = tx.Update("ctr_contract",
  1042. map[string]interface{}{
  1043. "collected_amount": amount,
  1044. }, "id = ?", id)
  1045. if err != nil {
  1046. return err
  1047. }
  1048. return nil
  1049. }
  1050. func (s CtrContractService) Delete(ctx context.Context, id []int) error {
  1051. if len(id) == 0 {
  1052. return nil
  1053. }
  1054. _, err := s.Dao.Where("Id IN (?)", id).Delete()
  1055. return err
  1056. }
  1057. func init() {
  1058. tenant := g.Config().GetString("micro_srv.tenant")
  1059. if tenant == "" {
  1060. panic("定时任务租户码未设置,请前往配置")
  1061. }
  1062. contractDao := dao.NewCtrContractDao(tenant)
  1063. produceDao := dao.NewCtrContractProductDao(tenant)
  1064. job := func() {
  1065. alert := map[int]*[]model.CtrContractProduct{
  1066. 180: {},
  1067. 90: {},
  1068. 30: {},
  1069. 10: {},
  1070. // 7: {},
  1071. }
  1072. where := `DATE_FORMAT(DATE_ADD(maintain_start_time, INTERVAL ? day), "%Y-%m-%d") = DATE_FORMAT(NOW(), "%Y-%m-%d")`
  1073. for day, p := range alert {
  1074. err := produceDao.Where(where, day).Structs(p)
  1075. if err != nil {
  1076. glog.Error(err)
  1077. }
  1078. glog.Infof("运维期到期 %d 天提醒,产品个数 %d", day, len(*p))
  1079. }
  1080. for day, p := range alert {
  1081. for _, i := range *p {
  1082. ctr, err := contractDao.Where("id = ?", i.ContractId).One()
  1083. if err != nil {
  1084. glog.Error(err)
  1085. }
  1086. text := fmt.Sprintf("合同:%s-%s 中的产品:%s 距离运维到期还有 %d 天",
  1087. ctr.ContractCode, ctr.ContractName, i.ProdName, day)
  1088. msg := g.MapStrStr{
  1089. "msgTitle": "运维期到期提醒",
  1090. "msgContent": text,
  1091. "msgType": "20",
  1092. "recvUserIds": strconv.Itoa(ctr.InchargeId),
  1093. "msgStatus": "10",
  1094. "sendType": "10",
  1095. }
  1096. if err := service.CreateSystemMessage(msg); err != nil {
  1097. glog.Error("消息提醒异常:", err)
  1098. }
  1099. glog.Infof("%s", text)
  1100. }
  1101. }
  1102. }
  1103. // 每天凌晨2点执行
  1104. gcron.AddSingleton("0 0 2 * * *", job)
  1105. // job()
  1106. }