ShopAdminService.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace biz\shop\services;
  3. use bizHd\admin\classes\AdminClass;
  4. use bizHd\admin\classes\AdminRoleClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use bizHd\auth\services\AuthService;
  7. use biz\base\services\BaseService;
  8. use bizHd\merchant\classes\ShopClass;
  9. use biz\sj\services\MerchantService;
  10. use bizHd\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 = '\biz\shop\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. $mainId = $data['mainId'] ?? 0;
  41. $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
  42. $shop = ShopClass::getById($shopId);
  43. if (empty($shop)) {
  44. util::fail('没有找到门店2');
  45. }
  46. $sjId = isset($shop['sjId']) ? $shop['sjId'] : 0;
  47. if (empty($bindData)) {
  48. util::fail('小程序码已经失效,请重新创建员工');
  49. }
  50. $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId]);
  51. if (!empty($shopAdmin)) {
  52. util::fail('您已经是管理员了');
  53. }
  54. $name = isset($bindData['name']) ? $bindData['name'] : '';
  55. if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
  56. util::fail('添加管理员时请选择角色');
  57. }
  58. $admin = AdminClass::getById($adminId);
  59. if (empty($admin)) {
  60. util::fail('没有找到管理员信息');
  61. }
  62. $roleId = $bindData['roleId'];
  63. $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
  64. $status = isset($bindData['status']) ? $bindData['status'] : 0;
  65. $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
  66. $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
  67. $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark];
  68. AdminClass::updateById($adminId, $update);
  69. $addData = [
  70. 'adminId' => $adminId,
  71. 'shopId' => $shopId,
  72. 'roleId' => $roleId,
  73. 'remind' => $remind,
  74. 'status' => $status,
  75. 'sjId' => $sjId,
  76. 'name' => $name,
  77. 'mainId' => $mainId,
  78. ];
  79. ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
  80. return ShopAdminClass::add($addData);
  81. }
  82. //获取管理员 ssh 2020.4.21
  83. public static function getAdminList($where)
  84. {
  85. $data = ShopAdminClass::getList('*', $where, 'addTime DESC');
  86. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  87. if (empty($list)) {
  88. return $data;
  89. }
  90. //管理员基础信息
  91. $ids = array_column($list, 'adminId');
  92. $adminInfo = AdminClass::getByIds($ids, null, 'id');
  93. $adminBaseInfo = AdminClass::groupAdminBaseInfo($adminInfo);
  94. $roleIds = array_column($list, 'roleId');
  95. $roleIds = array_filter(array_unique($roleIds));
  96. $roleList = AdminRoleClass::getByIds($roleIds, null, 'id');
  97. foreach ($list as $key => $val) {
  98. $adminId = $val['adminId'];
  99. $current = isset($adminBaseInfo[$adminId]) ? $adminBaseInfo[$adminId] : [];
  100. $list[$key]['adminBaseInfo'] = $current;
  101. $roleId = $val['roleId'];
  102. $roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : '';
  103. $list[$key]['roleName'] = $roleName;
  104. }
  105. $data['list'] = $list;
  106. return $data;
  107. }
  108. //获取要通知的管理员 ssh 2020.4.28
  109. public static function getNoticeAdminList($shopId)
  110. {
  111. $where = ['shopId' => $shopId];
  112. $respond = self::getAdminList($where);
  113. $list = isset($respond['list']) ? $respond['list'] : [];
  114. if (!empty($list)) {
  115. foreach ($list as $key => $val) {
  116. if (isset($val['remind']) && $val['remind'] == 0) {
  117. unset($list[$key]);
  118. }
  119. }
  120. }
  121. return $list;
  122. }
  123. public static function valid($shopAdmin, $shopId)
  124. {
  125. if (isset($shopAdmin['shopId']) == false || $shopAdmin['shopId'] != $shopId) {
  126. util::fail('不是您的员工');
  127. }
  128. }
  129. }