ShopAdminClass.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. //员工相关
  3. namespace bizGhs\shop\classes;
  4. use biz\admin\classes\AdminClass;
  5. use bizGhs\admin\classes\AdminRoleClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use common\components\dict;
  8. use common\components\sms;
  9. use common\components\util;
  10. use Yii;
  11. use bizHd\base\classes\BaseClass;
  12. class ShopAdminClass extends BaseClass
  13. {
  14. public static $baseFile = '\bizGhs\shop\models\ShopAdmin';
  15. public static function changeWeightRight($adminId, $ptItemId)
  16. {
  17. //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
  18. //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
  19. $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true);
  20. $hasMainList = [];
  21. $mayList = [];
  22. if (!empty($staffList)) {
  23. foreach ($staffList as $staff) {
  24. $mayList[] = $staff->mainId;
  25. if ($staff->super == 1) {
  26. $hasMainList[] = $staff->mainId;
  27. }
  28. }
  29. }
  30. $sameList = ProductClass::getAllByCondition(['itemId' => $ptItemId], null, 'id,itemId,mainId');
  31. $sameMainList = array_column($sameList, 'mainId');
  32. $hasNot = array_diff($sameMainList, $hasMainList);
  33. $hasRightChange = empty($hasNot) ? 1 : 0;
  34. $mayHasNot = array_diff($sameMainList, $mayList);
  35. $reason = '别的批发店也在用此花材,不能修改';
  36. if (empty($mayHasNot)) {
  37. $reason = '你在某个店没有改库存改价,不能修改';
  38. }
  39. return ['hasRightChange' => $hasRightChange, 'reason' => $reason];
  40. }
  41. const GENERATE_ADMIN_DATA = 'generate_ghs_admin_data_';//创建管理员需要的数据
  42. //查看财务权限 ssh 20230620
  43. public static function lookMoneyPower($staff, $shop)
  44. {
  45. $lookMoney = 0;
  46. if (isset($staff->finance) && $staff->finance == 1) {
  47. $lookMoney = 1;
  48. }
  49. $ptAdminId = AdminClass::getPtSuperAdminId();
  50. if (isset($staff->adminId) && $staff->adminId == $ptAdminId) {
  51. $lookMoney = 1;
  52. }
  53. return $lookMoney;
  54. }
  55. //创建员工 ssh 2021.5.9
  56. public static function appGenerateStaff($data, $admin)
  57. {
  58. $mobile = $data['mobile'] ?? '';
  59. $shopId = $data['shopId'] ?? 0;
  60. $name = $data['name'] ?? '未命名';
  61. $remark = isset($data['remark']) ? $data['remark'] : '';
  62. $status = 1;
  63. $super = $data['super'] ?? 0;
  64. $remind = isset($data['remind']) ? $data['remind'] : 0;
  65. $roleId = $data['roleId'] ?? 0;
  66. $finance = $data['finance'] ?? 0;
  67. $switchShop = $data['switchShop'] ?? 0;
  68. $role = AdminRoleClass::getById($roleId);
  69. if (empty($role)) {
  70. util::fail('没有找到角色哦');
  71. }
  72. $shop = ShopClass::getById($shopId);
  73. if (empty($shop)) {
  74. util::fail('没有找到门店25');
  75. }
  76. $avatar = $admin['avatar'] ?? '';
  77. $adminId = $admin['id'] ?? 0;
  78. $mainId = $shop['mainId'] ?? 0;
  79. $shopAdmin = self::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  80. if (!empty($shopAdmin)) {
  81. //已删除员工补回
  82. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  83. $shopAdmin->delStatus = 0;
  84. $shopAdmin->roleId = $roleId;
  85. $shopAdmin->remind = $remind;
  86. $shopAdmin->finance = $finance;
  87. $shopAdmin->switchShop = $switchShop;
  88. $shopAdmin->status = $status;
  89. $shopAdmin->remark = $remark;
  90. $shopAdmin->name = $name;
  91. $shopAdmin->avatar = $avatar;
  92. $shopAdmin->super = $super;
  93. $shopAdmin->save();
  94. //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
  95. }
  96. } else {
  97. $addData = [
  98. 'adminId' => $adminId,
  99. 'roleId' => $roleId,
  100. 'remind' => $remind,
  101. 'finance' => $finance,
  102. 'switchShop' => $switchShop,
  103. 'status' => $status,
  104. 'name' => $name,
  105. 'mobile' => $mobile,
  106. 'avatar' => $avatar,
  107. 'super' => $super,
  108. 'mainId' => $mainId
  109. ];
  110. $shopAdmin = ShopAdminClass::add($addData, true);
  111. //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
  112. }
  113. $lsShopId = $shop['lsShopId'] ?? 0;
  114. $update = ['currentGhsShopId' => $shopId, 'currentShopId' => $lsShopId];
  115. AdminClass::updateById($adminId, $update);
  116. return $shopAdmin;
  117. }
  118. //创建管理准备数据key ssh 2020.4.17
  119. public static function getGenerateAdminDataKey($mainId, $adminId)
  120. {
  121. return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
  122. }
  123. //创建管理员数据准备 ssh 2020.4.17
  124. public static function prepareBindAdmin($data)
  125. {
  126. $adminId = $data['adminId'];
  127. $mainId = $data['mainId'];
  128. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  129. $params = [$cacheKey];
  130. if (!empty($data)) {
  131. foreach ($data as $key => $val) {
  132. if (!is_array($val)) {
  133. $params[] = $key;
  134. $params[] = $val;
  135. }
  136. }
  137. }
  138. Yii::$app->redis->executeCommand('HMSET', $params);
  139. }
  140. //获取创建管理员需要的信息 ssh 2020.4.20
  141. public static function getBindAdminData($mainId, $adminId)
  142. {
  143. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  144. $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  145. $data = [];
  146. if (!empty($cacheData)) {
  147. $data = [];
  148. $list = [];
  149. $x = 0;
  150. foreach ($cacheData as $cKey => $cVal) {
  151. if ($cKey % 2 == 0) {
  152. $list[$x]['key'] = $cVal;
  153. } else {
  154. $list[$x]['value'] = $cVal;
  155. $x++;
  156. }
  157. }
  158. foreach ($list as $lKey => $lVal) {
  159. $data[$lVal['key']] = $lVal['value'];
  160. }
  161. }
  162. return $data;
  163. }
  164. //删除创建管理员需要的信息 ssh 2020.4.20
  165. public static function delBindAdminData($mainId, $adminId)
  166. {
  167. $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
  168. $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
  169. if (!empty($keyNameList)) {
  170. $data = array_merge([$cacheKey], $keyNameList);
  171. Yii::$app->redis->executeCommand('HDEL', $data);
  172. }
  173. }
  174. //权限判断 ssh 2021.1.13
  175. public static function valid($admin, $mainId)
  176. {
  177. if (isset($admin['mainId']) && $admin['mainId'] == $mainId) {
  178. return true;
  179. }
  180. util::fail('您无法操作');
  181. }
  182. //获取详情 ssh 2021.3.27
  183. public static function getInfo($id)
  184. {
  185. return self::getById($id);
  186. }
  187. //获取基本信息 ssh 2021.4.23
  188. public static function getAdminInfo($id)
  189. {
  190. $relation = self::getById($id);
  191. if (empty($relation)) {
  192. util::fail('没有找到员工信息');
  193. }
  194. return $relation;
  195. }
  196. //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1)
  197. public static function getRemindAdminIdsByShopId($shopId)
  198. {
  199. $where = [
  200. 'shopId' => $shopId,
  201. 'status' => 1,
  202. 'delStatus' => 0,
  203. 'remind' => 1
  204. ];
  205. $data = self::getAllByCondition($where, null, "id");
  206. return array_column($data, 'id');
  207. }
  208. }