SearchConditionTrait.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * 客户模块查询条件
  4. *
  5. * @author fanqi
  6. * @date 2021-03-09
  7. */
  8. namespace app\crm\traits;
  9. trait SearchConditionTrait
  10. {
  11. /**
  12. * 联系人tab列表查询条件(权限)
  13. *
  14. * @param $userId 当前登录ID
  15. * @author fanqi
  16. * @date 2021-03-09
  17. * @return \Closure
  18. */
  19. public function getContactsSearchWhere($userId)
  20. {
  21. $userModel = new \app\admin\model\User();
  22. $authUserIds = $userModel->getUserByPer('crm', 'contacts', 'index');
  23. $authMapData['auth_user_ids'] = $authUserIds;
  24. $authMapData['user_id'] = $userId;
  25. return $this->getSearchAuthWhere($authMapData);
  26. }
  27. /**
  28. * 商机tab列表查询条件(权限)
  29. *
  30. * @param $userId 当前登录ID
  31. * @author fanqi
  32. * @date 2021-03-09
  33. * @return \Closure
  34. */
  35. public function getBusinessSearchWhere($userId)
  36. {
  37. $userModel = new \app\admin\model\User();
  38. $authUserIds = $userModel->getUserByPer('crm', 'business', 'index');
  39. $authMapData['auth_user_ids'] = $authUserIds;
  40. $authMapData['user_id'] = $userId;
  41. return $this->getSearchAuthWhere($authMapData);
  42. }
  43. /**
  44. * 合同tab列表查询条件(权限)
  45. *
  46. * @param $userId 当前登录ID
  47. * @author fanqi
  48. * @date 2021-03-09
  49. * @return \Closure
  50. */
  51. public function getContractSearchWhere($userId)
  52. {
  53. $userModel = new \app\admin\model\User();
  54. $authUserIds = $userModel->getUserByPer('crm', 'contract', 'index');
  55. $authMapData['auth_user_ids'] = $authUserIds;
  56. $authMapData['user_id'] = $userId;
  57. return $this->getSearchAuthWhere($authMapData);
  58. }
  59. /**
  60. * 回访tab列表查询条件(权限)
  61. *
  62. * @param $userId
  63. * @author fanqi
  64. * @date 2021-03-09
  65. * @return \Closure
  66. */
  67. public function getVisitSearchWhere($userId)
  68. {
  69. $userModel = new \app\admin\model\User();
  70. $authUserIds = $userModel->getUserByPer('crm', 'visit', 'index');
  71. $authMapData['auth_user_ids'] = $authUserIds;
  72. $authMapData['user_id'] = $userId;
  73. return $this->getSearchAuthWhere($authMapData);
  74. }
  75. /**
  76. * 回款tab列表查询条件(权限)
  77. *
  78. * @author fanqi
  79. * @date 2021-03-10
  80. * @return array[]
  81. */
  82. public function getReceivablesSearchWhere()
  83. {
  84. $userModel = new \app\admin\model\User();
  85. return $userModel->getUserByPer('crm', 'receivables', 'index');
  86. }
  87. /**
  88. * 发票tab列表查询条件
  89. *
  90. * @author fanqi
  91. * @date 2021-03-11
  92. * @return array|false|string
  93. */
  94. public function getInvoiceSearchWhere()
  95. {
  96. $userModel = new \app\admin\model\User();
  97. return $userModel->getUserByPer('crm', 'invoice', 'index');
  98. }
  99. /**
  100. * 产品tab列表查询条件
  101. *
  102. * @author fanqi
  103. * @date 2021-03-11
  104. * @return array|false|string
  105. */
  106. public function getProductSearchWhere()
  107. {
  108. $userModel = new \app\admin\model\User();
  109. return $userModel->getUserByPer('crm', 'product', 'index');
  110. }
  111. /**
  112. * 查询权限条件
  113. *
  114. * @param $authMapData 权限范围内的ID
  115. * @return \Closure
  116. */
  117. private function getSearchAuthWhere($authMapData)
  118. {
  119. return function($query) use ($authMapData) {
  120. $query->where(['owner_user_id' => ['in', $authMapData['auth_user_ids']]])
  121. ->whereOr(function ($query) use ($authMapData) {
  122. $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", ro_user_id)')->where(['owner_user_id' => ['neq', '']]);
  123. })
  124. ->whereOr(function ($query) use ($authMapData) {
  125. $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", rw_user_id)')->where(['owner_user_id' => ['neq', '']]);
  126. });
  127. };
  128. }
  129. }