ShopAdminClass.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace biz\shop\classes;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\classes\AdminRoleClass;
  5. use bizGhs\ws\services\WsService;
  6. use bizHd\user\classes\UserClass;
  7. use common\components\util;
  8. use Yii;
  9. use biz\base\classes\BaseClass;
  10. class ShopAdminClass extends BaseClass
  11. {
  12. public static $baseFile = '\biz\shop\models\ShopAdmin';
  13. const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
  14. //添加客户 ssh 2021.3.1
  15. public static function addShopAdmin($data, $returnObj = false)
  16. {
  17. return self::add($data, $returnObj);
  18. }
  19. //创建管理准备数据key ssh 2020.4.17
  20. public static function getGenerateAdminDataKey($mainId, $adminId)
  21. {
  22. return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
  23. }
  24. //创建管理员数据准备 ssh 2020.4.17
  25. public static function prepareBindAdmin($data)
  26. {
  27. $adminId = $data['adminId'];
  28. $mainId = $data['mainId'];
  29. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  30. $params = [$cacheKey];
  31. if (!empty($data)) {
  32. foreach ($data as $key => $val) {
  33. if (!is_array($val)) {
  34. $params[] = $key;
  35. $params[] = $val;
  36. }
  37. }
  38. }
  39. Yii::$app->redis->executeCommand('HMSET', $params);
  40. }
  41. //获取创建管理员需要的信息 ssh 2020.4.20
  42. public static function getBindAdminData($mainId, $adminId)
  43. {
  44. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  45. $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  46. $data = [];
  47. if (!empty($cacheData)) {
  48. $data = [];
  49. $list = [];
  50. $x = 0;
  51. foreach ($cacheData as $cKey => $cVal) {
  52. if ($cKey % 2 == 0) {
  53. $list[$x]['key'] = $cVal;
  54. } else {
  55. $list[$x]['value'] = $cVal;
  56. $x++;
  57. }
  58. }
  59. foreach ($list as $lKey => $lVal) {
  60. $data[$lVal['key']] = $lVal['value'];
  61. }
  62. }
  63. return $data;
  64. }
  65. //删除创建管理员需要的信息 ssh 2020.4.20
  66. public static function delBindAdminData($mainId, $adminId)
  67. {
  68. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  69. $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
  70. if (!empty($keyNameList)) {
  71. $data = array_merge([$cacheKey], $keyNameList);
  72. $cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
  73. }
  74. }
  75. //取店长信息 ssh 2021.1.8
  76. public static function getManager($mainId)
  77. {
  78. $relate = self::getByCondition(['mainId' => $mainId, 'founder' => 2]);
  79. $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
  80. $info = [];
  81. if (!empty($adminId)) {
  82. $info = AdminClass::getById($adminId);
  83. }
  84. return $info;
  85. }
  86. public static function valid($adminInfo, $mainId)
  87. {
  88. if (isset($adminInfo['mainId']) && $adminInfo['mainId'] == $mainId) {
  89. return true;
  90. }
  91. util::fail('此员工您无法操作');
  92. }
  93. //切换门店时增加员工关系 ssh 2021.3.1
  94. public static function changeShopAddRelate($originShopAdmin, $newShop, $isPt = 0)
  95. {
  96. $newMainId = $newShop->mainId ?? 0;
  97. $name = $originShopAdmin->name ?? '';
  98. $mobile = $originShopAdmin->mobile ?? 0;
  99. $avatar = $originShopAdmin->avatar ?? '';
  100. $adminId = $originShopAdmin->adminId ?? 0;
  101. $roleId = $originShopAdmin->roleId ?? 0;
  102. $sjId = $originShopAdmin->sjId ?? 0;
  103. $super = $originShopAdmin->super ?? 0;
  104. $has = self::getByCondition(['mainId' => $newMainId, 'adminId' => $adminId], true);
  105. if (!empty($has)) {
  106. $has->delStatus = 0;
  107. $has->save();
  108. return $has;
  109. }
  110. $data = [
  111. 'name' => $name,
  112. 'mobile' => $mobile,
  113. 'avatar' => $avatar,
  114. 'roleId' => $roleId,
  115. 'adminId' => $adminId,
  116. 'sjId' => $sjId,
  117. 'super' => $super,
  118. 'mainId' => $newMainId,
  119. 'isPt' => $isPt,
  120. ];
  121. $return = self::addShopAdmin($data, true);
  122. return $return;
  123. }
  124. //员工收款通知 ssh 2021.4.19
  125. public static function incomeNotice($shopId, $money, $payWay = 0)
  126. {
  127. $list = self::getAllByCondition(['shopId' => $shopId, 'delStatus' => 0, 'status' => 1], null, '*');
  128. if (empty($list)) {
  129. return false;
  130. }
  131. foreach ($list as $key => $val) {
  132. if ($val['remind'] == 1) {
  133. $id = $val['id'];
  134. Yii::info("income notice shopAdminId:{$id} " . $money);
  135. WsService::arrivalNotice($id, $money, $payWay);
  136. }
  137. }
  138. }
  139. //获取基本信息 ssh 2021.4.23
  140. public static function getAdminInfo($id)
  141. {
  142. $relation = self::getById($id);
  143. if (empty($relation)) {
  144. util::fail('没有找到员工信息');
  145. }
  146. return $relation;
  147. }
  148. //是否有切换门店权限 0不是 1是
  149. public static function hasSwitchShopRight($shopAdmin)
  150. {
  151. $hasRight = 0;
  152. if ($shopAdmin->switchShop == 1) {
  153. $hasRight = 1;
  154. }
  155. $ptAdminId = AdminClass::getPtSuperAdminId();
  156. if ($shopAdmin->adminId == $ptAdminId) {
  157. $hasRight = 1;
  158. }
  159. return $hasRight;
  160. }
  161. //删除员工 ssh 2021.5.3
  162. public static function deleteShopAdmin($relation, $thisShopAdminId, $mainId)
  163. {
  164. $id = $relation->id ?? 0;
  165. if ($relation->founder == 2) {
  166. util::fail("创始人不能删除");
  167. }
  168. if ($id == $thisShopAdminId) {
  169. util::fail("不能删自己");
  170. }
  171. ShopAdminClass::valid($relation, $mainId);
  172. $adminId = $relation->adminId ?? 0;
  173. $currentShopId = $relation->shopId ?? 0;
  174. $admin = AdminClass::getById($adminId, true);
  175. if (empty($admin)) {
  176. util::fail('没有找到员工信息');
  177. }
  178. $admin->currentGhsShopId = 0;
  179. $admin->save();
  180. $relation->delStatus = 1;
  181. $relation->save();
  182. //删除员工关系后,再找出这个员工还有没其它门店员工身份补上
  183. if (!empty($admin) && isset($admin->currentShopId) && $admin->currentShopId == $currentShopId) {
  184. $has = self::getByCondition(['adminId' => $adminId, 'delStatus' => 0, 'status' => 1], true);
  185. $hasCurrentShopId = $has->shopId ?? 0;
  186. $admin->currentGhsShopId = $hasCurrentShopId;
  187. $admin->save();
  188. }
  189. // 员工数-1
  190. AdminRoleClass::counters(['num' => -1], ['id' => $relation->roleId]);
  191. }
  192. //根据shopId 获取 员工的shopAdminId
  193. //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1)
  194. public static function getRemindShopAdminIdsByShopId($shopId)
  195. {
  196. $where = [
  197. 'shopId' => $shopId,
  198. 'status' => 1,
  199. 'delStatus' => 0,
  200. 'remind' => 1
  201. ];
  202. $data = self::getAllByCondition($where, null, "id");
  203. return array_column($data, 'id');
  204. }
  205. //通过shopId 获取相应的需要通知的 adminIds (status=1 and delStatus=0 and remind=1)
  206. public static function getRemindAdminIdsByShopId($shopId)
  207. {
  208. $where = [
  209. 'shopId' => $shopId,
  210. 'status' => 1,
  211. 'delStatus' => 0,
  212. 'remind' => 1
  213. ];
  214. $data = self::getAllByCondition($where, null, "adminId");
  215. return array_column($data, 'adminId');
  216. }
  217. //获取需要通知的员工 ssh 20220822
  218. public static function getRemainAdmin($shop)
  219. {
  220. $mainId = $shop->mainId ?? 0;
  221. $where = ['mainId' => $mainId, 'status' => 1, 'delStatus' => 0, 'remind' => 1];
  222. $shopAdmin = self::getAllByCondition($where, null, 'id,adminId');
  223. if (empty($shopAdmin)) {
  224. return [];
  225. }
  226. $ids = array_column($shopAdmin, 'adminId');
  227. $admin = AdminClass::getByIds($ids);
  228. return $admin;
  229. }
  230. }