AdminService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\api\service;
  3. use app\admin\controller\AuthGroup;
  4. use app\common\model\AdminModel;
  5. use app\common\model\AuthGroupModel;
  6. use app\common\model\StoreModel;
  7. class AdminService extends \app\BaseService
  8. {
  9. private $adminModel;
  10. private $storeModel;
  11. public function __construct()
  12. {
  13. $this->adminModel = new AdminModel();
  14. $this->storeModel = new StoreModel();
  15. }
  16. public function search($text = null) {
  17. $admins = $this->adminModel->findAdmins($text)->toArray();
  18. $store_ids = [];
  19. foreach ($admins as &$admin) {
  20. $admin['store_ids'] = $admin['store_ids'] ? explode(',', $admin['store_ids']) : [];
  21. $store_ids = array_unique(array_merge($store_ids, $admin['store_ids']));
  22. }
  23. $stores = $this->storeModel->findByIds($store_ids)->toArray();
  24. $fmt_stores = [];
  25. foreach ($stores as $store) {
  26. $fmt_stores[$store['id']] = $store;
  27. }
  28. foreach ($admins as &$admin) {
  29. $now_stores = array_map(function ($store_id) use ($fmt_stores){
  30. return $fmt_stores[$store_id];
  31. }, $admin['store_ids']);
  32. $admin['stores'] = $now_stores;
  33. }
  34. return $admins;
  35. }
  36. public function fetchMenus($admin_id) {
  37. $admin = $this->adminModel->findById($admin_id);
  38. $group = $admin['access']['group'];
  39. $fmt_reception_rules = [];
  40. foreach (fetchReceptionRules() as $rule) {
  41. $fmt_reception_rules[$rule['id']] = $rule;
  42. }
  43. $reception_rule_ids = $group->reception_rules ? explode(',', $group->reception_rules) : [];
  44. return array_map(function ($id) use($fmt_reception_rules) {
  45. return $fmt_reception_rules[$id];
  46. },$reception_rule_ids);
  47. }
  48. }