ShopAdminService.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace bizMall\admin\services;
  3. use bizMall\admin\classes\AdminClass;
  4. use bizMall\admin\classes\AdminRoleClass;
  5. use bizMall\admin\classes\ShopAdminClass;
  6. use bizMall\auth\services\AuthService;
  7. use bizMall\base\services\BaseService;
  8. use bizMall\merchant\classes\ShopClass;
  9. use bizMall\merchant\services\MerchantService;
  10. use bizMall\user\services\UserService;
  11. use common\components\error;
  12. use common\components\miniUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use common\components\wxUtil;
  16. use common\services\xhTMessageService;
  17. use Yii;
  18. class ShopAdminService extends BaseService
  19. {
  20. public static $baseFile = '\bizMall\admin\classes\ShopAdminClass';
  21. ///创建管理员生成小程序 ssh 2020.4.17
  22. public static function prepareBindAdmin($data)
  23. {
  24. ShopAdminClass::prepareBindAdmin($data);
  25. $page = 'admin/shopAdmin/bind';
  26. $isOpen = 1;
  27. $adminId = $data['adminId'];
  28. $shopId = $data['shopId'];
  29. $scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
  30. $merchant = $data['merchant'];
  31. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
  32. return ['miniCode' => $imgUrl];
  33. }
  34. public static function generateAdmin($data)
  35. {
  36. $recommendAdminId = isset($data['recommendAdminId']) ? $data['recommendAdminId'] : 0;
  37. $mobile = isset($data['mobile']) ? $data['mobile'] : '';
  38. $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
  39. $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
  40. $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
  41. $shop = ShopClass::getById($shopId);
  42. if (empty($shop)) {
  43. util::fail('没有找到门店83');
  44. }
  45. $sjId = isset($shop['sjId']) ? $shop['sjId'] : 0;
  46. if (empty($bindData)) {
  47. util::fail('小程序码已经失效,请重新创建员工');
  48. }
  49. $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
  50. if (!empty($shopAdmin)) {
  51. util::fail('您已经是管理员了');
  52. }
  53. $name = isset($bindData['name']) ? $bindData['name'] : '';
  54. if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
  55. util::fail('添加管理员时请选择角色');
  56. }
  57. $admin = AdminClass::getById($adminId);
  58. if (empty($admin)) {
  59. util::fail('没有找到管理员信息');
  60. }
  61. if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
  62. //util::fail("请关注公众号({$admin['id']})");
  63. }
  64. $roleId = $bindData['roleId'];
  65. $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
  66. $status = isset($bindData['status']) ? $bindData['status'] : 0;
  67. $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
  68. $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
  69. $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark];
  70. AdminClass::updateById($adminId, $update);
  71. $addData = [
  72. 'adminId' => $adminId,
  73. 'shopId' => $shopId,
  74. 'roleId' => $roleId,
  75. 'remind' => $remind,
  76. 'status' => $status,
  77. 'sjId' => $sjId,
  78. 'name' => $name,
  79. ];
  80. ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
  81. return ShopAdminClass::add($addData);
  82. }
  83. //获取管理员 ssh 2020.4.21
  84. public static function getAdminList($where)
  85. {
  86. $data = ShopAdminClass::getList('*', $where, 'addTime DESC');
  87. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  88. if (empty($list)) {
  89. return $data;
  90. }
  91. //管理员基础信息
  92. $ids = array_column($list, 'adminId');
  93. $adminInfo = AdminClass::getByIds($ids, null, 'id');
  94. $adminBaseInfo = AdminClass::groupAdminBaseInfo($adminInfo);
  95. $roleIds = array_column($list, 'roleId');
  96. $roleIds = array_filter(array_unique($roleIds));
  97. $roleList = AdminRoleClass::getByIds($roleIds, null, 'id');
  98. foreach ($list as $key => $val) {
  99. $adminId = $val['adminId'];
  100. $current = isset($adminBaseInfo[$adminId]) ? $adminBaseInfo[$adminId] : [];
  101. $list[$key]['adminBaseInfo'] = $current;
  102. $roleId = $val['roleId'];
  103. $roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : '';
  104. $list[$key]['roleName'] = $roleName;
  105. }
  106. $data['list'] = $list;
  107. return $data;
  108. }
  109. //获取要通知的管理员 ssh 2020.4.28
  110. public static function getNoticeAdminList($shopId)
  111. {
  112. $where = ['shopId' => $shopId];
  113. $respond = self::getAdminList($where);
  114. $list = isset($respond['list']) ? $respond['list'] : [];
  115. if (!empty($list)) {
  116. foreach ($list as $key => $val) {
  117. if (isset($val['remind']) && $val['remind'] == 0) {
  118. unset($list[$key]);
  119. }
  120. }
  121. }
  122. return $list;
  123. }
  124. public static function valid($shopAdmin, $shopId)
  125. {
  126. if (isset($shopAdmin['shopId']) == false || $shopAdmin['shopId'] != $shopId) {
  127. util::fail('不是您的员工');
  128. }
  129. }
  130. }