company.go 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/company_user"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services/alarm_msg"
  12. "hongze/hz_crm_api/utils"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // AddCompanyPermission 新增客户权限
  18. func AddCompanyPermission(companyId, sysUserId, productId int, productName, sysUserName, permissionStr, startDate, endDate string) (companyReportPermissionList []*company.CompanyReportPermission, err error) {
  19. if permissionStr == "" {
  20. return
  21. }
  22. permissionArr := strings.Split(permissionStr, ",")
  23. count, _ := company.GetCompanyReportPermissionCount(companyId, productId)
  24. //删除权限
  25. if count > 0 {
  26. err = company.DeleteCompanyReportPermission(companyId, productId)
  27. if err != nil {
  28. return
  29. }
  30. }
  31. //如果是ficc类型的客户,且权限列表中没有 宏观权限,那么需要默认将宏观加进去
  32. if productId == utils.COMPANY_PRODUCT_FICC_ID && !utils.InArrayByStr(permissionArr, "1") {
  33. permissionArr = append(permissionArr, "1")
  34. }
  35. for _, pv := range permissionArr {
  36. permissionId, tmpErr := strconv.Atoi(pv)
  37. if productId == utils.COMPANY_PRODUCT_RAI_ID && permissionId == 1 {
  38. continue
  39. }
  40. if tmpErr != nil {
  41. err = tmpErr
  42. return
  43. }
  44. permission := new(company.CompanyReportPermission)
  45. permission.CompanyId = companyId
  46. permission.ReportPermissionId = permissionId
  47. permission.CreatedTime = time.Now()
  48. permission.LastUpdatedTime = time.Now()
  49. permission.ChartPermissionId = permissionId
  50. permission.StartDate = startDate
  51. permission.EndDate = endDate
  52. permission.ProductId = productId
  53. permission.ProductName = productName
  54. permission.ModifyTime = time.Now()
  55. permission.Status = "试用"
  56. err = company.AddCompanyReportPermission(permission)
  57. if err != nil {
  58. return
  59. }
  60. companyReportPermissionList = append(companyReportPermissionList, permission)
  61. cpLog := new(company.CompanyPermissionLog)
  62. cpLog.CompanyId = companyId
  63. cpLog.ChartPermissionId = permissionId
  64. cpLog.CreateTime = time.Now()
  65. cpLog.SysUserId = sysUserId
  66. cpLog.SysUserName = sysUserName
  67. cpLog.StartDate = startDate
  68. cpLog.EndDate = endDate
  69. cpLog.ProductId = productId
  70. cpLog.ProductName = productName
  71. go company.AddCompanyPermissionLog(cpLog)
  72. }
  73. return
  74. }
  75. func AddCompanyProductLog(companyProduct *company.CompanyProduct, adminId int, logType string) (err error) {
  76. defer func() {
  77. if err != nil {
  78. go alarm_msg.SendAlarmMsg("services:AddCompanyProductLog;Err:"+err.Error(), 3)
  79. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyProductLog;Err:"+err.Error(), utils.EmailSendToUsers)
  80. }
  81. }()
  82. productLog := new(company.CompanyProductLog)
  83. productLog.CompanyProductId = companyProduct.CompanyProductId
  84. productLog.CompanyId = companyProduct.CompanyId
  85. productLog.ProductId = companyProduct.ProductId
  86. productLog.ProductName = companyProduct.ProductName
  87. productLog.CompanyName = companyProduct.CompanyName
  88. productLog.CompanyName = companyProduct.CompanyName
  89. productLog.Source = companyProduct.Source
  90. productLog.Reasons = companyProduct.Reasons
  91. productLog.Status = companyProduct.Status
  92. productLog.IndustryId = companyProduct.IndustryId
  93. productLog.IndustryName = companyProduct.IndustryName
  94. productLog.SellerId = companyProduct.SellerId
  95. productLog.SellerName = companyProduct.SellerName
  96. productLog.GroupId = companyProduct.GroupId
  97. productLog.DepartmentId = companyProduct.DepartmentId
  98. productLog.IsSuspend = companyProduct.IsSuspend
  99. productLog.SuspendTime = companyProduct.SuspendTime
  100. productLog.ApproveStatus = companyProduct.ApproveStatus
  101. productLog.FreezeTime = companyProduct.FreezeTime
  102. productLog.Remark = companyProduct.Remark
  103. productLog.StartDate = companyProduct.StartDate
  104. productLog.EndDate = companyProduct.EndDate
  105. productLog.CreateTime = companyProduct.CreateTime
  106. productLog.ModifyTime = companyProduct.ModifyTime
  107. productLog.LoseReason = companyProduct.LoseReason
  108. productLog.LossTime = companyProduct.LossTime
  109. productLog.LogType = logType
  110. productLog.LogCreateTime = time.Now()
  111. productLog.AdminId = adminId
  112. err = company.AddCompanyProductLog(productLog)
  113. //修改公司更新时间
  114. sql := `UPDATE company SET last_updated_time=NOW() WHERE company_id=? `
  115. o := orm.NewOrm()
  116. o.Raw(sql, companyProduct.CompanyId).Exec()
  117. return
  118. }
  119. func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
  120. defer func() {
  121. if err != nil {
  122. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err:"+err.Error(), 3)
  123. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  124. }
  125. }()
  126. record := new(company.CompanyOperationRecord)
  127. record.CompanyId = companyId
  128. record.CompanyName = companyName
  129. record.SellerId = sellerId
  130. record.SysUserId = sysUserId
  131. record.SysRealName = sysUserRealName
  132. record.Remark = remark
  133. record.Operation = operation
  134. record.CreateTime = time.Now()
  135. record.ProductId = productId
  136. record.ProductName = productName
  137. record.ApproveUserId = approveAdminId
  138. record.ApproveRealName = approveUserRealName
  139. record.ApproveContent = approveContent
  140. record.ApproveRemark = approveRemark
  141. record.Status = status
  142. _, err = company.AddCompanyOperationRecord(record)
  143. return
  144. }
  145. // AddCompanyOperationRecordMore 添加操作记录(包含补充信息)
  146. func AddCompanyOperationRecordMore(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveContentExtra, approveUserRealName, approveRemark, status string) (err error) {
  147. defer func() {
  148. if err != nil {
  149. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecordMore;Err:"+err.Error(), 3)
  150. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  151. }
  152. }()
  153. record := new(company.CompanyOperationRecord)
  154. record.CompanyId = companyId
  155. record.CompanyName = companyName
  156. record.SellerId = sellerId
  157. record.SysUserId = sysUserId
  158. record.SysRealName = sysUserRealName
  159. record.Remark = remark
  160. record.Operation = operation
  161. record.CreateTime = time.Now()
  162. record.ProductId = productId
  163. record.ProductName = productName
  164. record.ApproveUserId = approveAdminId
  165. record.ApproveRealName = approveUserRealName
  166. record.ApproveContent = approveContent
  167. record.ApproveContentExtra = approveContentExtra
  168. record.ApproveRemark = approveRemark
  169. record.Status = status
  170. _, err = company.AddCompanyOperationRecord(record)
  171. return
  172. }
  173. func GetProductId(roleTypeCode string) (productId int) {
  174. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  175. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  176. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  177. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  178. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
  179. productId = 1
  180. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  181. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  182. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  183. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  184. productId = 2
  185. } else {
  186. productId = 0
  187. }
  188. return
  189. }
  190. // CheckAdminIsSeller 根据用户权限码获取是否属于销售
  191. func CheckAdminIsSeller(roleTypeCode string) (isSeller bool) {
  192. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  193. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  194. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  195. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  196. isSeller = true
  197. }
  198. return
  199. }
  200. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  201. // button.BtnView = true
  202. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  203. // if !strings.Contains(status, "/") {
  204. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  205. // //button.BtnModifySeller = true
  206. // return
  207. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  208. // button.BtnEdit = true
  209. // button.BtnDelete = true
  210. // //button.BtnModifySeller = true
  211. // return
  212. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  213. // //button.BtnModifySeller = true
  214. // return
  215. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  216. // //button.BtnModifySeller = true
  217. // button.BtnDelete = true
  218. // return
  219. // } else { //永续
  220. // //button.BtnModifySeller = true
  221. // button.BtnDelete = true
  222. // button.BtnEdit = true
  223. // return
  224. // }
  225. // }
  226. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  227. // if productId != 1 {
  228. // return
  229. // } else {
  230. // if !strings.Contains(status, "/") {
  231. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  232. // button.BtnModifySeller = true
  233. // return
  234. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  235. // button.BtnEdit = true
  236. // button.BtnDelete = true
  237. // button.BtnModifySeller = true
  238. // return
  239. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  240. // //button.BtnModifySeller = true
  241. // return
  242. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  243. // //button.BtnModifySeller = true
  244. // button.BtnDelete = true
  245. // return
  246. // } else { //永续
  247. // return
  248. // }
  249. // }
  250. // }
  251. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  252. // if !strings.Contains(status, "/") {
  253. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  254. // button.BtnModifySeller = true
  255. // return
  256. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  257. // button.BtnEdit = true
  258. // button.BtnDelete = true
  259. // return
  260. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  261. // return
  262. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  263. // button.BtnDelete = true
  264. // return
  265. // } else { //永续
  266. // return
  267. // }
  268. // }
  269. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  270. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  271. // return
  272. // }
  273. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  274. // return
  275. // }
  276. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  277. // if authority == 2 { //组长
  278. // if !strings.Contains(status, "/") {
  279. // if sysUserId == itemSellerId { //自己客户
  280. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  281. // button.BtnUpdate = true
  282. // button.BtnModifySeller = true
  283. // return
  284. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  285. // button.BtnEdit = true
  286. // button.BtnDelete = true
  287. // button.BtnSuspend = true
  288. // button.BtnDelay = true
  289. // button.BtnTurnPositive = true
  290. // button.BtnModifySeller = true
  291. // return
  292. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  293. // button.BtnThaw = true
  294. // return
  295. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  296. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  297. // button.BtnApplyReceive = true
  298. // } else {
  299. // button.BtnReceive = true
  300. // }
  301. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  302. // button.BtnDelete = true
  303. // }
  304. // return
  305. // } else { //永续
  306. // button.BtnDelete = true
  307. // return
  308. // }
  309. // } else {
  310. // if productId == 1 {
  311. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  312. // button.BtnModifySeller=true
  313. // return
  314. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  315. // button.BtnModifySeller=true
  316. // return
  317. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  318. // button.BtnThaw = true
  319. // return
  320. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  321. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  322. // button.BtnApplyReceive = true
  323. // } else {
  324. // button.BtnReceive = true
  325. // }
  326. // return
  327. // } else { //永续
  328. // button.BtnDelete = true
  329. // return
  330. // }
  331. // } else {
  332. // button.BtnReceive = true
  333. // }
  334. // }
  335. // }
  336. // } else { //销售
  337. // if !strings.Contains(status, "/") {
  338. // if itemSellerId == sysUserId {
  339. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  340. // button.BtnUpdate = true
  341. // return
  342. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  343. // button.BtnEdit = true
  344. // button.BtnDelete = true
  345. // button.BtnSuspend = true
  346. // button.BtnDelay = true
  347. // button.BtnTurnPositive = true
  348. // return
  349. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  350. // button.BtnThaw = true
  351. // return
  352. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  353. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  354. // button.BtnApplyReceive = true
  355. // } else {
  356. // button.BtnReceive = true
  357. // }
  358. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  359. // button.BtnDelete = true
  360. // }
  361. // return
  362. // } else { //永续
  363. // button.BtnDelete = true
  364. // return
  365. // }
  366. // } else {
  367. // if productId == 1 {
  368. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  369. // return
  370. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  371. // return
  372. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  373. // button.BtnThaw = true
  374. // return
  375. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  376. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  377. // button.BtnApplyReceive = true
  378. // } else {
  379. // button.BtnReceive = true
  380. // }
  381. // return
  382. // } else { //永续
  383. // button.BtnDelete = true
  384. // return
  385. // }
  386. // } else {
  387. // button.BtnReceive = true
  388. // }
  389. // }
  390. // }
  391. // }
  392. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  393. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  394. // return
  395. // }
  396. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  397. // return
  398. // }
  399. // if !strings.Contains(status, "/") {
  400. // if authority == 2 { //组长
  401. // if itemSellerId==sysUserId {
  402. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  403. // button.BtnUpdate = true
  404. // button.BtnModifySeller = true
  405. // return
  406. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  407. // button.BtnEdit = true
  408. // button.BtnDelete = true
  409. // button.BtnSuspend = true
  410. // button.BtnDelay = true
  411. // button.BtnTurnPositive = true
  412. // button.BtnModifySeller = true
  413. // return
  414. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  415. // button.BtnThaw = true
  416. // return
  417. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  418. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  419. // button.BtnApplyReceive = true
  420. // } else {
  421. // button.BtnReceive = true
  422. // }
  423. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  424. // button.BtnDelete = true
  425. // }
  426. // return
  427. // } else { //永续
  428. // button.BtnDelete = true
  429. // return
  430. // }
  431. // }else{
  432. // if productId==1 {
  433. // button.BtnReceive=true
  434. // }else{
  435. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  436. // button.BtnModifySeller=true
  437. // return
  438. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  439. // button.BtnModifySeller=true
  440. // return
  441. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  442. // button.BtnThaw = true
  443. // return
  444. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  445. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  446. // button.BtnApplyReceive = true
  447. // } else {
  448. // button.BtnReceive = true
  449. // }
  450. // return
  451. // } else { //永续
  452. // button.BtnDelete = true
  453. // return
  454. // }
  455. // }
  456. // }
  457. // } else {
  458. // if itemSellerId==sysUserId {
  459. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  460. // button.BtnUpdate = true
  461. // return
  462. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  463. // button.BtnEdit = true
  464. // button.BtnDelete = true
  465. // button.BtnSuspend = true
  466. // button.BtnDelay = true
  467. // button.BtnTurnPositive = true
  468. // return
  469. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  470. // button.BtnThaw = true
  471. // return
  472. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  473. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  474. // button.BtnApplyReceive = true
  475. // } else {
  476. // button.BtnReceive = true
  477. // }
  478. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  479. // button.BtnDelete = true
  480. // }
  481. // return
  482. // } else { //永续
  483. // button.BtnDelete = true
  484. // return
  485. // }
  486. // }else{
  487. // if productId==1 {
  488. // button.BtnReceive=true
  489. // }else{
  490. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  491. // return
  492. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  493. // return
  494. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  495. // button.BtnThaw = true
  496. // return
  497. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  498. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  499. // button.BtnApplyReceive = true
  500. // } else {
  501. // button.BtnReceive = true
  502. // }
  503. // return
  504. // } else { //永续
  505. // button.BtnDelete = true
  506. // return
  507. // }
  508. // }
  509. // }
  510. // }
  511. // }
  512. // }
  513. // return button
  514. //}
  515. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  516. // button.BtnView = true
  517. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  518. // if !strings.Contains(status, "/") {
  519. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  520. // button.BtnView = true
  521. // button.BtnModifySeller = true
  522. // return
  523. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  524. // button.BtnEdit = true
  525. // button.BtnDelete = true
  526. // button.BtnFreeze=true
  527. // return
  528. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  529. // button.BtnModifySeller = true
  530. // button.BtnView = true
  531. // return
  532. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  533. // button.BtnDelete = true
  534. // button.BtnModifySeller = true
  535. // return
  536. // } else { //永续
  537. // button.BtnDelete = true
  538. // button.BtnEdit = true
  539. // return
  540. // }
  541. // }
  542. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  543. // fmt.Println("itemSellerId:",itemSellerId)
  544. // fmt.Println("sysUserId:",sysUserId)
  545. // if !strings.Contains(status, "/") {
  546. // if itemSellerId == sysUserId {
  547. // if productId == 1 {
  548. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  549. // button.BtnModifySeller = true
  550. // button.BtnUpdate = true
  551. // return
  552. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  553. // button.BtnEdit = true
  554. // button.BtnDelete = true
  555. // button.BtnModifySeller = true
  556. // button.BtnSuspend = true
  557. // button.BtnDelay = true
  558. // button.BtnTurnPositive = true
  559. // button.BtnFreeze=true
  560. // return
  561. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  562. // button.BtnModifySeller = true
  563. // button.BtnView = true
  564. // return
  565. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  566. // button.BtnModifySeller = true
  567. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  568. // button.BtnDelete = true
  569. // }
  570. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  571. // button.BtnApplyReceive = true
  572. // } else {
  573. // button.BtnReceive = true
  574. // }
  575. // return
  576. // } else { //永续
  577. // button.BtnDelete = true
  578. // return
  579. // }
  580. // } else {
  581. // //button.BtnReceiveOther=true
  582. // return
  583. // }
  584. // } else {
  585. // if productId == 1 {
  586. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  587. // button.BtnModifySeller = true
  588. // return
  589. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  590. // button.BtnEdit = true
  591. // button.BtnDelete = true
  592. // return
  593. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  594. // button.BtnModifySeller = true
  595. // button.BtnView = true
  596. // return
  597. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  598. // button.BtnModifySeller = true
  599. // button.BtnDelete = true
  600. // button.BtnView = true
  601. // return
  602. // } else { //永续
  603. // return
  604. // }
  605. // } else {
  606. // button.BtnReceiveOther = true
  607. // return
  608. // }
  609. // }
  610. // }
  611. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  612. // if !strings.Contains(status, "/") {
  613. // if itemSellerId == sysUserId {
  614. // if productId == 2 {
  615. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  616. // button.BtnModifySeller = true
  617. // button.BtnUpdate = true
  618. // return
  619. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  620. // button.BtnEdit = true
  621. // button.BtnDelete = true
  622. // button.BtnModifySeller = true
  623. // button.BtnSuspend = true
  624. // button.BtnDelay = true
  625. // button.BtnTurnPositive = true
  626. // button.BtnFreeze=true
  627. // return
  628. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  629. // button.BtnModifySeller = true
  630. // return
  631. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  632. // button.BtnModifySeller = true
  633. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  634. // button.BtnDelete = true
  635. // }
  636. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  637. // button.BtnApplyReceive = true
  638. // } else {
  639. // button.BtnReceive = true
  640. // }
  641. // return
  642. // } else { //永续
  643. // button.BtnDelete = true
  644. // return
  645. // }
  646. // } else {
  647. // return
  648. // }
  649. // } else {
  650. // if productId == 2 {
  651. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  652. // button.BtnModifySeller = true
  653. // button.BtnView = true
  654. // return
  655. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  656. // button.BtnEdit = true
  657. // button.BtnDelete = true
  658. // return
  659. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  660. // button.BtnView = true
  661. // button.BtnModifySeller = true
  662. // return
  663. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  664. // button.BtnModifySeller = true
  665. // button.BtnDelete = true
  666. // button.BtnView = true
  667. // return
  668. // } else { //永续
  669. // return
  670. // }
  671. // } else {
  672. // //button.BtnReceive = true
  673. // return
  674. // }
  675. // }
  676. // }
  677. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  678. // if !strings.Contains(status, "/") {
  679. // if itemSellerId == sysUserId {
  680. // if productId == 1 {
  681. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  682. // button.BtnUpdate = true
  683. // return
  684. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  685. // button.BtnDelete = true
  686. // button.BtnEdit = true
  687. // button.BtnSuspend = true
  688. // button.BtnDelay = true
  689. // button.BtnTurnPositive = true
  690. // button.BtnFreeze=true
  691. // return
  692. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  693. // button.BtnThaw = true
  694. // return
  695. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  696. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  697. // button.BtnApplyReceive = true
  698. // } else {
  699. // button.BtnReceive = true
  700. // }
  701. // if itemSellerId == sysUserId || (sysUserGroupId == itemGroupId && authority == 2) {
  702. // button.BtnDelete = true
  703. // }
  704. // return
  705. // } else { //永续
  706. // button.BtnDelete = true
  707. // return
  708. // }
  709. // } else {
  710. // button.BtnReceiveOther = true
  711. // return
  712. // }
  713. // } else {
  714. // if productId == 1 {
  715. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  716. // return
  717. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  718. // return
  719. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  720. // button.BtnApplyReceive = true
  721. // button.BtnView = false
  722. // return
  723. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  724. // if itemGroupId == sysUserGroupId {
  725. // button.BtnApplyReceive = true
  726. // } else {
  727. // button.BtnReceive = true
  728. // }
  729. // button.BtnView = false
  730. // return
  731. // } else { //永续
  732. // button.BtnDelete = true
  733. // return
  734. // }
  735. // } else {
  736. // button.BtnReceiveOther = true
  737. // button.BtnView = false
  738. // return
  739. // }
  740. // }
  741. // }
  742. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  743. // if !strings.Contains(status, "/") {
  744. // if itemSellerId == sysUserId {
  745. // if productId == 2 {
  746. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  747. // button.BtnUpdate = true
  748. // return
  749. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  750. // button.BtnDelete = true
  751. // button.BtnEdit = true
  752. // button.BtnSuspend = true
  753. // button.BtnDelay = true
  754. // button.BtnTurnPositive = true
  755. // button.BtnFreeze=true
  756. // return
  757. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  758. // button.BtnThaw = true
  759. // return
  760. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  761. // if itemGroupId == sysUserGroupId {
  762. // button.BtnApplyReceive = true
  763. // } else {
  764. // button.BtnReceive = true
  765. // }
  766. // if sysUserGroupId == itemGroupId && authority == 2 {
  767. // button.BtnDelete = true
  768. // }
  769. // return
  770. // } else { //永续
  771. // button.BtnDelete = true
  772. // return
  773. // }
  774. // } else {
  775. // button.BtnReceiveOther = true
  776. // return
  777. // }
  778. // } else {
  779. // if productId == 2 {
  780. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  781. // return
  782. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  783. // return
  784. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  785. // button.BtnApplyReceive = true
  786. // button.BtnView = false
  787. // return
  788. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  789. // if itemGroupId == sysUserGroupId {
  790. // button.BtnApplyReceive = true
  791. // } else {
  792. // button.BtnReceive = true
  793. // }
  794. // button.BtnView = false
  795. // return
  796. // } else { //永续
  797. // button.BtnDelete = true
  798. // return
  799. // }
  800. // } else {
  801. // button.BtnReceiveOther = true
  802. // button.BtnView = false
  803. // return
  804. // }
  805. // }
  806. // }
  807. // }
  808. // return button
  809. //}
  810. //
  811. func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int, shareSellerIds string) (button company.ButtonPermission) {
  812. //产品状态map
  813. productStatusMap := make(map[int]string)
  814. if productId == 1 {
  815. productStatusMap[1] = status
  816. } else if productId == 2 {
  817. productStatusMap[2] = status
  818. }
  819. if strings.Contains(status, "/") {
  820. statusSlice := strings.Split(status, "/")
  821. productStatusMap[1] = statusSlice[0]
  822. productStatusMap[2] = statusSlice[1]
  823. }
  824. //所属销售map
  825. sellerIdMap := make(map[int]int)
  826. if productId == 1 {
  827. sellerIdMap[1] = itemSellerId
  828. } else if productId == 2 {
  829. sellerIdMap[2] = itemSellerId
  830. }
  831. if strings.Contains(itemSellerIds, "/") {
  832. sellerIdSlice := strings.Split(itemSellerIds, "/")
  833. sellerIdMap[1], _ = strconv.Atoi(sellerIdSlice[0])
  834. sellerIdMap[2], _ = strconv.Atoi(sellerIdSlice[1])
  835. }
  836. //分组map
  837. groupIdMap := make(map[int]int)
  838. if productId == 1 {
  839. groupIdMap[1] = itemGroupId
  840. } else if productId == 2 {
  841. groupIdMap[2] = itemGroupId
  842. }
  843. if strings.Contains(itemGroupIdS, "/") {
  844. groupIdSlice := strings.Split(itemGroupIdS, "/")
  845. groupIdMap[1], _ = strconv.Atoi(groupIdSlice[0])
  846. groupIdMap[2], _ = strconv.Atoi(groupIdSlice[1])
  847. }
  848. shareSellerIdArr := strings.Split(shareSellerIds, ",")
  849. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  850. button.BtnView = true //查看详情权限
  851. if !strings.Contains(status, "/") {
  852. if status == utils.COMPANY_STATUS_FORMAL { //正式
  853. //button.BtnModifySeller = true
  854. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  855. button.BtnRemarkViewHistory = true
  856. } else {
  857. button.BtnRemarkView = true
  858. }
  859. return
  860. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  861. button.BtnEdit = true
  862. button.BtnDelete = true
  863. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  864. button.BtnRemarkViewHistory = true
  865. } else {
  866. button.BtnRemarkView = true
  867. }
  868. //button.BtnModifySeller = true
  869. button.BtnFreeze = false
  870. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  871. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  872. }
  873. return
  874. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  875. //button.BtnModifySeller = true
  876. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  877. button.BtnRemarkViewHistory = true
  878. } else {
  879. button.BtnRemarkView = true
  880. }
  881. return
  882. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  883. //button.BtnModifySeller = true
  884. button.BtnDelete = true
  885. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  886. button.BtnRemarkViewHistory = true
  887. }
  888. return
  889. } else if status == utils.COMPANY_STATUS_CLOSE { // 关闭
  890. //button.BtnModifySeller = true
  891. button.BtnDelete = true
  892. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  893. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  894. }
  895. return
  896. } else { //永续
  897. //button.BtnModifySeller = true
  898. button.BtnDelete = true
  899. button.BtnEdit = true
  900. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  901. button.BtnRemarkViewHistory = true
  902. }
  903. return
  904. }
  905. }
  906. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  907. //查看详情权限
  908. productStatus, hasProduct := productStatusMap[1]
  909. if hasProduct {
  910. button.BtnView = true
  911. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  912. button.BtnModifySeller = true
  913. button.BtnShare = true
  914. return
  915. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  916. button.BtnEdit = true
  917. //button.BtnDelete = true
  918. button.BtnModifySeller = true
  919. button.BtnFreeze = false
  920. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  921. return
  922. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  923. button.BtnModifySeller = true
  924. return
  925. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  926. //button.BtnModifySeller = true
  927. //button.BtnDelete = true
  928. return
  929. } else if productStatus == utils.COMPANY_STATUS_CLOSE { // 关闭
  930. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  931. return
  932. } else { //永续
  933. return
  934. }
  935. } else {
  936. productStatus2, hasProduct2 := productStatusMap[2]
  937. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  938. if hasProduct2 {
  939. //其他产品的流失客户可以有查看权限
  940. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  941. button.BtnView = true //查看权限
  942. }
  943. }
  944. }
  945. return
  946. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  947. //查看详情权限
  948. productStatus, hasProduct := productStatusMap[2]
  949. if hasProduct {
  950. button.BtnView = true
  951. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  952. button.BtnModifySeller = true
  953. button.BtnShare = true
  954. button.BtnRemarkViewHistory = true
  955. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  956. button.BtnEdit = true
  957. //button.BtnDelete = true
  958. button.BtnModifySeller = true
  959. button.BtnFreeze = false
  960. // CRM14.7.2 权益管理员可以设置试用客户为共享
  961. button.BtnShare = true
  962. button.BtnRemarkViewHistory = true
  963. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  964. button.BtnModifySeller = true
  965. button.BtnRemarkViewHistory = true
  966. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  967. //button.BtnDelete = true
  968. button.BtnRemarkViewHistory = true
  969. } else { //永续
  970. button.BtnModifySeller = true
  971. button.BtnShare = true
  972. button.BtnRemarkViewHistory = true
  973. }
  974. } else {
  975. productStatus2, hasProduct2 := productStatusMap[1]
  976. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  977. if hasProduct2 {
  978. //其他产品的流失客户可以有查看权限
  979. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  980. button.BtnView = true //查看权限
  981. }
  982. }
  983. }
  984. return
  985. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  986. //判断该客户是否有ficc权限
  987. productStatus, hasProduct := productStatusMap[1]
  988. if hasProduct {
  989. //如果有权限的话:
  990. //获取当前ficc的销售id
  991. sellerId, hasSellerId := sellerIdMap[1]
  992. //获取当前ficc的销售分组id
  993. groupId, hasGroupId := groupIdMap[1]
  994. //如果是自己客户,那么拥有查看权限
  995. if hasSellerId {
  996. if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  997. button.BtnView = true //显示权限、详情
  998. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  999. button.BtnUpdate = true //服务更新
  1000. button.BtnAddAgreement = true //补充协议
  1001. button.BtnTryOut = true
  1002. button.BtnModifySeller = true
  1003. button.BtnShare = true
  1004. button.BtnRemarkEdit = true
  1005. button.BtnRemarkView = true
  1006. if sellerId != sysUserId {
  1007. button.BtnModifySeller = false
  1008. }
  1009. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1010. button.BtnEdit = true
  1011. button.BtnDelete = true
  1012. button.BtnSuspend = true
  1013. button.BtnDelay = true
  1014. button.BtnTurnPositive = true
  1015. button.BtnFreeze = true
  1016. button.BtnModifySeller = true
  1017. button.BtnRemarkEdit = true
  1018. button.BtnRemarkView = true
  1019. if sellerId != sysUserId {
  1020. button.BtnModifySeller = false
  1021. }
  1022. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1023. button.BtnThaw = true
  1024. button.BtnModifySeller = true
  1025. button.BtnRemarkEdit = true
  1026. button.BtnRemarkView = true
  1027. if sellerId != sysUserId {
  1028. button.BtnModifySeller = false
  1029. }
  1030. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1031. button.BtnApplyReceive = true
  1032. } else { //永续
  1033. //button.BtnDelete = true
  1034. }
  1035. } else {
  1036. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1037. button.BtnView = true //显示权限、详情
  1038. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1039. if groupId == sysUserGroupId {
  1040. button.BtnApplyReceive = true
  1041. } else {
  1042. button.BtnReceive = true
  1043. }
  1044. }
  1045. }
  1046. }
  1047. //如果是组长,且该客户属于本组客户
  1048. if authority == 4 && hasGroupId && groupId == sysUserGroupId && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  1049. button.BtnView = true //查看详情权限
  1050. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1051. button.BtnModifySeller = true
  1052. button.BtnShare = true
  1053. button.BtnRemarkView = true
  1054. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1055. button.BtnModifySeller = true
  1056. button.BtnRemarkView = true
  1057. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1058. button.BtnModifySeller = true
  1059. button.BtnRemarkView = true
  1060. //button.BtnThaw = false
  1061. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1062. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1063. button.BtnApplyReceive = true
  1064. } else {
  1065. button.BtnReceive = true
  1066. }
  1067. } else { //永续
  1068. //button.BtnDelete = true
  1069. }
  1070. }
  1071. //如果是ficc销售主管,且该客户属于本组客户
  1072. //获取父级groupId
  1073. groupIdpid, err := company.GetParentIdFromGroup(groupId)
  1074. if err != nil {
  1075. fmt.Println(err.Error())
  1076. }
  1077. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUserGroupId)
  1078. if err != nil {
  1079. fmt.Println(err.Error())
  1080. }
  1081. var pidBool bool
  1082. //处理主管和销售在不同的二三级分组下的情况
  1083. if groupIdpid != nil && sysUserGroupIdpid != nil {
  1084. pidBool = *groupIdpid == *sysUserGroupIdpid || *groupIdpid == sysUserGroupId || groupId == sysUserGroupId || groupId == *sysUserGroupIdpid
  1085. }
  1086. if authority == 2 && hasGroupId && pidBool && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  1087. button.BtnView = true //查看详情权限
  1088. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1089. button.BtnModifySeller = true
  1090. button.BtnShare = true
  1091. button.BtnRemarkView = true
  1092. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1093. button.BtnModifySeller = true
  1094. button.BtnRemarkView = true
  1095. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1096. button.BtnModifySeller = true
  1097. button.BtnRemarkView = true
  1098. //button.BtnThaw = false
  1099. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1100. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1101. button.BtnApplyReceive = true
  1102. } else {
  1103. button.BtnReceive = true
  1104. }
  1105. } else { //永续
  1106. //button.BtnDelete = true
  1107. }
  1108. }
  1109. //ficc同一个大组当作一个小组来处理领取按钮
  1110. var ids []*string
  1111. if groupIdpid != nil && *groupIdpid != 0 {
  1112. ids, err = company.GetGroupIdsByParentId(*groupIdpid)
  1113. if err != nil {
  1114. fmt.Println(err.Error())
  1115. }
  1116. }
  1117. var idSlice []string
  1118. var sid string
  1119. for _, id := range ids {
  1120. idSlice = append(idSlice, *id)
  1121. }
  1122. sid = strings.Join(idSlice, ",")
  1123. if strings.Contains(sid, strconv.Itoa(itemGroupId)) {
  1124. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1125. button.BtnApplyReceive = true
  1126. button.BtnReceive = false
  1127. }
  1128. }
  1129. } else {
  1130. productStatus2, hasProduct2 := productStatusMap[2]
  1131. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1132. if hasProduct2 {
  1133. //如果客户ficc权限是永续,那么也没有其他部门客户的按钮权限
  1134. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1135. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1136. }
  1137. //其他产品的流失客户可以有查看权限
  1138. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1139. button.BtnView = true //查看权限
  1140. }
  1141. }
  1142. }
  1143. return
  1144. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1145. //判断该客户是否有权益权限
  1146. productStatus, hasProduct := productStatusMap[2]
  1147. if hasProduct {
  1148. //如果有权限的话:
  1149. //获取当前 权益 的销售id
  1150. sellerId, hasSellerId := sellerIdMap[2]
  1151. //获取当前 权益 的销售分组id
  1152. groupId, hasGroupId := groupIdMap[2]
  1153. //如果是自己客户,那么拥有查看权限
  1154. if hasSellerId {
  1155. if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1156. button.BtnView = true //显示权限、详情
  1157. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1158. button.BtnUpdate = true
  1159. button.BtnTryOut = true
  1160. button.BtnModifySeller = true
  1161. //button.BtnShare = true
  1162. button.BtnRemarkEdit = true
  1163. //button.BtnRemarkView = true //权益销售隐藏
  1164. button.BtnRemarkViewHistory = true
  1165. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1166. button.BtnEdit = true
  1167. button.BtnDelete = true
  1168. button.BtnSuspend = true
  1169. button.BtnDelay = true
  1170. button.BtnTurnPositive = true
  1171. button.BtnModifySeller = true
  1172. button.BtnFreeze = true
  1173. button.BtnRemarkEdit = true
  1174. //button.BtnRemarkView = true //权益销售隐藏
  1175. button.BtnRemarkViewHistory = true
  1176. //button.BtnShare = true
  1177. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1178. button.BtnThaw = true
  1179. button.BtnModifySeller = true
  1180. button.BtnRemarkEdit = true
  1181. button.BtnRemarkView = true
  1182. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1183. button.BtnApplyReceive = true
  1184. button.BtnRemarkViewHistory = true
  1185. } else if productStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1186. button.BtnTurnPositive = true
  1187. button.BtnRemarkViewHistory = true
  1188. }
  1189. } else {
  1190. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1191. button.BtnView = true //显示权限、详情
  1192. button.BtnRemarkViewHistory = true
  1193. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1194. if groupId == sysUserGroupId {
  1195. button.BtnApplyReceive = true
  1196. } else {
  1197. button.BtnReceive = true
  1198. }
  1199. }
  1200. }
  1201. }
  1202. //如果是组长,且该客户属于本组客户
  1203. if authority == 2 && hasGroupId && groupId == sysUserGroupId {
  1204. button.BtnView = true //查看详情权限
  1205. button.BtnRemarkViewHistory = true //历史备注
  1206. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1207. button.BtnModifySeller = true
  1208. //button.BtnShare = true
  1209. //button.BtnRemarkView = true //权益销售隐藏
  1210. //button.BtnRemarkViewHistory = true
  1211. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1212. button.BtnModifySeller = true
  1213. //button.BtnRemarkView = true //权益销售隐藏
  1214. //button.BtnRemarkViewHistory = true
  1215. //button.BtnShare = true
  1216. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1217. button.BtnModifySeller = true
  1218. //button.BtnRemarkView = true //权益销售隐藏
  1219. //button.BtnRemarkViewHistory = true
  1220. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1221. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1222. button.BtnApplyReceive = true
  1223. } else {
  1224. button.BtnReceive = true
  1225. }
  1226. //button.BtnRemarkViewHistory = true
  1227. } else { //永续
  1228. //button.BtnDelete = true
  1229. //button.BtnRemarkViewHistory = true
  1230. }
  1231. }
  1232. } else {
  1233. productStatus2, hasProduct2 := productStatusMap[1]
  1234. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1235. if hasProduct2 {
  1236. //如果客户 权益 权限是永续,那么也没有其他部门客户的按钮权限
  1237. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1238. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1239. }
  1240. //其他产品的流失客户可以有查看权限
  1241. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1242. button.BtnView = true //查看权限
  1243. }
  1244. }
  1245. }
  1246. return
  1247. }
  1248. return button
  1249. }
  1250. // GetCompanyPermissionButtonByReceiveEnabled 查询当前销售 "添加客户" 权限来判断按钮权限
  1251. func GetCompanyPermissionButtonByReceiveEnabled(btnItem *company.ButtonPermission, receiveEnabled bool) (buttonNew *company.ButtonPermission) {
  1252. //查询当前销售 "添加客户" 权限是否为禁用
  1253. if !receiveEnabled {
  1254. //申请领取、领取客户、领取其他部门客户按钮权限按钮显示时
  1255. if btnItem.BtnApplyReceive || btnItem.BtnReceive || btnItem.BtnReceiveOther {
  1256. btnItem.BtnApplyReceive = false
  1257. btnItem.BtnReceive = false
  1258. btnItem.BtnReceiveOther = false
  1259. }
  1260. if btnItem.BtnThaw {
  1261. btnItem.BtnThaw = false
  1262. }
  1263. }
  1264. buttonNew = btnItem
  1265. return buttonNew
  1266. }
  1267. //func GetCompanyPermissionButtonOld(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  1268. // button.BtnView = true
  1269. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  1270. // if !strings.Contains(status, "/") {
  1271. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1272. // //button.BtnModifySeller = true
  1273. // return
  1274. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1275. // button.BtnEdit = true
  1276. // button.BtnDelete = true
  1277. // //button.BtnModifySeller = true
  1278. // button.BtnFreeze = false
  1279. // return
  1280. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1281. // //button.BtnModifySeller = true
  1282. // return
  1283. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1284. // //button.BtnModifySeller = true
  1285. // button.BtnDelete = true
  1286. // return
  1287. // } else { //永续
  1288. // //button.BtnModifySeller = true
  1289. // button.BtnDelete = true
  1290. // button.BtnEdit = true
  1291. // return
  1292. // }
  1293. // }
  1294. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1295. // if productId != 1 {
  1296. // return
  1297. // } else {
  1298. // if !strings.Contains(status, "/") {
  1299. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1300. // button.BtnModifySeller = true
  1301. // return
  1302. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1303. // //button.BtnEdit = true
  1304. // //button.BtnDelete = true
  1305. // button.BtnModifySeller = true
  1306. // button.BtnFreeze = false
  1307. // return
  1308. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1309. // //button.BtnModifySeller = true
  1310. // return
  1311. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1312. // //button.BtnModifySeller = true
  1313. // //button.BtnDelete = true
  1314. // return
  1315. // } else { //永续
  1316. // return
  1317. // }
  1318. // }
  1319. // }
  1320. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1321. // if !strings.Contains(status, "/") {
  1322. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1323. // button.BtnModifySeller = true
  1324. // return
  1325. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1326. // //button.BtnEdit = true
  1327. // //button.BtnDelete = true
  1328. // button.BtnModifySeller = true
  1329. // button.BtnFreeze = false
  1330. // return
  1331. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1332. // return
  1333. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1334. // //button.BtnDelete = true
  1335. // return
  1336. // } else { //永续
  1337. // return
  1338. // }
  1339. // }
  1340. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  1341. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1342. // if !strings.Contains(status, "/") {
  1343. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1344. // } else {
  1345. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1346. // statusSlice := strings.Split(status, "/")
  1347. // ficcStatus := statusSlice[0]
  1348. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1349. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1350. // button.BtnApplyReceive = true //申请领取按钮权限
  1351. // } else {
  1352. // button.BtnReceive = true //领取客户按钮权限
  1353. // }
  1354. // return
  1355. // }
  1356. // }
  1357. // return
  1358. // }
  1359. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1360. // return
  1361. // }
  1362. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  1363. // if authority == 2 { //组长
  1364. // if !strings.Contains(status, "/") {
  1365. // if sysUserId == itemSellerId { //自己客户
  1366. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1367. // button.BtnUpdate = true
  1368. // button.BtnModifySeller = true
  1369. // button.BtnTryOut = true
  1370. // return
  1371. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1372. // button.BtnEdit = true
  1373. // button.BtnDelete = true
  1374. // button.BtnSuspend = true
  1375. // button.BtnDelay = true
  1376. // button.BtnTurnPositive = true
  1377. // button.BtnModifySeller = true
  1378. // button.BtnFreeze = true
  1379. // return
  1380. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1381. // button.BtnThaw = true
  1382. // return
  1383. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1384. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1385. // button.BtnApplyReceive = true
  1386. // } else {
  1387. // button.BtnReceive = true
  1388. // }
  1389. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1390. // //button.BtnDelete = true
  1391. // }
  1392. // return
  1393. // } else { //永续
  1394. // button.BtnDelete = true
  1395. // return
  1396. // }
  1397. // } else {
  1398. // if productId == 1 {
  1399. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1400. // button.BtnModifySeller = true
  1401. // return
  1402. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1403. // button.BtnModifySeller = true
  1404. // return
  1405. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1406. // button.BtnThaw = false
  1407. // return
  1408. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1409. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1410. // button.BtnApplyReceive = true
  1411. // } else {
  1412. // button.BtnReceive = true
  1413. // }
  1414. // return
  1415. // } else { //永续
  1416. // button.BtnDelete = true
  1417. // return
  1418. // }
  1419. // } else {
  1420. // //button.BtnReceive = true
  1421. // }
  1422. // }
  1423. // }
  1424. // } else { //销售
  1425. // if !strings.Contains(status, "/") {
  1426. // if itemSellerId == sysUserId {
  1427. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1428. // button.BtnUpdate = true
  1429. // button.BtnTryOut = true
  1430. // return
  1431. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1432. // button.BtnEdit = true
  1433. // button.BtnDelete = true
  1434. // button.BtnSuspend = true
  1435. // button.BtnDelay = true
  1436. // button.BtnTurnPositive = true
  1437. // button.BtnFreeze = true
  1438. // return
  1439. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1440. // button.BtnThaw = true
  1441. // return
  1442. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1443. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1444. // button.BtnApplyReceive = true
  1445. // } else {
  1446. // button.BtnReceive = true
  1447. // }
  1448. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1449. // //button.BtnDelete = true
  1450. // }
  1451. // return
  1452. // } else { //永续
  1453. // button.BtnDelete = true
  1454. // return
  1455. // }
  1456. // } else {
  1457. // if productId == 1 {
  1458. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1459. // return
  1460. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1461. // return
  1462. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1463. // button.BtnThaw = false
  1464. // return
  1465. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1466. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1467. // button.BtnApplyReceive = true
  1468. // } else {
  1469. // button.BtnReceive = true
  1470. // }
  1471. // return
  1472. // } else { //永续
  1473. // button.BtnDelete = true
  1474. // return
  1475. // }
  1476. // } else {
  1477. // //button.BtnReceive = true
  1478. // }
  1479. // }
  1480. // } else {
  1481. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1482. // statusSlice := strings.Split(status, "/")
  1483. // ficcStatus := statusSlice[0]
  1484. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1485. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1486. // button.BtnApplyReceive = true //申请领取按钮权限
  1487. // } else {
  1488. // button.BtnReceive = true //领取客户按钮权限
  1489. // }
  1490. // return
  1491. // }
  1492. // }
  1493. // }
  1494. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  1495. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1496. // return
  1497. // }
  1498. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1499. // if !strings.Contains(status, "/") {
  1500. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1501. // } else {
  1502. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1503. // statusSlice := strings.Split(status, "/")
  1504. // raiStatus := statusSlice[1]
  1505. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1506. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1507. // button.BtnApplyReceive = true //申请领取按钮权限
  1508. // } else {
  1509. // button.BtnReceive = true //领取客户按钮权限
  1510. // }
  1511. // return
  1512. // }
  1513. // }
  1514. // return
  1515. // }
  1516. // if !strings.Contains(status, "/") {
  1517. // if authority == 2 { //组长
  1518. // if itemSellerId == sysUserId {
  1519. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1520. // button.BtnUpdate = true
  1521. // button.BtnModifySeller = true
  1522. // button.BtnTryOut = true
  1523. // return
  1524. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1525. // button.BtnEdit = true
  1526. // button.BtnDelete = true
  1527. // button.BtnSuspend = true
  1528. // button.BtnDelay = true
  1529. // button.BtnTurnPositive = true
  1530. // button.BtnModifySeller = true
  1531. // button.BtnFreeze = true
  1532. // return
  1533. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1534. // button.BtnThaw = true
  1535. // return
  1536. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1537. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1538. // button.BtnApplyReceive = true
  1539. // } else {
  1540. // button.BtnReceive = true
  1541. // }
  1542. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1543. // //button.BtnDelete = true
  1544. // }
  1545. // return
  1546. // } else { //永续
  1547. // button.BtnDelete = true
  1548. // return
  1549. // }
  1550. // } else {
  1551. // if productId == 1 {
  1552. // //button.BtnReceive = true
  1553. // } else {
  1554. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1555. // button.BtnModifySeller = true
  1556. // return
  1557. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1558. // button.BtnModifySeller = true
  1559. // return
  1560. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1561. // button.BtnThaw = false
  1562. // return
  1563. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1564. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1565. // button.BtnApplyReceive = true
  1566. // } else {
  1567. // button.BtnReceive = true
  1568. // }
  1569. // return
  1570. // } else { //永续
  1571. // button.BtnDelete = true
  1572. // return
  1573. // }
  1574. // }
  1575. // }
  1576. // } else {
  1577. // if itemSellerId == sysUserId {
  1578. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1579. // button.BtnUpdate = true
  1580. // button.BtnTryOut = true
  1581. // return
  1582. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1583. // button.BtnEdit = true
  1584. // button.BtnDelete = true
  1585. // button.BtnSuspend = true
  1586. // button.BtnDelay = true
  1587. // button.BtnTurnPositive = true
  1588. // button.BtnFreeze = true
  1589. // return
  1590. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1591. // button.BtnThaw = true
  1592. // return
  1593. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1594. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1595. // button.BtnApplyReceive = true //申请领取按钮权限
  1596. // } else {
  1597. // button.BtnReceive = true //领取客户按钮权限
  1598. // }
  1599. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1600. // //button.BtnDelete = true
  1601. // }
  1602. // return
  1603. // } else { //永续
  1604. // button.BtnDelete = true
  1605. // return
  1606. // }
  1607. // } else {
  1608. // if productId == 1 {
  1609. // //button.BtnReceive = true
  1610. // } else {
  1611. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1612. // return
  1613. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1614. // return
  1615. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1616. // button.BtnThaw = false
  1617. // return
  1618. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1619. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1620. // button.BtnApplyReceive = true //申请领取按钮权限
  1621. // } else {
  1622. // button.BtnReceive = true //领取客户按钮权限
  1623. // }
  1624. // return
  1625. // } else { //永续
  1626. // button.BtnDelete = true
  1627. // return
  1628. // }
  1629. // }
  1630. // }
  1631. // }
  1632. // } else {
  1633. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1634. // statusSlice := strings.Split(status, "/")
  1635. // raiStatus := statusSlice[1]
  1636. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1637. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1638. // button.BtnApplyReceive = true //申请领取按钮权限
  1639. // } else {
  1640. // button.BtnReceive = true //领取客户按钮权限
  1641. // }
  1642. // return
  1643. // }
  1644. // }
  1645. // }
  1646. // return button
  1647. //}
  1648. // 校验当前操作员是否具有联系人权限是否有操作权限
  1649. func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId, shareSellerId int, status string) (ok bool) {
  1650. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1651. ok = true
  1652. return
  1653. }
  1654. if sysUserId == itemSellerId || shareSellerId == sysUserId {
  1655. ok = true
  1656. //如果客户状态是流失,那么就无法操作
  1657. if status == utils.COMPANY_STATUS_LOSE || status == utils.COMPANY_STATUS_CLOSE {
  1658. ok = false
  1659. return
  1660. }
  1661. return
  1662. } else {
  1663. if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1664. //如果是ficc类型,同时当前账户是ficc管理员
  1665. ok = true
  1666. } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1667. //如果是权益类型,同时当前账户是 权益管理员
  1668. ok = true
  1669. }
  1670. }
  1671. return
  1672. }
  1673. // 校验当前操作员是否具给联系人开通个人研选的权限
  1674. func CheckCompanyUserYanXuanButton(roleTypeCode string, adminMobile string) (ok bool, err error) {
  1675. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1676. ok = true
  1677. return
  1678. }
  1679. crmConfig, err := company.GetConfigDetailByCode("rai_wx_user_yanxuan_button")
  1680. if err != nil {
  1681. return
  1682. }
  1683. sliceMobile := strings.Split(crmConfig.ConfigValue, ",")
  1684. for _, v := range sliceMobile {
  1685. if v == adminMobile {
  1686. ok = true
  1687. return
  1688. }
  1689. }
  1690. return
  1691. }
  1692. // GenerateOpenCompanyCode 生成第三方code编号
  1693. func GenerateOpenCompanyCode(companyId int) (openCode string) {
  1694. openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
  1695. return
  1696. }
  1697. // GenerateOpenCompanyProductCode 生成客户产品第三方code编号
  1698. func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
  1699. openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
  1700. return
  1701. }
  1702. // GetApplyTurnContractType
  1703. // 获取客户申请合同类型
  1704. func GetApplyTurnContractType(companyId, productId int) (contractType string, err error) {
  1705. //合同类型
  1706. contractType = "新签合同"
  1707. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  1708. if err != nil {
  1709. if err.Error() == utils.ErrNoRow() {
  1710. err = nil
  1711. return
  1712. }
  1713. err = errors.New("获取客户信息失败,Err:" + err.Error())
  1714. return
  1715. }
  1716. // 当前客户产品状态为试用,那么是续约合同
  1717. if companyProduct.Status == "正式" {
  1718. contractType = "续约合同"
  1719. }
  1720. var condition string
  1721. var pars []interface{}
  1722. condition += " AND product_id = ?"
  1723. pars = append(pars, productId)
  1724. condition += " AND status = ?"
  1725. pars = append(pars, 1)
  1726. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  1727. if err != nil {
  1728. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1729. return
  1730. }
  1731. if len(list) > 0 {
  1732. contractType = "续约合同"
  1733. }
  1734. //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  1735. total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  1736. if err != nil {
  1737. err = errors.New("查询用户变更记录异常,Err:" + err.Error())
  1738. return
  1739. }
  1740. if total > 0 {
  1741. contractType = "续约合同"
  1742. }
  1743. return
  1744. }
  1745. // GetLastContractPermissionList
  1746. // 获取客户的最近合同的权限期限
  1747. func GetLastContractPermissionList(companyId, productId int) (permissionMap map[int]company.PermissionLookItem, err error) {
  1748. permissionMap = map[int]company.PermissionLookItem{}
  1749. contractList, err := company.GetCompanyWillContractList(companyId, productId)
  1750. if err != nil {
  1751. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1752. return
  1753. }
  1754. for _, contractInfo := range contractList {
  1755. permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
  1756. if permissionErr != nil {
  1757. err = errors.New("获取合同信息失败,Err:" + permissionErr.Error())
  1758. return
  1759. }
  1760. for _, v := range permissionList {
  1761. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1762. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1763. if tmpErr != nil {
  1764. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1765. return
  1766. }
  1767. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1768. if err != nil {
  1769. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1770. return
  1771. }
  1772. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1773. if nowEndDateTime.After(perEndDateTime) {
  1774. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1775. ChartPermissionId: v.ChartPermissionId,
  1776. PermissionName: v.ChartPermissionName,
  1777. StartDate: v.StartDate,
  1778. EndDate: v.EndDate,
  1779. //Status string `description:"'正式','试用','关闭'"`
  1780. //ExpireDay string `description:"到期天数"`
  1781. ClassifyName: v.ClassifyName,
  1782. }
  1783. }
  1784. } else {
  1785. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1786. ChartPermissionId: v.ChartPermissionId,
  1787. PermissionName: v.ChartPermissionName,
  1788. StartDate: v.StartDate,
  1789. EndDate: v.EndDate,
  1790. //Status string `description:"'正式','试用','关闭'"`
  1791. //ExpireDay string `description:"到期天数"`
  1792. ClassifyName: v.ClassifyName,
  1793. }
  1794. }
  1795. }
  1796. }
  1797. //获取权限
  1798. permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
  1799. if permissionErr != nil {
  1800. err = errors.New("获取权限失败,Err:" + permissionErr.Error())
  1801. return
  1802. }
  1803. for _, v := range permissionList {
  1804. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1805. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1806. if tmpErr != nil {
  1807. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1808. return
  1809. }
  1810. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1811. if err != nil {
  1812. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1813. return
  1814. }
  1815. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1816. if nowEndDateTime.After(perEndDateTime) {
  1817. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1818. ChartPermissionId: v.ChartPermissionId,
  1819. PermissionName: v.PermissionName,
  1820. StartDate: v.StartDate,
  1821. EndDate: v.EndDate,
  1822. //Status string `description:"'正式','试用','关闭'"`
  1823. //ExpireDay string `description:"到期天数"`
  1824. ClassifyName: v.ClassifyName,
  1825. }
  1826. }
  1827. } else {
  1828. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1829. ChartPermissionId: v.ChartPermissionId,
  1830. PermissionName: v.PermissionName,
  1831. StartDate: v.StartDate,
  1832. EndDate: v.EndDate,
  1833. //Status string `description:"'正式','试用','关闭'"`
  1834. //ExpireDay string `description:"到期天数"`
  1835. ClassifyName: v.ClassifyName,
  1836. }
  1837. }
  1838. }
  1839. return
  1840. }
  1841. // GetFiccLastUserViewHistoryByCompanyIds 根据客户id集合map获取ficc最后一次阅读时间
  1842. func GetFiccLastUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTime map[int]time.Time, err error) {
  1843. //user_view_record mobile
  1844. companyViewTime = make(map[int]time.Time)
  1845. userViewList, err := models.GetLastUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1846. if err != nil {
  1847. return
  1848. }
  1849. for _, userView := range userViewList {
  1850. companyViewTime[userView.CompanyId] = userView.ViewTime
  1851. }
  1852. //user_view_record email
  1853. userViewList, err = models.GetLastUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1854. if err != nil {
  1855. return
  1856. }
  1857. checkLastTime(companyViewTime, userViewList)
  1858. //AdvisoryArticleViewRecord mobile
  1859. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1860. if err != nil {
  1861. return
  1862. }
  1863. checkLastTime(companyViewTime, userViewList)
  1864. //AdvisoryArticleViewRecord email
  1865. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1866. if err != nil {
  1867. return
  1868. }
  1869. checkLastTime(companyViewTime, userViewList)
  1870. //ReportViewRecord mobile
  1871. mobileOrEmailViewList, err := models.GetLastReportViewRecordByMobileList(mobileList)
  1872. if err != nil {
  1873. return
  1874. }
  1875. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, mobileCompanyIdMap)
  1876. //ReportViewRecord email
  1877. mobileOrEmailViewList, err = models.GetLastReportViewRecordByEmailList(emailList)
  1878. if err != nil {
  1879. return
  1880. }
  1881. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, emailCompanyIdMap)
  1882. //UserViewStatistics mobile
  1883. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1884. if err != nil {
  1885. return
  1886. }
  1887. checkLastTime(companyViewTime, userViewList)
  1888. //UserViewStatistics email
  1889. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1890. if err != nil {
  1891. return
  1892. }
  1893. checkLastTime(companyViewTime, userViewList)
  1894. return
  1895. }
  1896. // GetRaiLastUserViewHistoryByCompanyIds 根据客户id集合map获取权益最后一次阅读时间
  1897. func GetRaiLastUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTime map[int]time.Time, err error) {
  1898. //CygxArticleViewRecord mobile
  1899. companyViewTime = make(map[int]time.Time)
  1900. userViewList, err := models.GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1901. if err != nil {
  1902. return
  1903. }
  1904. for _, userView := range userViewList {
  1905. companyViewTime[userView.CompanyId] = userView.ViewTime
  1906. }
  1907. //CygxArticleViewRecord email
  1908. userViewList, err = models.GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1909. if err != nil {
  1910. return
  1911. }
  1912. checkLastTime(companyViewTime, userViewList)
  1913. return
  1914. }
  1915. // checkLastTime 检测最后的时间并重新赋值
  1916. func checkLastTime(companyViewTime map[int]time.Time, userViewList []*models.CompanyLastViewSlice) {
  1917. for _, userView := range userViewList {
  1918. if viewTime, ok := companyViewTime[userView.CompanyId]; ok {
  1919. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1920. companyViewTime[userView.CompanyId] = userView.ViewTime
  1921. }
  1922. } else { //如果没有数据,那么直接赋值
  1923. companyViewTime[userView.CompanyId] = userView.ViewTime
  1924. }
  1925. }
  1926. return
  1927. }
  1928. // checkMobileOrEmailLastTime 根据用户信息检测最后的时间并重新赋值
  1929. func checkMobileOrEmailLastTime(companyViewTime map[int]time.Time, userViewList []*models.MobileOrEmailLastViewSlice, companyMap map[string]int) {
  1930. for _, userView := range userViewList {
  1931. // 先找到客户id
  1932. companyId, ok := companyMap[userView.Mobile]
  1933. if !ok {
  1934. continue
  1935. }
  1936. // 相同客户id的数据进行比较
  1937. if viewTime, ok := companyViewTime[companyId]; ok {
  1938. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1939. companyViewTime[companyId] = userView.ViewTime
  1940. }
  1941. } else { //如果没有数据,那么直接赋值
  1942. companyViewTime[companyId] = userView.ViewTime
  1943. }
  1944. }
  1945. return
  1946. }
  1947. // GetFiccCountUserViewHistoryByCompanyIds 根据客户id集合map获取ficc的阅读次数
  1948. func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTotal map[int]int, err error) {
  1949. //user_view_record mobile
  1950. companyViewTotal = make(map[int]int)
  1951. userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1952. if err != nil {
  1953. return
  1954. }
  1955. for _, userView := range userViewList {
  1956. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1957. }
  1958. userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1959. if err != nil {
  1960. return
  1961. }
  1962. checkCount(companyViewTotal, userViewList)
  1963. //AdvisoryArticleViewRecord mobile
  1964. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1965. if err != nil {
  1966. return
  1967. }
  1968. checkCount(companyViewTotal, userViewList)
  1969. //AdvisoryArticleViewRecord email
  1970. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1971. if err != nil {
  1972. return
  1973. }
  1974. checkCount(companyViewTotal, userViewList)
  1975. //ReportViewRecord mobile
  1976. mobileOrEmailViewList, err := models.GetCountReportViewRecordByMobileList(mobileList)
  1977. if err != nil {
  1978. return
  1979. }
  1980. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, mobileCompanyIdMap)
  1981. //ReportViewRecord email
  1982. mobileOrEmailViewList, err = models.GetCountReportViewRecordByEmailList(emailList)
  1983. if err != nil {
  1984. return
  1985. }
  1986. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, emailCompanyIdMap)
  1987. //UserViewStatistics mobile
  1988. userViewList, err = models.GetUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1989. if err != nil {
  1990. return
  1991. }
  1992. checkCount(companyViewTotal, userViewList)
  1993. //UserViewStatistics email
  1994. userViewList, err = models.GetUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1995. if err != nil {
  1996. return
  1997. }
  1998. checkCount(companyViewTotal, userViewList)
  1999. return
  2000. }
  2001. // GetRaiCountUserViewHistoryByCompanyIds 根据客户id集合map获取权益的阅读次数
  2002. func GetRaiCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  2003. //CygxArticleViewRecord mobile
  2004. companyViewTotal = make(map[int]int)
  2005. userViewList, err := models.GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  2006. if err != nil {
  2007. return
  2008. }
  2009. for _, userView := range userViewList {
  2010. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  2011. }
  2012. //CygxArticleViewRecord email
  2013. userViewList, err = models.GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  2014. if err != nil {
  2015. return
  2016. }
  2017. checkCount(companyViewTotal, userViewList)
  2018. return
  2019. }
  2020. // GetAllCountUserViewHistoryByCompanyIds 根据客户id集合map获取所有的阅读次数
  2021. //func GetAllCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  2022. // companyViewTotal = make(map[int]int)
  2023. // companyFiccViewTotal, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  2024. // if err != nil {
  2025. // return
  2026. // }
  2027. //
  2028. // companyRaiViewTotal, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  2029. // if err != nil {
  2030. // return
  2031. // }
  2032. //
  2033. // companyIdList := strings.Split(companyIdStr, ",")
  2034. //
  2035. // for _, companyIdStr := range companyIdList {
  2036. // companyId, _ := strconv.Atoi(companyIdStr)
  2037. // ficcTotal, ok := companyFiccViewTotal[companyId]
  2038. // if !ok {
  2039. // ficcTotal = 0
  2040. // }
  2041. // raiTotal, ok := companyRaiViewTotal[companyId]
  2042. // if !ok {
  2043. // raiTotal = 0
  2044. // }
  2045. // companyViewTotal[companyId] = ficcTotal + raiTotal
  2046. // }
  2047. // return
  2048. //}
  2049. func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
  2050. for _, userView := range userViewList {
  2051. if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
  2052. companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
  2053. } else { //如果没有数据,那么直接赋值
  2054. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  2055. }
  2056. }
  2057. return
  2058. }
  2059. // checkMobileOrEmailCount 根据手机号或者邮箱进行数据比较
  2060. func checkMobileOrEmailCount(companyViewTotal map[int]int, mobileOrEmailViewList []*models.MobileOrEmailViewTotalSlice, companyMap map[string]int) {
  2061. for _, userView := range mobileOrEmailViewList {
  2062. // 先找到客户id
  2063. companyId, ok := companyMap[userView.Mobile]
  2064. if !ok {
  2065. continue
  2066. }
  2067. // 相同客户id的数据进行比较
  2068. if viewTotal, ok := companyViewTotal[companyId]; ok {
  2069. companyViewTotal[companyId] = viewTotal + userView.ViewTotal
  2070. } else { //如果没有数据,那么直接赋值
  2071. companyViewTotal[companyId] = userView.ViewTotal
  2072. }
  2073. }
  2074. return
  2075. }
  2076. // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
  2077. func ModifyCompanyProductLastViewData(companyIdList []int) (err error) {
  2078. defer func() {
  2079. if err != nil {
  2080. go alarm_msg.SendAlarmMsg("修改客户产品的总共阅读次数以及最近阅读时间失败,"+fmt.Sprint("companyIdList:", companyIdList, ";err:", err), 3)
  2081. //go utils.SendEmail("修改客户产品的总共阅读次数以及最近阅读时间失败", fmt.Sprint("companyIdList:", companyIdList, ";err:", err), utils.EmailSendToUsers)
  2082. }
  2083. }()
  2084. wxUserList, err := models.GetWxUserByCompanyIds(companyIdList)
  2085. if err != nil {
  2086. return
  2087. }
  2088. mobileList := make([]string, 0)
  2089. mobileCompanyIdMap := make(map[string]int, 0)
  2090. emailList := make([]string, 0)
  2091. emailCompanyIdMap := make(map[string]int, 0)
  2092. for _, v := range wxUserList {
  2093. if v.Mobile != `` {
  2094. mobileList = append(mobileList, v.Mobile)
  2095. mobileCompanyIdMap[v.Mobile] = v.CompanyId
  2096. }
  2097. if v.Email != `` {
  2098. emailList = append(emailList, v.Email)
  2099. emailCompanyIdMap[v.Email] = v.CompanyId
  2100. }
  2101. }
  2102. // 根据companyId列表获取客户公司的阅读情况
  2103. companyViewRecordList, err := models.GetUserViewHistoryByCompanyIdList(companyIdList)
  2104. if err != nil {
  2105. return
  2106. }
  2107. companyViewRecordMap := make(map[int]*models.CompanyViewRecord)
  2108. for _, v := range companyViewRecordList {
  2109. companyViewRecordMap[v.CompanyId] = v
  2110. }
  2111. for _, companyId := range companyIdList {
  2112. companyViewRecord, ok := companyViewRecordMap[companyId]
  2113. //ficc
  2114. var companyFiccViewTotal, companyRaiViewTotal int
  2115. var companyFiccLastView, companyRaiLastView time.Time
  2116. var companyFiccLastViewStr, companyRaiLastViewStr string
  2117. if ok && companyViewRecord != nil {
  2118. companyFiccViewTotal = companyViewRecord.FiccViewTotal
  2119. companyFiccLastView = companyViewRecord.FiccLastViewTime
  2120. companyRaiViewTotal = companyViewRecord.RaiViewTotal
  2121. companyRaiLastView = companyViewRecord.RaiLastViewTime
  2122. }
  2123. if companyFiccLastView.IsZero() {
  2124. companyFiccLastViewStr = "0000-00-00 00:00:00"
  2125. } else {
  2126. companyFiccLastViewStr = companyFiccLastView.Format(utils.FormatDateTime)
  2127. }
  2128. company.ModifyCompanyProductLastViewData(companyId, 1, companyFiccViewTotal, companyFiccLastViewStr)
  2129. //权益
  2130. if companyRaiLastView.IsZero() {
  2131. companyRaiLastViewStr = "0000-00-00 00:00:00"
  2132. } else {
  2133. companyRaiLastViewStr = companyRaiLastView.Format(utils.FormatDateTime)
  2134. }
  2135. company.ModifyCompanyProductLastViewData(companyId, 2, companyRaiViewTotal, companyRaiLastViewStr)
  2136. }
  2137. return
  2138. }
  2139. // CompanyDeleteBakInfo 删除客户时的备份信息
  2140. type CompanyDeleteBakInfo struct {
  2141. CompanyId int `description:"客户id"`
  2142. CompanyName string `description:"客户名称"`
  2143. CompanyInfo *company.Company `description:"客户主表信息"`
  2144. CompanyProductInfo []*company.CompanyProduct `description:"客户产品信息"`
  2145. CompanyPermissionInfo []*company.CompanyReportPermission `description:"客户产品权限信息"`
  2146. UserSellerRelationInfo []*models.UserSellerRelation `description:"联系人与销售关系信息"`
  2147. UserRecordInfo []*models.UserRecord `description:"联系人关系信息"`
  2148. UserInfo []*models.WxUser `description:"联系人信息"`
  2149. CompanyChartPermissionInfo []*company_user.ChartClassifyPermission `description:"客户图表权限信息"`
  2150. CompanyContract []*company.CompanyContract `description:"客户合同信息"`
  2151. CompanyContractPermission []*company.CompanyContractPermission `description:"客户合同权限信息"`
  2152. OpUserId int `description:"操作人id"`
  2153. OpUserName string `description:"操作人名称"`
  2154. }
  2155. // GetBeforeDeleteCompanyInfo 获取删除客户之前的信息
  2156. func GetBeforeDeleteCompanyInfo(companyId int) (companyProductLists []*company.CompanyProduct, companyReportPermissions []*company.CompanyReportPermission, wxUsers []*models.WxUser, userSellerRelations []*models.UserSellerRelation, companyContracts []*company.CompanyContract, companyContractPermissions []*company.CompanyContractPermission, companyInfo *company.Company, err error) {
  2157. o := orm.NewOrm()
  2158. //删除客户产品
  2159. bakSql := `SELECT * FROM company_product WHERE company_id=? `
  2160. _, err = o.Raw(bakSql, companyId).QueryRows(&companyProductLists)
  2161. if err != nil {
  2162. return
  2163. }
  2164. //删除客户权限
  2165. bakSql = `SELECT * FROM company_report_permission WHERE company_id=? `
  2166. _, err = o.Raw(bakSql, companyId).QueryRows(&companyReportPermissions)
  2167. if err != nil {
  2168. return
  2169. }
  2170. //联系人表
  2171. bakSql = `SELECT * FROM wx_user WHERE company_id=? `
  2172. _, err = o.Raw(bakSql, companyId).QueryRows(&wxUsers)
  2173. if err != nil {
  2174. return
  2175. }
  2176. //联系人 与 销售 关系表
  2177. bakSql = `SELECT * FROM user_seller_relation WHERE company_id=? `
  2178. _, err = o.Raw(bakSql, companyId).QueryRows(&userSellerRelations)
  2179. if err != nil {
  2180. return
  2181. }
  2182. // 合同
  2183. bakSql = `SELECT * FROM company_contract WHERE company_id=? `
  2184. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContracts)
  2185. if err != nil {
  2186. return
  2187. }
  2188. // 合同权限
  2189. bakSql = `SELECT * FROM company_contract_permission WHERE company_id=? `
  2190. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContractPermissions)
  2191. if err != nil {
  2192. return
  2193. }
  2194. // 客户
  2195. bakSql = `SELECT * FROM company WHERE company_id=? `
  2196. err = o.Raw(bakSql, companyId).QueryRow(&companyInfo)
  2197. if err != nil {
  2198. return
  2199. }
  2200. return
  2201. }
  2202. // CheckCompanyReceiveButton 查询领取客户按钮的权限
  2203. func CheckCompanyReceiveButton(adminId int) (receiveEnabled bool, err error) {
  2204. receiveEnabled = true
  2205. receivePermissionInfo, err := company.GetSellerCompanyPermissionByAdminIdType(adminId, 1)
  2206. if err != nil {
  2207. if err.Error() != utils.ErrNoRow() {
  2208. err = errors.New("获取账号权限失败,Err:" + err.Error())
  2209. return
  2210. }
  2211. } else {
  2212. if receivePermissionInfo != nil && receivePermissionInfo.Enabled == 0 {
  2213. receiveEnabled = false
  2214. }
  2215. }
  2216. return
  2217. }
  2218. // AddWxUserOpLog 记录新增用户的日志
  2219. func AddWxUserOpLog(wxUserOpLog company.WxUserOpLog) {
  2220. userSellerRelationList, err := models.GetUserSellerRelationList(wxUserOpLog.UserId)
  2221. if err != nil {
  2222. return
  2223. }
  2224. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2225. wxUserOpLog.UserSellerInfo = string(userSellerRelationInfo)
  2226. company.AddWxUserOpLog(&wxUserOpLog)
  2227. }
  2228. // FilterReadAndContractAuth 根据已购品种和阅读权限获取筛选条件
  2229. func FilterReadAndContractAuth(chartPermissions, contractPermissions, condition string) (cond string, empty bool, err error) {
  2230. cond = condition
  2231. var queryChart, queryContract bool
  2232. if chartPermissions != "" && chartPermissions != "1" {
  2233. queryChart = true
  2234. }
  2235. if contractPermissions != "" && contractPermissions != "1" {
  2236. queryContract = true
  2237. }
  2238. if !queryChart && !queryContract {
  2239. return
  2240. }
  2241. readIds := make([]int, 0)
  2242. buyIds := make([]int, 0)
  2243. // 阅读权限
  2244. if queryChart {
  2245. {
  2246. // 处理权益的主观客观的筛选条件搜索
  2247. ids := make([]int, 0)
  2248. strIdArr := strings.Split(chartPermissions, ",")
  2249. for _, s := range strIdArr {
  2250. v, _ := strconv.Atoi(s)
  2251. ids = append(ids, v)
  2252. }
  2253. if len(ids) == 0 {
  2254. err = fmt.Errorf("权限ID有误")
  2255. return
  2256. }
  2257. names, e := company.GetPermissionNameByPermissionIds(ids)
  2258. if e != nil {
  2259. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2260. return
  2261. }
  2262. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2263. if e != nil {
  2264. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2265. return
  2266. }
  2267. companyIds, e := company.GetCompanyIdsStrByReportPermissionIds(permissionIds)
  2268. if e != nil {
  2269. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2270. return
  2271. }
  2272. readIds = companyIds
  2273. }
  2274. }
  2275. // 已购合同权限
  2276. if queryContract {
  2277. {
  2278. // 处理权益的主观客观的筛选条件搜索
  2279. ids := make([]int, 0)
  2280. strIdArr := strings.Split(contractPermissions, ",")
  2281. for _, s := range strIdArr {
  2282. v, _ := strconv.Atoi(s)
  2283. ids = append(ids, v)
  2284. }
  2285. if len(ids) == 0 {
  2286. err = fmt.Errorf("权限ID有误")
  2287. return
  2288. }
  2289. names, e := company.GetPermissionNameByPermissionIds(ids)
  2290. if e != nil {
  2291. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2292. return
  2293. }
  2294. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2295. if e != nil {
  2296. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2297. return
  2298. }
  2299. companyIds, e := company.GetCompanyIdsStrByContractPermissionIds(permissionIds)
  2300. if e != nil {
  2301. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2302. return
  2303. }
  2304. buyIds = companyIds
  2305. // 勾选了已购品种的, 仅筛选正式客户
  2306. cond += ` AND b.status = '正式'`
  2307. }
  2308. }
  2309. queryIds := make([]int, 0)
  2310. queryIdArr := make([]string, 0)
  2311. // 阅读权限和已购品种同时筛选取两者的companyIds交集
  2312. if queryChart && queryContract {
  2313. queryIds = utils.IntersectInt(readIds, buyIds)
  2314. } else if queryChart && !queryContract {
  2315. queryIds = readIds
  2316. } else if !queryChart && queryContract {
  2317. queryIds = buyIds
  2318. }
  2319. if len(queryIds) == 0 {
  2320. empty = true
  2321. return
  2322. }
  2323. for _, q := range queryIds {
  2324. queryIdArr = append(queryIdArr, strconv.Itoa(q))
  2325. }
  2326. cond += ` AND a.company_id IN (` + strings.Join(queryIdArr, ",") + `) `
  2327. return
  2328. }
  2329. // GetShareCompanyPermissionButton 正式客户共享-权限按钮
  2330. func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId int, item *company.CompanyItem, sysUser *system.Admin) (button *company.ButtonPermission) {
  2331. statuses = strings.Replace(statuses, "(共享)", "", -1)
  2332. statusMap := make(map[int]string)
  2333. statusMap[productId] = statuses
  2334. if strings.Contains(statuses, "/") {
  2335. statusArr := strings.Split(statuses, "/")
  2336. statusMap[1] = statusArr[0]
  2337. statusMap[2] = statusArr[1]
  2338. }
  2339. //roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId
  2340. //所属销售map
  2341. sellerIdMap := make(map[int]string)
  2342. sellerIdMap[productId] = item.SellerIds
  2343. if strings.Contains(item.SellerIds, "/") {
  2344. sellerIdSlice := strings.Split(item.SellerIds, "/")
  2345. sellerIdMap[1] = sellerIdSlice[0]
  2346. sellerIdMap[2] = sellerIdSlice[1]
  2347. }
  2348. //分组map
  2349. groupIdMap := make(map[int]string)
  2350. groupIdMap[productId] = item.GroupIds
  2351. if strings.Contains(item.GroupIds, "/") {
  2352. groupIdSlice := strings.Split(item.GroupIds, "/")
  2353. groupIdMap[1] = groupIdSlice[0]
  2354. groupIdMap[2] = groupIdSlice[1]
  2355. }
  2356. // 查看权限均有
  2357. button = new(company.ButtonPermission)
  2358. button.BtnView = true
  2359. // 超管, FICC管理员
  2360. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2361. button.BtnModifySeller = true
  2362. button.BtnRemarkView = true
  2363. button.BtnServiceRecord = true
  2364. }
  2365. //梁春悦、罗礼智的单独展示
  2366. if sysUser.RoleName == "权益服务组长" || sysUser.RoleName == "权益销售组长(外部)" {
  2367. button.BtnModifySeller = true
  2368. }
  2369. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2370. button.BtnModifySeller = false
  2371. }
  2372. status, _ := statusMap[1]
  2373. //if !ok {
  2374. // return
  2375. //}
  2376. // 客户非关闭状态可见沟通记录按钮
  2377. if status != utils.COMPANY_STATUS_CLOSE {
  2378. button.BtnServiceRecord = true
  2379. }
  2380. // 销售
  2381. sellerArr := []string{
  2382. utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  2383. utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  2384. }
  2385. if !utils.InArrayByStr(sellerArr, roleTypeCode) {
  2386. return
  2387. }
  2388. if status == utils.COMPANY_STATUS_TRY_OUT {
  2389. button.BtnTurnPositive = true
  2390. button.BtnRemarkEdit = true
  2391. button.BtnRemarkView = true
  2392. button.BtnServiceRecord = true
  2393. }
  2394. if status == utils.COMPANY_STATUS_FORMAL {
  2395. button.BtnUpdate = true
  2396. button.BtnAddAgreement = true
  2397. button.BtnTryOut = true
  2398. button.BtnRemarkEdit = true
  2399. button.BtnRemarkView = true
  2400. button.BtnServiceRecord = true
  2401. }
  2402. companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  2403. if companyButton.BtnShare == true {
  2404. button.BtnShare = true
  2405. }
  2406. //备注与历史备注修改 CRM15.9.1
  2407. button.BtnRemarkView = companyButton.BtnRemarkView
  2408. if productId == 2 {
  2409. button.BtnRemarkView = false
  2410. button.BtnRemarkViewHistory = true
  2411. }
  2412. if utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP}, roleTypeCode) {
  2413. button.BtnServiceRecord = false //王芳,权益销售,权益销售组长,这三种身份看不到这个按钮
  2414. }
  2415. return
  2416. }