ShopAdminClass.php 7.6 KB

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