network.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package service
  2. import (
  3. "database/sql"
  4. "strings"
  5. . "app.yhyue.com/moapp/jybase/date"
  6. . "bp.jydev.jianyu360.cn/CRM/application/api/common"
  7. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  8. )
  9. var VarNetwork = &Network{}
  10. type Network struct {
  11. }
  12. //人脉库-添加/修改人脉
  13. func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
  14. reply := &types.Reply{}
  15. itype := 0
  16. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  17. switch in.Type {
  18. case "firstparty":
  19. itype = 1
  20. case "supplier:供应商":
  21. itype = 2
  22. case "adiffb":
  23. itype = 3
  24. case "middleman":
  25. itype = 4
  26. case "agency":
  27. itype = 5
  28. }
  29. nowFormat := NowFormat(Date_Full_Layout)
  30. var getValues = func(cid int64) []interface{} {
  31. values := []interface{}{}
  32. if in.Introduce_owner_id != "" {
  33. for k, v := range strings.Split(in.Introduce_owner_id, ",") {
  34. values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, strings.Split(in.Introduce_owner_name, ",")[k], 1, nowFormat)
  35. }
  36. }
  37. if in.Introduce_project_id != "" {
  38. for k, v := range strings.Split(in.Introduce_project_id, ",") {
  39. values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, strings.Split(in.Introduce_project_name, ",")[k], 1, nowFormat)
  40. }
  41. }
  42. return values
  43. }
  44. if in.Id > 0 {
  45. if CrmMysql.ExecTx("更新人脉", func(tx *sql.Tx) bool {
  46. r1 := CrmMysql.UpdateOrDeleteBySqlByTx(`update connection set company_name=?,company_id=?,contact_person=?,contact_phone=?,update_time=? where id=? and position_id=?`, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, nowFormat, in.Id, in.PositionId)
  47. r2 := CrmMysql.UpdateOrDeleteBySqlByTx(`delete from connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
  48. var r3 int64
  49. if len(values) > 0 {
  50. _, r3 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"connection_id", "relate_id", "relate_name", "itype", "create_time"}, getValues(r1))
  51. }
  52. return r1 > 0 && r2 >= 0 && r3 >= 0
  53. }) {
  54. reply.Data = map[string]interface{}{
  55. "status": 1,
  56. }
  57. } else {
  58. reply.Data = map[string]interface{}{
  59. "status": 0,
  60. }
  61. }
  62. } else {
  63. id := 0
  64. if CrmMysql.ExecTx("新增人脉", func(tx *sql.Tx) bool {
  65. _, r1 := CrmMysql.InsertBatchByTx(tx, "connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "position_id", "contact_name", "contact_phone", "status", "create_time", "update_time"}, []interface{}{in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, itype, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, 1, nowFormat, nowFormat})
  66. var r2 int64
  67. if len(values) > 0 {
  68. _, r2 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
  69. }
  70. return r1 > 0 && r2 >= 0
  71. }) {
  72. reply.Data = map[string]interface{}{
  73. "status": 1,
  74. "id": id,
  75. }
  76. } else {
  77. reply.Data = map[string]interface{}{
  78. "status": 0,
  79. }
  80. }
  81. }
  82. return reply
  83. }
  84. //人脉库-业主名称联想
  85. func (n *Network) Associate(in *types.AssociateReq) *types.Reply {
  86. return nil
  87. }
  88. //人脉库-全部人脉项目
  89. func (n *Network) Allproject(in *types.AllprojectReq) *types.Reply {
  90. return nil
  91. }
  92. //人脉库-列表
  93. func (n *Network) List(in *types.NetWorkListReq) *types.Reply {
  94. return nil
  95. }