ShopAdminClass.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace biz\shop\classes;
  3. use bizHd\user\classes\UserClass;
  4. use common\components\util;
  5. use Yii;
  6. use biz\base\classes\BaseClass;
  7. class ShopAdminClass extends BaseClass
  8. {
  9. public static $baseFile = '\biz\shop\models\ShopAdmin';
  10. const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
  11. //添加客户 shish 2021.3.1
  12. public static function addShopAdmin($data)
  13. {
  14. return self::add($data);
  15. }
  16. //创建管理准备数据key shish 2020.4.17
  17. public static function getGenerateAdminDataKey($shopId, $adminId)
  18. {
  19. return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
  20. }
  21. //创建管理员数据准备 shish 2020.4.17
  22. public static function prepareBindAdmin($data)
  23. {
  24. $adminId = $data['adminId'];
  25. $shopId = $data['shopId'];
  26. $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
  27. $params = [$cacheKey];
  28. if (!empty($data)) {
  29. foreach ($data as $key => $val) {
  30. if (!is_array($val)) {
  31. $params[] = $key;
  32. $params[] = $val;
  33. }
  34. }
  35. }
  36. Yii::$app->redis->executeCommand('HMSET', $params);
  37. }
  38. //获取创建管理员需要的信息 shish 2020.4.20
  39. public static function getBindAdminData($shopId, $adminId)
  40. {
  41. $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
  42. $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  43. $data = [];
  44. if (!empty($cacheData)) {
  45. $data = [];
  46. $list = [];
  47. $x = 0;
  48. foreach ($cacheData as $cKey => $cVal) {
  49. if ($cKey % 2 == 0) {
  50. $list[$x]['key'] = $cVal;
  51. } else {
  52. $list[$x]['value'] = $cVal;
  53. $x++;
  54. }
  55. }
  56. foreach ($list as $lKey => $lVal) {
  57. $data[$lVal['key']] = $lVal['value'];
  58. }
  59. }
  60. return $data;
  61. }
  62. //删除创建管理员需要的信息 shish 2020.4.20
  63. public static function delBindAdminData($shopId, $adminId)
  64. {
  65. $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
  66. $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
  67. if (!empty($keyNameList)) {
  68. $data = array_merge([$cacheKey], $keyNameList);
  69. $cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
  70. }
  71. }
  72. //取店长 shish 2021.1.8
  73. public static function getManager($shopId)
  74. {
  75. $relate = self::getByCondition(['shopId' => $shopId]);
  76. $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
  77. $info = [];
  78. if (!empty($adminId)) {
  79. $info = AdminClass::getById($adminId);
  80. }
  81. return $info;
  82. }
  83. public static function valid($adminInfo, $merchantId)
  84. {
  85. if (isset($adminInfo['merchantId']) && $adminInfo['merchantId'] == $merchantId) {
  86. return true;
  87. }
  88. util::fail('此员工您没有权限操作');
  89. }
  90. //切换门店时增加员工关系 shish 2021.3.1
  91. public static function toggleShopAddRelate($originShopAdmin, $toggleShopId)
  92. {
  93. $adminId = $originShopAdmin['adminId'];
  94. $roleId = $originShopAdmin['roleId'];
  95. $sjId = $originShopAdmin['merchantId'];
  96. $has = self::getCount(['shopId' => $toggleShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  97. if ($has) {
  98. return $has;
  99. }
  100. $data = [
  101. 'roleId' => $roleId,
  102. 'adminId' => $adminId,
  103. 'shopId' => $toggleShopId,
  104. 'merchantId' => $sjId,
  105. ];
  106. return self::addShopAdmin($data);
  107. }
  108. }