ShopAdminClass.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. //员工相关
  3. namespace bizGhs\shop\classes;
  4. use biz\admin\classes\AdminClass;
  5. use bizGhs\admin\classes\AdminRoleClass;
  6. use common\components\dict;
  7. use common\components\sms;
  8. use common\components\util;
  9. use Yii;
  10. use bizHd\base\classes\BaseClass;
  11. class ShopAdminClass extends BaseClass
  12. {
  13. public static $baseFile = '\bizGhs\shop\models\ShopAdmin';
  14. const GENERATE_ADMIN_DATA = 'generate_ghs_admin_data_';//创建管理员需要的数据
  15. //查看财务权限 ssh 20230620
  16. public static function lookMoneyPower($staff, $shop)
  17. {
  18. $lookMoney = 0;
  19. if (isset($staff->finance) && $staff->finance == 1) {
  20. $lookMoney = 1;
  21. }
  22. $ptAdminId = AdminClass::getPtSuperAdminId();
  23. if (isset($staff->adminId) && $staff->adminId == $ptAdminId) {
  24. $lookMoney = 1;
  25. }
  26. return $lookMoney;
  27. }
  28. //创建员工 ssh 2021.5.9
  29. public static function appGenerateStaff($data, $admin)
  30. {
  31. $mobile = $data['mobile'] ?? '';
  32. $shopId = $data['shopId'] ?? 0;
  33. $name = $data['name'] ?? '未命名';
  34. $remark = isset($data['remark']) ? $data['remark'] : '';
  35. $status = 1;
  36. $super = $data['super'] ?? 0;
  37. $remind = isset($data['remind']) ? $data['remind'] : 0;
  38. $roleId = $data['roleId'] ?? 0;
  39. $finance = $data['finance'] ?? 0;
  40. $switchShop = $data['switchShop'] ?? 0;
  41. $role = AdminRoleClass::getById($roleId);
  42. if (empty($role)) {
  43. util::fail('没有找到角色哦');
  44. }
  45. $shop = ShopClass::getById($shopId);
  46. if (empty($shop)) {
  47. util::fail('没有找到门店25');
  48. }
  49. $avatar = $admin['avatar'] ?? '';
  50. $adminId = $admin['id'] ?? 0;
  51. $mainId = $shop['mainId'] ?? 0;
  52. $shopAdmin = self::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  53. if (!empty($shopAdmin)) {
  54. //已删除员工补回
  55. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  56. $shopAdmin->delStatus = 0;
  57. $shopAdmin->roleId = $roleId;
  58. $shopAdmin->remind = $remind;
  59. $shopAdmin->finance = $finance;
  60. $shopAdmin->switchShop = $switchShop;
  61. $shopAdmin->status = $status;
  62. $shopAdmin->remark = $remark;
  63. $shopAdmin->name = $name;
  64. $shopAdmin->avatar = $avatar;
  65. $shopAdmin->super = $super;
  66. $shopAdmin->save();
  67. //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
  68. }
  69. } else {
  70. $addData = [
  71. 'adminId' => $adminId,
  72. 'roleId' => $roleId,
  73. 'remind' => $remind,
  74. 'finance' => $finance,
  75. 'switchShop' => $switchShop,
  76. 'status' => $status,
  77. 'name' => $name,
  78. 'mobile' => $mobile,
  79. 'avatar' => $avatar,
  80. 'super' => $super,
  81. 'mainId' => $mainId
  82. ];
  83. $shopAdmin = ShopAdminClass::add($addData, true);
  84. //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
  85. }
  86. $lsShopId = $shop['lsShopId'] ?? 0;
  87. $update = ['currentGhsShopId' => $shopId, 'currentShopId' => $lsShopId];
  88. AdminClass::updateById($adminId, $update);
  89. return $shopAdmin;
  90. }
  91. //创建管理准备数据key ssh 2020.4.17
  92. public static function getGenerateAdminDataKey($mainId, $adminId)
  93. {
  94. return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
  95. }
  96. //创建管理员数据准备 ssh 2020.4.17
  97. public static function prepareBindAdmin($data)
  98. {
  99. $adminId = $data['adminId'];
  100. $mainId = $data['mainId'];
  101. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  102. $params = [$cacheKey];
  103. if (!empty($data)) {
  104. foreach ($data as $key => $val) {
  105. if (!is_array($val)) {
  106. $params[] = $key;
  107. $params[] = $val;
  108. }
  109. }
  110. }
  111. Yii::$app->redis->executeCommand('HMSET', $params);
  112. }
  113. //获取创建管理员需要的信息 ssh 2020.4.20
  114. public static function getBindAdminData($mainId, $adminId)
  115. {
  116. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  117. $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  118. $data = [];
  119. if (!empty($cacheData)) {
  120. $data = [];
  121. $list = [];
  122. $x = 0;
  123. foreach ($cacheData as $cKey => $cVal) {
  124. if ($cKey % 2 == 0) {
  125. $list[$x]['key'] = $cVal;
  126. } else {
  127. $list[$x]['value'] = $cVal;
  128. $x++;
  129. }
  130. }
  131. foreach ($list as $lKey => $lVal) {
  132. $data[$lVal['key']] = $lVal['value'];
  133. }
  134. }
  135. return $data;
  136. }
  137. //删除创建管理员需要的信息 ssh 2020.4.20
  138. public static function delBindAdminData($mainId, $adminId)
  139. {
  140. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  141. $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
  142. if (!empty($keyNameList)) {
  143. $data = array_merge([$cacheKey], $keyNameList);
  144. Yii::$app->redis->executeCommand('HDEL', $data);
  145. }
  146. }
  147. //权限判断 ssh 2021.1.13
  148. public static function valid($admin, $mainId)
  149. {
  150. if (isset($admin['mainId']) && $admin['mainId'] == $mainId) {
  151. return true;
  152. }
  153. util::fail('您无法操作');
  154. }
  155. //获取详情 ssh 2021.3.27
  156. public static function getInfo($id)
  157. {
  158. return self::getById($id);
  159. }
  160. //获取基本信息 ssh 2021.4.23
  161. public static function getAdminInfo($id)
  162. {
  163. $relation = self::getById($id);
  164. if (empty($relation)) {
  165. util::fail('没有找到员工信息');
  166. }
  167. return $relation;
  168. }
  169. //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1)
  170. public static function getRemindAdminIdsByShopId($shopId)
  171. {
  172. $where = [
  173. 'shopId' => $shopId,
  174. 'status' => 1,
  175. 'delStatus' => 0,
  176. 'remind' => 1
  177. ];
  178. $data = self::getAllByCondition($where, null, "id");
  179. return array_column($data, 'id');
  180. }
  181. }