company.go 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  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. button.BtnRemarkView = true
  855. return
  856. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  857. button.BtnEdit = true
  858. button.BtnDelete = true
  859. button.BtnRemarkView = true
  860. //button.BtnModifySeller = true
  861. button.BtnFreeze = false
  862. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  863. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  864. }
  865. return
  866. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  867. //button.BtnModifySeller = true
  868. button.BtnRemarkView = true
  869. return
  870. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  871. //button.BtnModifySeller = true
  872. button.BtnDelete = true
  873. return
  874. } else if status == utils.COMPANY_STATUS_CLOSE { // 关闭
  875. //button.BtnModifySeller = true
  876. button.BtnDelete = true
  877. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  878. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  879. }
  880. return
  881. } else { //永续
  882. //button.BtnModifySeller = true
  883. button.BtnDelete = true
  884. button.BtnEdit = true
  885. return
  886. }
  887. }
  888. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  889. //查看详情权限
  890. productStatus, hasProduct := productStatusMap[1]
  891. if hasProduct {
  892. button.BtnView = true
  893. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  894. button.BtnModifySeller = true
  895. button.BtnShare = true
  896. return
  897. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  898. button.BtnEdit = true
  899. //button.BtnDelete = true
  900. button.BtnModifySeller = true
  901. button.BtnFreeze = false
  902. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  903. return
  904. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  905. button.BtnModifySeller = true
  906. return
  907. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  908. //button.BtnModifySeller = true
  909. //button.BtnDelete = true
  910. return
  911. } else if productStatus == utils.COMPANY_STATUS_CLOSE { // 关闭
  912. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  913. return
  914. } else { //永续
  915. return
  916. }
  917. } else {
  918. productStatus2, hasProduct2 := productStatusMap[2]
  919. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  920. if hasProduct2 {
  921. //其他产品的流失客户可以有查看权限
  922. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  923. button.BtnView = true //查看权限
  924. }
  925. }
  926. }
  927. return
  928. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  929. //查看详情权限
  930. productStatus, hasProduct := productStatusMap[2]
  931. if hasProduct {
  932. button.BtnView = true
  933. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  934. button.BtnModifySeller = true
  935. button.BtnShare = true
  936. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  937. button.BtnEdit = true
  938. //button.BtnDelete = true
  939. button.BtnModifySeller = true
  940. button.BtnFreeze = false
  941. // CRM14.7.2 权益管理员可以设置试用客户为共享
  942. button.BtnShare = true
  943. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  944. button.BtnModifySeller = true
  945. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  946. //button.BtnDelete = true
  947. } else { //永续
  948. }
  949. } else {
  950. productStatus2, hasProduct2 := productStatusMap[1]
  951. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  952. if hasProduct2 {
  953. //其他产品的流失客户可以有查看权限
  954. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  955. button.BtnView = true //查看权限
  956. }
  957. }
  958. }
  959. return
  960. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  961. //判断该客户是否有ficc权限
  962. productStatus, hasProduct := productStatusMap[1]
  963. if hasProduct {
  964. //如果有权限的话:
  965. //获取当前ficc的销售id
  966. sellerId, hasSellerId := sellerIdMap[1]
  967. //获取当前ficc的销售分组id
  968. groupId, hasGroupId := groupIdMap[1]
  969. //如果是自己客户,那么拥有查看权限
  970. if hasSellerId {
  971. if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  972. button.BtnView = true //显示权限、详情
  973. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  974. button.BtnUpdate = true //服务更新
  975. button.BtnAddAgreement = true //补充协议
  976. button.BtnTryOut = true
  977. button.BtnModifySeller = true
  978. button.BtnShare = true
  979. button.BtnRemarkEdit = true
  980. button.BtnRemarkView = true
  981. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  982. button.BtnEdit = true
  983. button.BtnDelete = true
  984. button.BtnSuspend = true
  985. button.BtnDelay = true
  986. button.BtnTurnPositive = true
  987. button.BtnFreeze = true
  988. button.BtnModifySeller = true
  989. button.BtnRemarkEdit = true
  990. button.BtnRemarkView = true
  991. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  992. button.BtnThaw = true
  993. button.BtnModifySeller = true
  994. button.BtnRemarkEdit = true
  995. button.BtnRemarkView = true
  996. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  997. button.BtnApplyReceive = true
  998. } else { //永续
  999. //button.BtnDelete = true
  1000. }
  1001. } else {
  1002. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1003. button.BtnView = true //显示权限、详情
  1004. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1005. if groupId == sysUserGroupId {
  1006. button.BtnApplyReceive = true
  1007. } else {
  1008. button.BtnReceive = true
  1009. }
  1010. }
  1011. }
  1012. }
  1013. //如果是组长,且该客户属于本组客户
  1014. if authority == 4 && hasGroupId && groupId == sysUserGroupId && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  1015. button.BtnView = true //查看详情权限
  1016. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1017. button.BtnModifySeller = true
  1018. button.BtnShare = true
  1019. button.BtnRemarkView = true
  1020. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1021. button.BtnModifySeller = true
  1022. button.BtnRemarkView = true
  1023. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1024. button.BtnModifySeller = true
  1025. button.BtnRemarkView = true
  1026. //button.BtnThaw = false
  1027. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1028. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1029. button.BtnApplyReceive = true
  1030. } else {
  1031. button.BtnReceive = true
  1032. }
  1033. } else { //永续
  1034. //button.BtnDelete = true
  1035. }
  1036. }
  1037. //如果是ficc销售主管,且该客户属于本组客户
  1038. //获取父级groupId
  1039. groupIdpid, err := company.GetParentIdFromGroup(groupId)
  1040. if err != nil {
  1041. fmt.Println(err.Error())
  1042. }
  1043. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUserGroupId)
  1044. if err != nil {
  1045. fmt.Println(err.Error())
  1046. }
  1047. var pidBool bool
  1048. //处理主管和销售在不同的二三级分组下的情况
  1049. if groupIdpid != nil && sysUserGroupIdpid != nil {
  1050. pidBool = *groupIdpid == *sysUserGroupIdpid || *groupIdpid == sysUserGroupId || groupId == sysUserGroupId || groupId == *sysUserGroupIdpid
  1051. }
  1052. if authority == 2 && hasGroupId && pidBool && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  1053. button.BtnView = true //查看详情权限
  1054. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1055. button.BtnModifySeller = true
  1056. button.BtnShare = true
  1057. button.BtnRemarkView = true
  1058. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1059. button.BtnModifySeller = true
  1060. button.BtnRemarkView = true
  1061. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1062. button.BtnModifySeller = true
  1063. button.BtnRemarkView = true
  1064. //button.BtnThaw = false
  1065. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1066. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1067. button.BtnApplyReceive = true
  1068. } else {
  1069. button.BtnReceive = true
  1070. }
  1071. } else { //永续
  1072. //button.BtnDelete = true
  1073. }
  1074. }
  1075. //ficc同一个大组当作一个小组来处理领取按钮
  1076. var ids []*string
  1077. if groupIdpid != nil && *groupIdpid != 0 {
  1078. ids, err = company.GetGroupIdsByParentId(*groupIdpid)
  1079. if err != nil {
  1080. fmt.Println(err.Error())
  1081. }
  1082. }
  1083. var idSlice []string
  1084. var sid string
  1085. for _, id := range ids {
  1086. idSlice = append(idSlice, *id)
  1087. }
  1088. sid = strings.Join(idSlice, ",")
  1089. if strings.Contains(sid, strconv.Itoa(itemGroupId)) {
  1090. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1091. button.BtnApplyReceive = true
  1092. button.BtnReceive = false
  1093. }
  1094. }
  1095. } else {
  1096. productStatus2, hasProduct2 := productStatusMap[2]
  1097. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1098. if hasProduct2 {
  1099. //如果客户ficc权限是永续,那么也没有其他部门客户的按钮权限
  1100. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1101. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1102. }
  1103. //其他产品的流失客户可以有查看权限
  1104. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1105. button.BtnView = true //查看权限
  1106. }
  1107. }
  1108. }
  1109. return
  1110. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1111. //判断该客户是否有权益权限
  1112. productStatus, hasProduct := productStatusMap[2]
  1113. if hasProduct {
  1114. //如果有权限的话:
  1115. //获取当前 权益 的销售id
  1116. sellerId, hasSellerId := sellerIdMap[2]
  1117. //获取当前 权益 的销售分组id
  1118. groupId, hasGroupId := groupIdMap[2]
  1119. //如果是自己客户,那么拥有查看权限
  1120. if hasSellerId {
  1121. if sellerId == sysUserId ||utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1122. button.BtnView = true //显示权限、详情
  1123. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1124. button.BtnUpdate = true
  1125. button.BtnTryOut = true
  1126. button.BtnModifySeller = true
  1127. //button.BtnShare = true
  1128. button.BtnRemarkEdit = true
  1129. button.BtnRemarkView = true
  1130. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1131. button.BtnEdit = true
  1132. button.BtnDelete = true
  1133. button.BtnSuspend = true
  1134. button.BtnDelay = true
  1135. button.BtnTurnPositive = true
  1136. button.BtnModifySeller = true
  1137. button.BtnFreeze = true
  1138. button.BtnRemarkEdit = true
  1139. button.BtnRemarkView = true
  1140. //button.BtnShare = true
  1141. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1142. button.BtnThaw = true
  1143. button.BtnModifySeller = true
  1144. button.BtnRemarkEdit = true
  1145. button.BtnRemarkView = true
  1146. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1147. button.BtnApplyReceive = true
  1148. } else { //永续
  1149. //button.BtnDelete = true
  1150. }
  1151. } else {
  1152. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1153. button.BtnView = true //显示权限、详情
  1154. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1155. if groupId == sysUserGroupId {
  1156. button.BtnApplyReceive = true
  1157. } else {
  1158. button.BtnReceive = true
  1159. }
  1160. }
  1161. }
  1162. }
  1163. //如果是组长,且该客户属于本组客户
  1164. if authority == 2 && hasGroupId && groupId == sysUserGroupId {
  1165. button.BtnView = true //查看详情权限
  1166. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1167. button.BtnModifySeller = true
  1168. //button.BtnShare = true
  1169. button.BtnRemarkView = true
  1170. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1171. button.BtnModifySeller = true
  1172. button.BtnRemarkView = true
  1173. //button.BtnShare = true
  1174. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1175. button.BtnModifySeller = true
  1176. button.BtnRemarkView = true
  1177. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1178. if sellerId == sysUserId || groupId == sysUserGroupId ||utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1179. button.BtnApplyReceive = true
  1180. } else {
  1181. button.BtnReceive = true
  1182. }
  1183. } else { //永续
  1184. //button.BtnDelete = true
  1185. }
  1186. }
  1187. } else {
  1188. productStatus2, hasProduct2 := productStatusMap[1]
  1189. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1190. if hasProduct2 {
  1191. //如果客户 权益 权限是永续,那么也没有其他部门客户的按钮权限
  1192. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1193. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1194. }
  1195. //其他产品的流失客户可以有查看权限
  1196. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1197. button.BtnView = true //查看权限
  1198. }
  1199. }
  1200. }
  1201. return
  1202. }
  1203. return button
  1204. }
  1205. // GetCompanyPermissionButtonByReceiveEnabled 查询当前销售 "添加客户" 权限来判断按钮权限
  1206. func GetCompanyPermissionButtonByReceiveEnabled(btnItem *company.ButtonPermission, receiveEnabled bool) (buttonNew *company.ButtonPermission) {
  1207. //查询当前销售 "添加客户" 权限是否为禁用
  1208. if !receiveEnabled {
  1209. //申请领取、领取客户、领取其他部门客户按钮权限按钮显示时
  1210. if btnItem.BtnApplyReceive || btnItem.BtnReceive || btnItem.BtnReceiveOther {
  1211. btnItem.BtnApplyReceive = false
  1212. btnItem.BtnReceive = false
  1213. btnItem.BtnReceiveOther = false
  1214. }
  1215. if btnItem.BtnThaw {
  1216. btnItem.BtnThaw = false
  1217. }
  1218. }
  1219. buttonNew = btnItem
  1220. return buttonNew
  1221. }
  1222. //func GetCompanyPermissionButtonOld(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  1223. // button.BtnView = true
  1224. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  1225. // if !strings.Contains(status, "/") {
  1226. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1227. // //button.BtnModifySeller = true
  1228. // return
  1229. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1230. // button.BtnEdit = true
  1231. // button.BtnDelete = true
  1232. // //button.BtnModifySeller = true
  1233. // button.BtnFreeze = false
  1234. // return
  1235. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1236. // //button.BtnModifySeller = true
  1237. // return
  1238. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1239. // //button.BtnModifySeller = true
  1240. // button.BtnDelete = true
  1241. // return
  1242. // } else { //永续
  1243. // //button.BtnModifySeller = true
  1244. // button.BtnDelete = true
  1245. // button.BtnEdit = true
  1246. // return
  1247. // }
  1248. // }
  1249. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1250. // if productId != 1 {
  1251. // return
  1252. // } else {
  1253. // if !strings.Contains(status, "/") {
  1254. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1255. // button.BtnModifySeller = true
  1256. // return
  1257. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1258. // //button.BtnEdit = true
  1259. // //button.BtnDelete = true
  1260. // button.BtnModifySeller = true
  1261. // button.BtnFreeze = false
  1262. // return
  1263. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1264. // //button.BtnModifySeller = true
  1265. // return
  1266. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1267. // //button.BtnModifySeller = true
  1268. // //button.BtnDelete = true
  1269. // return
  1270. // } else { //永续
  1271. // return
  1272. // }
  1273. // }
  1274. // }
  1275. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1276. // if !strings.Contains(status, "/") {
  1277. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1278. // button.BtnModifySeller = true
  1279. // return
  1280. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1281. // //button.BtnEdit = true
  1282. // //button.BtnDelete = true
  1283. // button.BtnModifySeller = true
  1284. // button.BtnFreeze = false
  1285. // return
  1286. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1287. // return
  1288. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1289. // //button.BtnDelete = true
  1290. // return
  1291. // } else { //永续
  1292. // return
  1293. // }
  1294. // }
  1295. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  1296. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1297. // if !strings.Contains(status, "/") {
  1298. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1299. // } else {
  1300. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1301. // statusSlice := strings.Split(status, "/")
  1302. // ficcStatus := statusSlice[0]
  1303. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1304. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1305. // button.BtnApplyReceive = true //申请领取按钮权限
  1306. // } else {
  1307. // button.BtnReceive = true //领取客户按钮权限
  1308. // }
  1309. // return
  1310. // }
  1311. // }
  1312. // return
  1313. // }
  1314. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1315. // return
  1316. // }
  1317. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  1318. // if authority == 2 { //组长
  1319. // if !strings.Contains(status, "/") {
  1320. // if sysUserId == itemSellerId { //自己客户
  1321. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1322. // button.BtnUpdate = true
  1323. // button.BtnModifySeller = true
  1324. // button.BtnTryOut = true
  1325. // return
  1326. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1327. // button.BtnEdit = true
  1328. // button.BtnDelete = true
  1329. // button.BtnSuspend = true
  1330. // button.BtnDelay = true
  1331. // button.BtnTurnPositive = true
  1332. // button.BtnModifySeller = true
  1333. // button.BtnFreeze = true
  1334. // return
  1335. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1336. // button.BtnThaw = true
  1337. // return
  1338. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1339. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1340. // button.BtnApplyReceive = true
  1341. // } else {
  1342. // button.BtnReceive = true
  1343. // }
  1344. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1345. // //button.BtnDelete = true
  1346. // }
  1347. // return
  1348. // } else { //永续
  1349. // button.BtnDelete = true
  1350. // return
  1351. // }
  1352. // } else {
  1353. // if productId == 1 {
  1354. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1355. // button.BtnModifySeller = true
  1356. // return
  1357. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1358. // button.BtnModifySeller = true
  1359. // return
  1360. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1361. // button.BtnThaw = false
  1362. // return
  1363. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1364. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1365. // button.BtnApplyReceive = true
  1366. // } else {
  1367. // button.BtnReceive = true
  1368. // }
  1369. // return
  1370. // } else { //永续
  1371. // button.BtnDelete = true
  1372. // return
  1373. // }
  1374. // } else {
  1375. // //button.BtnReceive = true
  1376. // }
  1377. // }
  1378. // }
  1379. // } else { //销售
  1380. // if !strings.Contains(status, "/") {
  1381. // if itemSellerId == sysUserId {
  1382. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1383. // button.BtnUpdate = true
  1384. // button.BtnTryOut = true
  1385. // return
  1386. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1387. // button.BtnEdit = true
  1388. // button.BtnDelete = true
  1389. // button.BtnSuspend = true
  1390. // button.BtnDelay = true
  1391. // button.BtnTurnPositive = true
  1392. // button.BtnFreeze = true
  1393. // return
  1394. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1395. // button.BtnThaw = true
  1396. // return
  1397. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1398. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1399. // button.BtnApplyReceive = true
  1400. // } else {
  1401. // button.BtnReceive = true
  1402. // }
  1403. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1404. // //button.BtnDelete = true
  1405. // }
  1406. // return
  1407. // } else { //永续
  1408. // button.BtnDelete = true
  1409. // return
  1410. // }
  1411. // } else {
  1412. // if productId == 1 {
  1413. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1414. // return
  1415. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1416. // return
  1417. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1418. // button.BtnThaw = false
  1419. // return
  1420. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1421. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1422. // button.BtnApplyReceive = true
  1423. // } else {
  1424. // button.BtnReceive = true
  1425. // }
  1426. // return
  1427. // } else { //永续
  1428. // button.BtnDelete = true
  1429. // return
  1430. // }
  1431. // } else {
  1432. // //button.BtnReceive = true
  1433. // }
  1434. // }
  1435. // } else {
  1436. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1437. // statusSlice := strings.Split(status, "/")
  1438. // ficcStatus := statusSlice[0]
  1439. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1440. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1441. // button.BtnApplyReceive = true //申请领取按钮权限
  1442. // } else {
  1443. // button.BtnReceive = true //领取客户按钮权限
  1444. // }
  1445. // return
  1446. // }
  1447. // }
  1448. // }
  1449. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  1450. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1451. // return
  1452. // }
  1453. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1454. // if !strings.Contains(status, "/") {
  1455. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1456. // } else {
  1457. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1458. // statusSlice := strings.Split(status, "/")
  1459. // raiStatus := statusSlice[1]
  1460. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1461. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1462. // button.BtnApplyReceive = true //申请领取按钮权限
  1463. // } else {
  1464. // button.BtnReceive = true //领取客户按钮权限
  1465. // }
  1466. // return
  1467. // }
  1468. // }
  1469. // return
  1470. // }
  1471. // if !strings.Contains(status, "/") {
  1472. // if authority == 2 { //组长
  1473. // if itemSellerId == sysUserId {
  1474. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1475. // button.BtnUpdate = true
  1476. // button.BtnModifySeller = true
  1477. // button.BtnTryOut = true
  1478. // return
  1479. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1480. // button.BtnEdit = true
  1481. // button.BtnDelete = true
  1482. // button.BtnSuspend = true
  1483. // button.BtnDelay = true
  1484. // button.BtnTurnPositive = true
  1485. // button.BtnModifySeller = true
  1486. // button.BtnFreeze = true
  1487. // return
  1488. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1489. // button.BtnThaw = true
  1490. // return
  1491. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1492. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1493. // button.BtnApplyReceive = true
  1494. // } else {
  1495. // button.BtnReceive = true
  1496. // }
  1497. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1498. // //button.BtnDelete = true
  1499. // }
  1500. // return
  1501. // } else { //永续
  1502. // button.BtnDelete = true
  1503. // return
  1504. // }
  1505. // } else {
  1506. // if productId == 1 {
  1507. // //button.BtnReceive = true
  1508. // } else {
  1509. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1510. // button.BtnModifySeller = true
  1511. // return
  1512. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1513. // button.BtnModifySeller = true
  1514. // return
  1515. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1516. // button.BtnThaw = false
  1517. // return
  1518. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1519. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1520. // button.BtnApplyReceive = true
  1521. // } else {
  1522. // button.BtnReceive = true
  1523. // }
  1524. // return
  1525. // } else { //永续
  1526. // button.BtnDelete = true
  1527. // return
  1528. // }
  1529. // }
  1530. // }
  1531. // } else {
  1532. // if itemSellerId == sysUserId {
  1533. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1534. // button.BtnUpdate = true
  1535. // button.BtnTryOut = true
  1536. // return
  1537. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1538. // button.BtnEdit = true
  1539. // button.BtnDelete = true
  1540. // button.BtnSuspend = true
  1541. // button.BtnDelay = true
  1542. // button.BtnTurnPositive = true
  1543. // button.BtnFreeze = true
  1544. // return
  1545. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1546. // button.BtnThaw = true
  1547. // return
  1548. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1549. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1550. // button.BtnApplyReceive = true //申请领取按钮权限
  1551. // } else {
  1552. // button.BtnReceive = true //领取客户按钮权限
  1553. // }
  1554. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1555. // //button.BtnDelete = true
  1556. // }
  1557. // return
  1558. // } else { //永续
  1559. // button.BtnDelete = true
  1560. // return
  1561. // }
  1562. // } else {
  1563. // if productId == 1 {
  1564. // //button.BtnReceive = true
  1565. // } else {
  1566. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1567. // return
  1568. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1569. // return
  1570. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1571. // button.BtnThaw = false
  1572. // return
  1573. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1574. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1575. // button.BtnApplyReceive = true //申请领取按钮权限
  1576. // } else {
  1577. // button.BtnReceive = true //领取客户按钮权限
  1578. // }
  1579. // return
  1580. // } else { //永续
  1581. // button.BtnDelete = true
  1582. // return
  1583. // }
  1584. // }
  1585. // }
  1586. // }
  1587. // } else {
  1588. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1589. // statusSlice := strings.Split(status, "/")
  1590. // raiStatus := statusSlice[1]
  1591. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1592. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1593. // button.BtnApplyReceive = true //申请领取按钮权限
  1594. // } else {
  1595. // button.BtnReceive = true //领取客户按钮权限
  1596. // }
  1597. // return
  1598. // }
  1599. // }
  1600. // }
  1601. // return button
  1602. //}
  1603. // 校验当前操作员是否具有联系人权限是否有操作权限
  1604. func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId, shareSellerId int, status string) (ok bool) {
  1605. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1606. ok = true
  1607. return
  1608. }
  1609. if sysUserId == itemSellerId || shareSellerId == sysUserId {
  1610. ok = true
  1611. //如果客户状态是流失,那么就无法操作
  1612. if status == utils.COMPANY_STATUS_LOSE || status == utils.COMPANY_STATUS_CLOSE {
  1613. ok = false
  1614. return
  1615. }
  1616. return
  1617. } else {
  1618. if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1619. //如果是ficc类型,同时当前账户是ficc管理员
  1620. ok = true
  1621. } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1622. //如果是权益类型,同时当前账户是 权益管理员
  1623. ok = true
  1624. }
  1625. }
  1626. return
  1627. }
  1628. // 校验当前操作员是否具给联系人开通个人研选的权限
  1629. func CheckCompanyUserYanXuanButton(roleTypeCode string, adminMobile string) (ok bool, err error) {
  1630. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1631. ok = true
  1632. return
  1633. }
  1634. crmConfig, err := company.GetConfigDetailByCode("rai_wx_user_yanxuan_button")
  1635. if err != nil {
  1636. return
  1637. }
  1638. sliceMobile := strings.Split(crmConfig.ConfigValue, ",")
  1639. for _, v := range sliceMobile {
  1640. if v == adminMobile {
  1641. ok = true
  1642. return
  1643. }
  1644. }
  1645. return
  1646. }
  1647. // GenerateOpenCompanyCode 生成第三方code编号
  1648. func GenerateOpenCompanyCode(companyId int) (openCode string) {
  1649. openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
  1650. return
  1651. }
  1652. // GenerateOpenCompanyProductCode 生成客户产品第三方code编号
  1653. func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
  1654. openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
  1655. return
  1656. }
  1657. // GetApplyTurnContractType
  1658. // 获取客户申请合同类型
  1659. func GetApplyTurnContractType(companyId, productId int) (contractType string, err error) {
  1660. //合同类型
  1661. contractType = "新签合同"
  1662. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  1663. if err != nil {
  1664. if err.Error() == utils.ErrNoRow() {
  1665. err = nil
  1666. return
  1667. }
  1668. err = errors.New("获取客户信息失败,Err:" + err.Error())
  1669. return
  1670. }
  1671. // 当前客户产品状态为试用,那么是续约合同
  1672. if companyProduct.Status == "正式" {
  1673. contractType = "续约合同"
  1674. }
  1675. var condition string
  1676. var pars []interface{}
  1677. condition += " AND product_id = ?"
  1678. pars = append(pars, productId)
  1679. condition += " AND status = ?"
  1680. pars = append(pars, 1)
  1681. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  1682. if err != nil {
  1683. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1684. return
  1685. }
  1686. if len(list) > 0 {
  1687. contractType = "续约合同"
  1688. }
  1689. //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  1690. total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  1691. if err != nil {
  1692. err = errors.New("查询用户变更记录异常,Err:" + err.Error())
  1693. return
  1694. }
  1695. if total > 0 {
  1696. contractType = "续约合同"
  1697. }
  1698. return
  1699. }
  1700. // GetLastContractPermissionList
  1701. // 获取客户的最近合同的权限期限
  1702. func GetLastContractPermissionList(companyId, productId int) (permissionMap map[int]company.PermissionLookItem, err error) {
  1703. permissionMap = map[int]company.PermissionLookItem{}
  1704. contractList, err := company.GetCompanyWillContractList(companyId, productId)
  1705. if err != nil {
  1706. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1707. return
  1708. }
  1709. for _, contractInfo := range contractList {
  1710. permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
  1711. if permissionErr != nil {
  1712. err = errors.New("获取合同信息失败,Err:" + permissionErr.Error())
  1713. return
  1714. }
  1715. for _, v := range permissionList {
  1716. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1717. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1718. if tmpErr != nil {
  1719. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1720. return
  1721. }
  1722. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1723. if err != nil {
  1724. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1725. return
  1726. }
  1727. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1728. if nowEndDateTime.After(perEndDateTime) {
  1729. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1730. ChartPermissionId: v.ChartPermissionId,
  1731. PermissionName: v.ChartPermissionName,
  1732. StartDate: v.StartDate,
  1733. EndDate: v.EndDate,
  1734. //Status string `description:"'正式','试用','关闭'"`
  1735. //ExpireDay string `description:"到期天数"`
  1736. ClassifyName: v.ClassifyName,
  1737. }
  1738. }
  1739. } else {
  1740. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1741. ChartPermissionId: v.ChartPermissionId,
  1742. PermissionName: v.ChartPermissionName,
  1743. StartDate: v.StartDate,
  1744. EndDate: v.EndDate,
  1745. //Status string `description:"'正式','试用','关闭'"`
  1746. //ExpireDay string `description:"到期天数"`
  1747. ClassifyName: v.ClassifyName,
  1748. }
  1749. }
  1750. }
  1751. }
  1752. //获取权限
  1753. permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
  1754. if permissionErr != nil {
  1755. err = errors.New("获取权限失败,Err:" + permissionErr.Error())
  1756. return
  1757. }
  1758. for _, v := range permissionList {
  1759. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1760. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1761. if tmpErr != nil {
  1762. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1763. return
  1764. }
  1765. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1766. if err != nil {
  1767. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1768. return
  1769. }
  1770. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1771. if nowEndDateTime.After(perEndDateTime) {
  1772. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1773. ChartPermissionId: v.ChartPermissionId,
  1774. PermissionName: v.PermissionName,
  1775. StartDate: v.StartDate,
  1776. EndDate: v.EndDate,
  1777. //Status string `description:"'正式','试用','关闭'"`
  1778. //ExpireDay string `description:"到期天数"`
  1779. ClassifyName: v.ClassifyName,
  1780. }
  1781. }
  1782. } else {
  1783. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1784. ChartPermissionId: v.ChartPermissionId,
  1785. PermissionName: v.PermissionName,
  1786. StartDate: v.StartDate,
  1787. EndDate: v.EndDate,
  1788. //Status string `description:"'正式','试用','关闭'"`
  1789. //ExpireDay string `description:"到期天数"`
  1790. ClassifyName: v.ClassifyName,
  1791. }
  1792. }
  1793. }
  1794. return
  1795. }
  1796. // GetFiccLastUserViewHistoryByCompanyIds 根据客户id集合map获取ficc最后一次阅读时间
  1797. func GetFiccLastUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTime map[int]time.Time, err error) {
  1798. //user_view_record mobile
  1799. companyViewTime = make(map[int]time.Time)
  1800. userViewList, err := models.GetLastUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1801. if err != nil {
  1802. return
  1803. }
  1804. for _, userView := range userViewList {
  1805. companyViewTime[userView.CompanyId] = userView.ViewTime
  1806. }
  1807. //user_view_record email
  1808. userViewList, err = models.GetLastUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1809. if err != nil {
  1810. return
  1811. }
  1812. checkLastTime(companyViewTime, userViewList)
  1813. //AdvisoryArticleViewRecord mobile
  1814. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1815. if err != nil {
  1816. return
  1817. }
  1818. checkLastTime(companyViewTime, userViewList)
  1819. //AdvisoryArticleViewRecord email
  1820. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1821. if err != nil {
  1822. return
  1823. }
  1824. checkLastTime(companyViewTime, userViewList)
  1825. //ReportViewRecord mobile
  1826. mobileOrEmailViewList, err := models.GetLastReportViewRecordByMobileList(mobileList)
  1827. if err != nil {
  1828. return
  1829. }
  1830. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, mobileCompanyIdMap)
  1831. //ReportViewRecord email
  1832. mobileOrEmailViewList, err = models.GetLastReportViewRecordByEmailList(emailList)
  1833. if err != nil {
  1834. return
  1835. }
  1836. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, emailCompanyIdMap)
  1837. //UserViewStatistics mobile
  1838. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1839. if err != nil {
  1840. return
  1841. }
  1842. checkLastTime(companyViewTime, userViewList)
  1843. //UserViewStatistics email
  1844. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1845. if err != nil {
  1846. return
  1847. }
  1848. checkLastTime(companyViewTime, userViewList)
  1849. return
  1850. }
  1851. // GetRaiLastUserViewHistoryByCompanyIds 根据客户id集合map获取权益最后一次阅读时间
  1852. func GetRaiLastUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTime map[int]time.Time, err error) {
  1853. //CygxArticleViewRecord mobile
  1854. companyViewTime = make(map[int]time.Time)
  1855. userViewList, err := models.GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1856. if err != nil {
  1857. return
  1858. }
  1859. for _, userView := range userViewList {
  1860. companyViewTime[userView.CompanyId] = userView.ViewTime
  1861. }
  1862. //CygxArticleViewRecord email
  1863. userViewList, err = models.GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1864. if err != nil {
  1865. return
  1866. }
  1867. checkLastTime(companyViewTime, userViewList)
  1868. return
  1869. }
  1870. // checkLastTime 检测最后的时间并重新赋值
  1871. func checkLastTime(companyViewTime map[int]time.Time, userViewList []*models.CompanyLastViewSlice) {
  1872. for _, userView := range userViewList {
  1873. if viewTime, ok := companyViewTime[userView.CompanyId]; ok {
  1874. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1875. companyViewTime[userView.CompanyId] = userView.ViewTime
  1876. }
  1877. } else { //如果没有数据,那么直接赋值
  1878. companyViewTime[userView.CompanyId] = userView.ViewTime
  1879. }
  1880. }
  1881. return
  1882. }
  1883. // checkMobileOrEmailLastTime 根据用户信息检测最后的时间并重新赋值
  1884. func checkMobileOrEmailLastTime(companyViewTime map[int]time.Time, userViewList []*models.MobileOrEmailLastViewSlice, companyMap map[string]int) {
  1885. for _, userView := range userViewList {
  1886. // 先找到客户id
  1887. companyId, ok := companyMap[userView.Mobile]
  1888. if !ok {
  1889. continue
  1890. }
  1891. // 相同客户id的数据进行比较
  1892. if viewTime, ok := companyViewTime[companyId]; ok {
  1893. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1894. companyViewTime[companyId] = userView.ViewTime
  1895. }
  1896. } else { //如果没有数据,那么直接赋值
  1897. companyViewTime[companyId] = userView.ViewTime
  1898. }
  1899. }
  1900. return
  1901. }
  1902. // GetFiccCountUserViewHistoryByCompanyIds 根据客户id集合map获取ficc的阅读次数
  1903. func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTotal map[int]int, err error) {
  1904. //user_view_record mobile
  1905. companyViewTotal = make(map[int]int)
  1906. userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1907. if err != nil {
  1908. return
  1909. }
  1910. for _, userView := range userViewList {
  1911. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1912. }
  1913. userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1914. if err != nil {
  1915. return
  1916. }
  1917. checkCount(companyViewTotal, userViewList)
  1918. //AdvisoryArticleViewRecord mobile
  1919. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1920. if err != nil {
  1921. return
  1922. }
  1923. checkCount(companyViewTotal, userViewList)
  1924. //AdvisoryArticleViewRecord email
  1925. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1926. if err != nil {
  1927. return
  1928. }
  1929. checkCount(companyViewTotal, userViewList)
  1930. //ReportViewRecord mobile
  1931. mobileOrEmailViewList, err := models.GetCountReportViewRecordByMobileList(mobileList)
  1932. if err != nil {
  1933. return
  1934. }
  1935. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, mobileCompanyIdMap)
  1936. //ReportViewRecord email
  1937. mobileOrEmailViewList, err = models.GetCountReportViewRecordByEmailList(emailList)
  1938. if err != nil {
  1939. return
  1940. }
  1941. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, emailCompanyIdMap)
  1942. //UserViewStatistics mobile
  1943. userViewList, err = models.GetUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1944. if err != nil {
  1945. return
  1946. }
  1947. checkCount(companyViewTotal, userViewList)
  1948. //UserViewStatistics email
  1949. userViewList, err = models.GetUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1950. if err != nil {
  1951. return
  1952. }
  1953. checkCount(companyViewTotal, userViewList)
  1954. return
  1955. }
  1956. // GetRaiCountUserViewHistoryByCompanyIds 根据客户id集合map获取权益的阅读次数
  1957. func GetRaiCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1958. //CygxArticleViewRecord mobile
  1959. companyViewTotal = make(map[int]int)
  1960. userViewList, err := models.GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1961. if err != nil {
  1962. return
  1963. }
  1964. for _, userView := range userViewList {
  1965. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1966. }
  1967. //CygxArticleViewRecord email
  1968. userViewList, err = models.GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1969. if err != nil {
  1970. return
  1971. }
  1972. checkCount(companyViewTotal, userViewList)
  1973. return
  1974. }
  1975. // GetAllCountUserViewHistoryByCompanyIds 根据客户id集合map获取所有的阅读次数
  1976. //func GetAllCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1977. // companyViewTotal = make(map[int]int)
  1978. // companyFiccViewTotal, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1979. // if err != nil {
  1980. // return
  1981. // }
  1982. //
  1983. // companyRaiViewTotal, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1984. // if err != nil {
  1985. // return
  1986. // }
  1987. //
  1988. // companyIdList := strings.Split(companyIdStr, ",")
  1989. //
  1990. // for _, companyIdStr := range companyIdList {
  1991. // companyId, _ := strconv.Atoi(companyIdStr)
  1992. // ficcTotal, ok := companyFiccViewTotal[companyId]
  1993. // if !ok {
  1994. // ficcTotal = 0
  1995. // }
  1996. // raiTotal, ok := companyRaiViewTotal[companyId]
  1997. // if !ok {
  1998. // raiTotal = 0
  1999. // }
  2000. // companyViewTotal[companyId] = ficcTotal + raiTotal
  2001. // }
  2002. // return
  2003. //}
  2004. func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
  2005. for _, userView := range userViewList {
  2006. if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
  2007. companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
  2008. } else { //如果没有数据,那么直接赋值
  2009. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  2010. }
  2011. }
  2012. return
  2013. }
  2014. // checkMobileOrEmailCount 根据手机号或者邮箱进行数据比较
  2015. func checkMobileOrEmailCount(companyViewTotal map[int]int, mobileOrEmailViewList []*models.MobileOrEmailViewTotalSlice, companyMap map[string]int) {
  2016. for _, userView := range mobileOrEmailViewList {
  2017. // 先找到客户id
  2018. companyId, ok := companyMap[userView.Mobile]
  2019. if !ok {
  2020. continue
  2021. }
  2022. // 相同客户id的数据进行比较
  2023. if viewTotal, ok := companyViewTotal[companyId]; ok {
  2024. companyViewTotal[companyId] = viewTotal + userView.ViewTotal
  2025. } else { //如果没有数据,那么直接赋值
  2026. companyViewTotal[companyId] = userView.ViewTotal
  2027. }
  2028. }
  2029. return
  2030. }
  2031. // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
  2032. func ModifyCompanyProductLastViewData(companyIdList []int) (err error) {
  2033. defer func() {
  2034. if err != nil {
  2035. go alarm_msg.SendAlarmMsg("修改客户产品的总共阅读次数以及最近阅读时间失败,"+fmt.Sprint("companyIdList:", companyIdList, ";err:", err), 3)
  2036. //go utils.SendEmail("修改客户产品的总共阅读次数以及最近阅读时间失败", fmt.Sprint("companyIdList:", companyIdList, ";err:", err), utils.EmailSendToUsers)
  2037. }
  2038. }()
  2039. wxUserList, err := models.GetWxUserByCompanyIds(companyIdList)
  2040. if err != nil {
  2041. return
  2042. }
  2043. mobileList := make([]string, 0)
  2044. mobileCompanyIdMap := make(map[string]int, 0)
  2045. emailList := make([]string, 0)
  2046. emailCompanyIdMap := make(map[string]int, 0)
  2047. for _, v := range wxUserList {
  2048. if v.Mobile != `` {
  2049. mobileList = append(mobileList, v.Mobile)
  2050. mobileCompanyIdMap[v.Mobile] = v.CompanyId
  2051. }
  2052. if v.Email != `` {
  2053. emailList = append(emailList, v.Email)
  2054. emailCompanyIdMap[v.Email] = v.CompanyId
  2055. }
  2056. }
  2057. // 根据companyId列表获取客户公司的阅读情况
  2058. companyViewRecordList, err := models.GetUserViewHistoryByCompanyIdList(companyIdList)
  2059. if err != nil {
  2060. return
  2061. }
  2062. companyViewRecordMap := make(map[int]*models.CompanyViewRecord)
  2063. for _, v := range companyViewRecordList {
  2064. companyViewRecordMap[v.CompanyId] = v
  2065. }
  2066. for _, companyId := range companyIdList {
  2067. companyViewRecord, ok := companyViewRecordMap[companyId]
  2068. //ficc
  2069. var companyFiccViewTotal, companyRaiViewTotal int
  2070. var companyFiccLastView, companyRaiLastView time.Time
  2071. var companyFiccLastViewStr, companyRaiLastViewStr string
  2072. if ok && companyViewRecord != nil {
  2073. companyFiccViewTotal = companyViewRecord.FiccViewTotal
  2074. companyFiccLastView = companyViewRecord.FiccLastViewTime
  2075. companyRaiViewTotal = companyViewRecord.RaiViewTotal
  2076. companyRaiLastView = companyViewRecord.RaiLastViewTime
  2077. }
  2078. if companyFiccLastView.IsZero() {
  2079. companyFiccLastViewStr = "0000-00-00 00:00:00"
  2080. } else {
  2081. companyFiccLastViewStr = companyFiccLastView.Format(utils.FormatDateTime)
  2082. }
  2083. company.ModifyCompanyProductLastViewData(companyId, 1, companyFiccViewTotal, companyFiccLastViewStr)
  2084. //权益
  2085. if companyRaiLastView.IsZero() {
  2086. companyRaiLastViewStr = "0000-00-00 00:00:00"
  2087. } else {
  2088. companyRaiLastViewStr = companyRaiLastView.Format(utils.FormatDateTime)
  2089. }
  2090. company.ModifyCompanyProductLastViewData(companyId, 2, companyRaiViewTotal, companyRaiLastViewStr)
  2091. }
  2092. return
  2093. }
  2094. // CompanyDeleteBakInfo 删除客户时的备份信息
  2095. type CompanyDeleteBakInfo struct {
  2096. CompanyId int `description:"客户id"`
  2097. CompanyName string `description:"客户名称"`
  2098. CompanyInfo *company.Company `description:"客户主表信息"`
  2099. CompanyProductInfo []*company.CompanyProduct `description:"客户产品信息"`
  2100. CompanyPermissionInfo []*company.CompanyReportPermission `description:"客户产品权限信息"`
  2101. UserSellerRelationInfo []*models.UserSellerRelation `description:"联系人与销售关系信息"`
  2102. UserRecordInfo []*models.UserRecord `description:"联系人关系信息"`
  2103. UserInfo []*models.WxUser `description:"联系人信息"`
  2104. CompanyChartPermissionInfo []*company_user.ChartClassifyPermission `description:"客户图表权限信息"`
  2105. CompanyContract []*company.CompanyContract `description:"客户合同信息"`
  2106. CompanyContractPermission []*company.CompanyContractPermission `description:"客户合同权限信息"`
  2107. OpUserId int `description:"操作人id"`
  2108. OpUserName string `description:"操作人名称"`
  2109. }
  2110. // GetBeforeDeleteCompanyInfo 获取删除客户之前的信息
  2111. 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) {
  2112. o := orm.NewOrm()
  2113. //删除客户产品
  2114. bakSql := `SELECT * FROM company_product WHERE company_id=? `
  2115. _, err = o.Raw(bakSql, companyId).QueryRows(&companyProductLists)
  2116. if err != nil {
  2117. return
  2118. }
  2119. //删除客户权限
  2120. bakSql = `SELECT * FROM company_report_permission WHERE company_id=? `
  2121. _, err = o.Raw(bakSql, companyId).QueryRows(&companyReportPermissions)
  2122. if err != nil {
  2123. return
  2124. }
  2125. //联系人表
  2126. bakSql = `SELECT * FROM wx_user WHERE company_id=? `
  2127. _, err = o.Raw(bakSql, companyId).QueryRows(&wxUsers)
  2128. if err != nil {
  2129. return
  2130. }
  2131. //联系人 与 销售 关系表
  2132. bakSql = `SELECT * FROM user_seller_relation WHERE company_id=? `
  2133. _, err = o.Raw(bakSql, companyId).QueryRows(&userSellerRelations)
  2134. if err != nil {
  2135. return
  2136. }
  2137. // 合同
  2138. bakSql = `SELECT * FROM company_contract WHERE company_id=? `
  2139. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContracts)
  2140. if err != nil {
  2141. return
  2142. }
  2143. // 合同权限
  2144. bakSql = `SELECT * FROM company_contract_permission WHERE company_id=? `
  2145. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContractPermissions)
  2146. if err != nil {
  2147. return
  2148. }
  2149. // 客户
  2150. bakSql = `SELECT * FROM company WHERE company_id=? `
  2151. err = o.Raw(bakSql, companyId).QueryRow(&companyInfo)
  2152. if err != nil {
  2153. return
  2154. }
  2155. return
  2156. }
  2157. // CheckCompanyReceiveButton 查询领取客户按钮的权限
  2158. func CheckCompanyReceiveButton(adminId int) (receiveEnabled bool, err error) {
  2159. receiveEnabled = true
  2160. receivePermissionInfo, err := company.GetSellerCompanyPermissionByAdminIdType(adminId, 1)
  2161. if err != nil {
  2162. if err.Error() != utils.ErrNoRow() {
  2163. err = errors.New("获取账号权限失败,Err:" + err.Error())
  2164. return
  2165. }
  2166. } else {
  2167. if receivePermissionInfo != nil && receivePermissionInfo.Enabled == 0 {
  2168. receiveEnabled = false
  2169. }
  2170. }
  2171. return
  2172. }
  2173. // AddWxUserOpLog 记录新增用户的日志
  2174. func AddWxUserOpLog(wxUserOpLog company.WxUserOpLog) {
  2175. userSellerRelationList, err := models.GetUserSellerRelationList(wxUserOpLog.UserId)
  2176. if err != nil {
  2177. return
  2178. }
  2179. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2180. wxUserOpLog.UserSellerInfo = string(userSellerRelationInfo)
  2181. company.AddWxUserOpLog(&wxUserOpLog)
  2182. }
  2183. // FilterReadAndContractAuth 根据已购品种和阅读权限获取筛选条件
  2184. func FilterReadAndContractAuth(chartPermissions, contractPermissions, condition string) (cond string, empty bool, err error) {
  2185. cond = condition
  2186. var queryChart, queryContract bool
  2187. if chartPermissions != "" && chartPermissions != "1" {
  2188. queryChart = true
  2189. }
  2190. if contractPermissions != "" && contractPermissions != "1" {
  2191. queryContract = true
  2192. }
  2193. if !queryChart && !queryContract {
  2194. return
  2195. }
  2196. readIds := make([]int, 0)
  2197. buyIds := make([]int, 0)
  2198. // 阅读权限
  2199. if queryChart {
  2200. {
  2201. // 处理权益的主观客观的筛选条件搜索
  2202. ids := make([]int, 0)
  2203. strIdArr := strings.Split(chartPermissions, ",")
  2204. for _, s := range strIdArr {
  2205. v, _ := strconv.Atoi(s)
  2206. ids = append(ids, v)
  2207. }
  2208. if len(ids) == 0 {
  2209. err = fmt.Errorf("权限ID有误")
  2210. return
  2211. }
  2212. names, e := company.GetPermissionNameByPermissionIds(ids)
  2213. if e != nil {
  2214. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2215. return
  2216. }
  2217. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2218. if e != nil {
  2219. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2220. return
  2221. }
  2222. companyIds, e := company.GetCompanyIdsStrByReportPermissionIds(permissionIds)
  2223. if e != nil {
  2224. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2225. return
  2226. }
  2227. readIds = companyIds
  2228. }
  2229. }
  2230. // 已购合同权限
  2231. if queryContract {
  2232. {
  2233. // 处理权益的主观客观的筛选条件搜索
  2234. ids := make([]int, 0)
  2235. strIdArr := strings.Split(contractPermissions, ",")
  2236. for _, s := range strIdArr {
  2237. v, _ := strconv.Atoi(s)
  2238. ids = append(ids, v)
  2239. }
  2240. if len(ids) == 0 {
  2241. err = fmt.Errorf("权限ID有误")
  2242. return
  2243. }
  2244. names, e := company.GetPermissionNameByPermissionIds(ids)
  2245. if e != nil {
  2246. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2247. return
  2248. }
  2249. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2250. if e != nil {
  2251. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2252. return
  2253. }
  2254. companyIds, e := company.GetCompanyIdsStrByContractPermissionIds(permissionIds)
  2255. if e != nil {
  2256. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2257. return
  2258. }
  2259. buyIds = companyIds
  2260. // 勾选了已购品种的, 仅筛选正式客户
  2261. cond += ` AND b.status = '正式'`
  2262. }
  2263. }
  2264. queryIds := make([]int, 0)
  2265. queryIdArr := make([]string, 0)
  2266. // 阅读权限和已购品种同时筛选取两者的companyIds交集
  2267. if queryChart && queryContract {
  2268. queryIds = utils.IntersectInt(readIds, buyIds)
  2269. } else if queryChart && !queryContract {
  2270. queryIds = readIds
  2271. } else if !queryChart && queryContract {
  2272. queryIds = buyIds
  2273. }
  2274. if len(queryIds) == 0 {
  2275. empty = true
  2276. return
  2277. }
  2278. for _, q := range queryIds {
  2279. queryIdArr = append(queryIdArr, strconv.Itoa(q))
  2280. }
  2281. cond += ` AND a.company_id IN (` + strings.Join(queryIdArr, ",") + `) `
  2282. return
  2283. }
  2284. // GetShareCompanyPermissionButton 正式客户共享-权限按钮
  2285. func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId int, item *company.CompanyItem, sysUser *system.Admin) (button *company.ButtonPermission) {
  2286. statusMap := make(map[int]string)
  2287. statusMap[productId] = statuses
  2288. if strings.Contains(statuses, "/") {
  2289. statusArr := strings.Split(statuses, "/")
  2290. statusMap[1] = statusArr[0]
  2291. statusMap[2] = statusArr[1]
  2292. }
  2293. //roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId
  2294. //所属销售map
  2295. sellerIdMap := make(map[int]string)
  2296. sellerIdMap[productId] = item.SellerIds
  2297. if strings.Contains(item.SellerIds, "/") {
  2298. sellerIdSlice := strings.Split(item.SellerIds, "/")
  2299. sellerIdMap[1] = sellerIdSlice[0]
  2300. sellerIdMap[2] = sellerIdSlice[1]
  2301. }
  2302. //分组map
  2303. groupIdMap := make(map[int]string)
  2304. groupIdMap[productId] = item.GroupIds
  2305. if strings.Contains(item.GroupIds, "/") {
  2306. groupIdSlice := strings.Split(item.GroupIds, "/")
  2307. groupIdMap[1] = groupIdSlice[0]
  2308. groupIdMap[2] = groupIdSlice[1]
  2309. }
  2310. // 查看权限均有
  2311. button = new(company.ButtonPermission)
  2312. button.BtnView = true
  2313. // 超管, FICC管理员
  2314. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2315. button.BtnModifySeller = true
  2316. button.BtnRemarkView = true
  2317. button.BtnServiceRecord = true
  2318. }
  2319. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2320. button.BtnModifySeller = false
  2321. }
  2322. status, _ := statusMap[1]
  2323. //if !ok {
  2324. // return
  2325. //}
  2326. // 销售
  2327. sellerArr := []string{
  2328. utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  2329. utils.ROLE_TYPE_CODE_RAI_GROUP,utils.ROLE_TYPE_CODE_RAI_SELLER,utils.ROLE_TYPE_CODE_RAI_ADMIN,
  2330. }
  2331. if !utils.InArrayByStr(sellerArr, roleTypeCode) {
  2332. return
  2333. }
  2334. if status == utils.COMPANY_STATUS_TRY_OUT {
  2335. button.BtnTurnPositive = true
  2336. button.BtnRemarkEdit = true
  2337. button.BtnRemarkView = true
  2338. button.BtnServiceRecord = true
  2339. }
  2340. if status == utils.COMPANY_STATUS_FORMAL {
  2341. button.BtnUpdate = true
  2342. button.BtnAddAgreement = true
  2343. button.BtnTryOut = true
  2344. button.BtnRemarkEdit = true
  2345. button.BtnRemarkView = true
  2346. button.BtnServiceRecord = true
  2347. }
  2348. companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  2349. if companyButton.BtnShare == true {
  2350. button.BtnShare = true
  2351. }
  2352. return
  2353. }