AdminController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\item\classes\LabelClass;
  4. use bizGhs\shop\classes\ShopAdminClass;
  5. use bizHd\wx\classes\WxOpenClass;
  6. use bizGhs\admin\classes\AdminClass;
  7. use bizGhs\admin\services\AdminService;
  8. use common\components\noticeUtil;
  9. use common\components\stringUtil;
  10. use common\components\util;
  11. use Yii;
  12. use yii\helpers\Json;
  13. use bizHd\user\classes\UserClass;
  14. class AdminController extends BaseController
  15. {
  16. public $guestAccess = ['recent-shop', 'mini-full-info', 'mini-mobile', 'login-detail'];
  17. //个人信息 ssh 20230505
  18. public function actionInfo()
  19. {
  20. $admin = $this->admin;
  21. util::success(['info' => $admin]);
  22. }
  23. //修改个人信息 ssh 20230505
  24. public function actionUpdateAdmin()
  25. {
  26. $post = Yii::$app->request->post();
  27. $ghsOpenId = $post['ghsOpenId'] ?? '';
  28. $name = $post['name'] ?? '';
  29. $admin = $this->admin;
  30. $admin->ghsOpenId = $ghsOpenId;
  31. if (!empty($name)) {
  32. $admin->name = $name;
  33. }
  34. $admin->save();
  35. if (!empty($name)) {
  36. $adminId = $this->adminId;
  37. ShopAdminClass::updateByCondition(['adminId' => $adminId], ['name' => $name]);
  38. }
  39. util::complete();
  40. }
  41. //绑定帐号自动登录 ssh 20210121
  42. public function actionBindAutoLogin()
  43. {
  44. $post = Yii::$app->request->post();
  45. $iv = isset($post['iv']) ? $post['iv'] : '';
  46. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  47. $merchant = WxOpenClass::getGhsWxInfo();
  48. $appId = $merchant['miniAppId'];
  49. $miniOpenId = $post['miniOpenId'];
  50. if (empty($miniOpenId)) {
  51. util::fail('绑定失败');
  52. }
  53. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  54. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  55. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  56. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  57. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  58. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  59. if ($errCode != 0) {
  60. Yii::info($result . ' ' . $errCode);
  61. util::fail('绑定失败了');
  62. }
  63. Yii::info('小程序获取用户信息:' . $result);
  64. $wxInfo = Json::decode($result);
  65. $nickName = $wxInfo['nickName'] ?? '';
  66. if (empty($nickName)) {
  67. util::fail('绑定失败');
  68. }
  69. $admin = $this->admin ?? [];
  70. if (empty($admin)) {
  71. util::fail('绑定失败');
  72. }
  73. $admin->ghsMiniOpenId = $miniOpenId;
  74. $admin->save();
  75. util::complete();
  76. }
  77. //修改保存安卓clientId
  78. public function actionReplaceClientId()
  79. {
  80. $get = Yii::$app->request->get();
  81. $id = $get['id'] ?? '';
  82. if (empty($id)) {
  83. util::success(['returnStatus' => 'FAILURE']);
  84. }
  85. $this->admin->clientId = $id;
  86. $this->admin->save();
  87. //noticeUtil::push("保存客户端ID:" . $id, '15280215347');
  88. util::complete();
  89. }
  90. //修改密码 ssh 20220106
  91. public function actionModifyPassword()
  92. {
  93. $get = Yii::$app->request->get();
  94. $password = $get['password'] ?? '';
  95. if (empty($password)) {
  96. util::fail('请填写密码');
  97. }
  98. stringUtil::passwordCheck($password);
  99. $adminId = $this->adminId;
  100. $password = password_hash($password, PASSWORD_BCRYPT);
  101. AdminClass::updateById($adminId, ['password' => $password]);
  102. util::complete('操作成功');
  103. }
  104. //最近店铺 ssh 2021.2.27
  105. public function actionRecentShop()
  106. {
  107. $respond = AdminClass::getRecentShop($this->admin);
  108. util::success($respond);
  109. }
  110. //获取登陆员工的权限 ssh 2019.11.24
  111. public function actionLoginAuth()
  112. {
  113. $auth = AdminService::getAuth($this->adminId, $this->sjId);
  114. util::success($auth);
  115. }
  116. //添加员工 ssh 2019.12.8
  117. public function actionAdd()
  118. {
  119. $post = Yii::$app->request->post();
  120. $post['sjId'] = $this->sjId;
  121. $admin = AdminService::addAdmin($post);
  122. $id = $admin['id'];
  123. $info = AdminService::getDetail($id);
  124. util::success($info);
  125. }
  126. //删除员工 ssh 2019.12.9
  127. public function actionDelete()
  128. {
  129. Yii::$app->end();
  130. $id = Yii::$app->request->post('id');
  131. $admin = AdminClass::getById($id);
  132. AdminService::valid($admin, $this->sjId);
  133. AdminService::deleteAdmin($admin, $this->adminId);
  134. util::complete();
  135. }
  136. //查看员工详情 ssh 2019.12.9
  137. public function actionDetail()
  138. {
  139. $id = Yii::$app->request->get('id');
  140. $admin = AdminService::getDetail($id);
  141. AdminService::valid($admin, $this->sjId);
  142. util::success($admin);
  143. }
  144. //密码修改
  145. public function actionPassword()
  146. {
  147. $post = Yii::$app->request->post();
  148. $old = isset($post['old']) ? $post['old'] : '';
  149. $new = isset($post['new']) ? $post['new'] : '';
  150. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  151. if (empty($new)) {
  152. util::fail('请输入新密码');
  153. }
  154. if ($new != $confirm) {
  155. util::fail('二次密码不一致');
  156. }
  157. $admin = $this->admin->attributes;
  158. $adminId = $this->adminId;
  159. if (!empty($admin['password'])) {
  160. if (empty($old)) {
  161. util::fail('请填写旧密码');
  162. }
  163. if (password_verify($old, $admin['password']) == false) {
  164. util::fail('旧密码错误');
  165. }
  166. }
  167. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  168. util::complete('修改成功');
  169. }
  170. //支付密码修改
  171. public function actionConfirmPassword()
  172. {
  173. $post = Yii::$app->request->post();
  174. $old = isset($post['old']) ? $post['old'] : '';
  175. $new = isset($post['new']) ? $post['new'] : '';
  176. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  177. if (empty($new)) {
  178. util::fail('请输入新密码');
  179. }
  180. if ($new != $confirm) {
  181. util::fail('二次密码不一致');
  182. }
  183. $admin = $this->admin->attributes;
  184. $adminId = $this->adminId;
  185. if (!empty($admin['payPassword'])) {
  186. if (empty($old)) {
  187. util::fail('请填写旧密码');
  188. }
  189. if (password_verify($old, $admin['payPassword']) == false) {
  190. util::fail('旧密码错误');
  191. }
  192. }
  193. AdminService::updateById($adminId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  194. util::complete('修改成功');
  195. }
  196. //登陆员工的详情 ssh 2019.12.26
  197. public function actionLoginDetail()
  198. {
  199. $detail = AdminService::getDetail($this->adminId);
  200. util::success($detail);
  201. }
  202. //小程序用户完整信息 ssh 2019.12.12
  203. public function actionMiniFullInfo()
  204. {
  205. $post = Yii::$app->request->post();
  206. $iv = isset($post['iv']) ? $post['iv'] : '';
  207. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  208. $merchant = WxOpenClass::getGhsWxInfo();
  209. $appId = $merchant['miniAppId'];
  210. $admin = $this->admin;
  211. $adminId = $this->adminId;
  212. $miniOpenId = $admin->ghsMiniOpenId;
  213. if (empty($miniOpenId)) {
  214. util::fail('没有找到管理员信息(miniOpenId)');
  215. }
  216. $unionId = $admin->unionId ?? '';
  217. if (empty($unionId)) {
  218. util::fail('没有找到管理员信息(unionId)');
  219. }
  220. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  221. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  222. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  223. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  224. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  225. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  226. if ($errCode != 0) {
  227. Yii::info($result . ' ' . $errCode);
  228. util::fail('获取用户信息失败');
  229. }
  230. Yii::info('小程序获取用户信息:' . $result);
  231. $wxInfo = Json::decode($result);
  232. $source = UserClass::$userSourceId['mini']['name'];
  233. $wxInfo['ghsMiniOpenId'] = $admin->ghsMiniOpenId ?? '';
  234. $wxInfo['unionId'] = $unionId;
  235. $wxInfo['mainId'] = $this->mainId;
  236. //更新
  237. AdminClass::replaceAdmin($wxInfo, $source);
  238. $admin = AdminService::getAdminById($adminId);
  239. util::success($admin);
  240. }
  241. //小程序用户手机号
  242. public function actionMiniMobile()
  243. {
  244. $post = Yii::$app->request->post();
  245. $iv = $post['iv'];
  246. $encryptedData = $post['encryptedData'];
  247. $merchant = WxOpenClass::getGhsWxInfo();
  248. $appId = $merchant['miniAppId'];
  249. $admin = $this->admin->attributes;
  250. $miniOpenId = $admin['miniOpenId'];
  251. if (empty($miniOpenId)) {
  252. util::fail('没有找到管理员信息(miniOpenId)');
  253. }
  254. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  255. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  256. if (empty($sessionKey)) {
  257. util::fail('sesstion key empty');
  258. }
  259. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  260. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  261. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  262. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  263. if ($errCode != 0) {
  264. util::fail('解密失败');
  265. }
  266. $arr = Json::decode($result);
  267. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  268. $originalMobile = $admin['mobile'] ?? '';
  269. if (empty($originalMobile)) {
  270. \biz\admin\classes\AdminClass::updateById($this->adminId, ['mobile' => $mobile]);
  271. }
  272. util::success(['mobile' => $mobile]);
  273. }
  274. //已经存有token,但没有store信息重新获取
  275. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  276. public function actionHasTokenAutoLogin()
  277. {
  278. $admin = $this->admin;
  279. $currentGhsShopId = $admin->currentGhsShopId ?? 0;
  280. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($this->shopAdmin);
  281. $openShop = $admin['openGhsShop'] ?? 1;
  282. $showDemo = 1;
  283. $skCustomId = $this->shop->skCustomId ?? 0;
  284. $mainId = $this->shop->mainId ?? 0;
  285. $apiHost = Yii::$app->params['ghsHost'];
  286. $imgUploadApi = $apiHost . '/upload/save-file';
  287. //使用手册
  288. $cacheKey = 'close_book_' . $this->shopAdminId;
  289. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  290. $showBook = !empty($hasClose) ? 0 : 1;
  291. $cacheKey = 'has_hit_navigate_' . $this->shopAdminId;
  292. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  293. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  294. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  295. if ($ghsUpgrading == 1) {
  296. util::fail('系统升级中,稍后再试');
  297. }
  298. $lookAllShop = 0;
  299. $adminId = $admin['id'] ?? 0;
  300. if (getenv('YII_ENV') == 'production') {
  301. if ($adminId == 4 || $adminId == 51 || $adminId == 7335 || $adminId == 12747 || $adminId == 143686 || $adminId == 127109) {
  302. $lookAllShop = 1;
  303. }
  304. } else {
  305. $lookAllShop = 1;
  306. }
  307. //惠雅鲜花员工不能看收入情况
  308. if (in_array($adminId, [2366, 2812, 4004])) {
  309. $this->shopAdmin->super = 0;
  310. }
  311. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  312. util::success([
  313. 'token' => '',
  314. 'admin' => $admin,
  315. 'shopAdminId' => $this->shopAdminId,
  316. 'shopId' => $currentGhsShopId,
  317. 'switchShop' => $switchShop,
  318. 'openShop' => $openShop,
  319. 'showDemo' => $showDemo,
  320. //有小程序新版本提示更新
  321. 'update' => 0,
  322. 'skCustomId' => $skCustomId,
  323. 'apiHost' => $apiHost,
  324. 'imgUploadApi' => $imgUploadApi,
  325. 'showBook' => $showBook,
  326. 'hasHitNavigate' => $hasHitNavigate,
  327. 'staff' => $this->shopAdmin,
  328. 'lookAllShop' => $lookAllShop,
  329. 'labelList' => $labelList,
  330. ]);
  331. }
  332. }