AdminController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace ghs\controllers;
  3. use bizHd\wx\classes\WxOpenClass;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\admin\services\AdminService;
  6. use bizHd\wx\services\WxOpenService;
  7. use common\components\util;
  8. use Yii;
  9. use yii\helpers\Json;
  10. use bizHd\user\classes\UserClass;
  11. class AdminController extends BaseController
  12. {
  13. public $guestAccess = ['recent-shop', 'mini-full-info', 'mini-mobile', 'login-detail'];
  14. //修改保存安卓clientId
  15. public function actionReplaceClientId()
  16. {
  17. $get = Yii::$app->request->get();
  18. $id = $get['id'] ?? '';
  19. if (empty($id)) {
  20. util::success(['returnStatus' => 'FAILURE']);
  21. }
  22. $this->admin->clientId = $id;
  23. $this->admin->save();
  24. util::complete();
  25. }
  26. //修改密码 shish 20220106
  27. public function actionModifyPassword()
  28. {
  29. $get = Yii::$app->request->get();
  30. $password = $get['password'] ?? '';
  31. if (empty($password)) {
  32. util::fail('请填写密码');
  33. }
  34. if (ctype_alnum($password)) {
  35. util::fail('密码必须是字母、数字和符号的组合');
  36. }
  37. $adminId = $this->adminId;
  38. $password = password_hash($password, PASSWORD_BCRYPT);
  39. AdminClass::updateById($adminId, ['password' => $password]);
  40. util::complete('操作成功');
  41. }
  42. //最近店铺 ssh 2021.2.27
  43. public function actionRecentShop()
  44. {
  45. $respond = AdminClass::getRecentShop($this->admin);
  46. util::success($respond);
  47. }
  48. //获取登陆员工的权限 ssh 2019.11.24
  49. public function actionLoginAuth()
  50. {
  51. $auth = AdminService::getAuth($this->adminId, $this->sjId);
  52. util::success($auth);
  53. }
  54. //添加员工 ssh 2019.12.8
  55. public function actionAdd()
  56. {
  57. $post = Yii::$app->request->post();
  58. $post['sjId'] = $this->sjId;
  59. $admin = AdminService::addAdmin($post);
  60. $id = $admin['id'];
  61. $info = AdminService::getDetail($id);
  62. util::success($info);
  63. }
  64. //删除员工 ssh 2019.12.9
  65. public function actionDelete()
  66. {
  67. Yii::$app->end();
  68. $id = Yii::$app->request->post('id');
  69. $admin = AdminClass::getById($id);
  70. AdminService::valid($admin, $this->sjId);
  71. AdminService::deleteAdmin($admin, $this->adminId);
  72. util::complete();
  73. }
  74. //查看员工详情 ssh 2019.12.9
  75. public function actionDetail()
  76. {
  77. $id = Yii::$app->request->get('id');
  78. $admin = AdminService::getDetail($id);
  79. AdminService::valid($admin, $this->sjId);
  80. util::success($admin);
  81. }
  82. //密码修改
  83. public function actionPassword()
  84. {
  85. $post = Yii::$app->request->post();
  86. $old = isset($post['old']) ? $post['old'] : '';
  87. $new = isset($post['new']) ? $post['new'] : '';
  88. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  89. if (empty($new)) {
  90. util::fail('请输入新密码');
  91. }
  92. if ($new != $confirm) {
  93. util::fail('二次密码不一致');
  94. }
  95. $admin = $this->admin->attributes;
  96. $adminId = $this->adminId;
  97. if (!empty($admin['password'])) {
  98. if (empty($old)) {
  99. util::fail('请填写旧密码');
  100. }
  101. if (password_verify($old, $admin['password']) == false) {
  102. util::fail('旧密码错误');
  103. }
  104. }
  105. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  106. util::complete('修改成功');
  107. }
  108. //支付密码修改
  109. public function actionConfirmPassword()
  110. {
  111. $post = Yii::$app->request->post();
  112. $old = isset($post['old']) ? $post['old'] : '';
  113. $new = isset($post['new']) ? $post['new'] : '';
  114. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  115. if (empty($new)) {
  116. util::fail('请输入新密码');
  117. }
  118. if ($new != $confirm) {
  119. util::fail('二次密码不一致');
  120. }
  121. $admin = $this->admin->attributes;
  122. $adminId = $this->adminId;
  123. if (!empty($admin['payPassword'])) {
  124. if (empty($old)) {
  125. util::fail('请填写旧密码');
  126. }
  127. if (password_verify($old, $admin['payPassword']) == false) {
  128. util::fail('旧密码错误');
  129. }
  130. }
  131. AdminService::updateById($adminId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  132. util::complete('修改成功');
  133. }
  134. //登陆员工的详情 ssh 2019.12.26
  135. public function actionLoginDetail()
  136. {
  137. $detail = AdminService::getDetail($this->adminId);
  138. util::success($detail);
  139. }
  140. //小程序用户完整信息 ssh 2019.12.12
  141. public function actionMiniFullInfo()
  142. {
  143. $post = Yii::$app->request->post();
  144. $iv = isset($post['iv']) ? $post['iv'] : '';
  145. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  146. $merchant = WxOpenClass::getGhsWxInfo();
  147. $appId = $merchant['miniAppId'];
  148. $admin = $this->admin->attributes;
  149. $miniOpenId = $admin['miniOpenId'];
  150. if (empty($miniOpenId)) {
  151. util::fail('没有找到管理员信息(miniOpenId)');
  152. }
  153. $unionId = $admin['unionId'] ?? '';
  154. if (empty($unionId)) {
  155. util::fail('没有找到管理员信息(unionId)');
  156. }
  157. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  158. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  159. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  160. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  161. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  162. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  163. if ($errCode != 0) {
  164. Yii::info($result . ' ' . $errCode);
  165. util::fail('获取用户信息失败');
  166. }
  167. Yii::info('小程序获取用户信息:' . $result);
  168. $wxInfo = Json::decode($result);
  169. $source = UserClass::$userSourceId['mini']['name'];
  170. $wxInfo['miniOpenId'] = $admin['miniOpenId'] ?? '';
  171. //这个接口没有提供unionId,这边补充一下
  172. $wxInfo['unionId'] = $unionId;
  173. $admin = AdminService::replaceAdmin($wxInfo, $source);
  174. $adminId = $admin['id'];
  175. $admin = AdminService::getAdminById($adminId);
  176. util::success($admin);
  177. }
  178. //小程序用户手机号
  179. public function actionMiniMobile()
  180. {
  181. $post = Yii::$app->request->post();
  182. $iv = $post['iv'];
  183. $encryptedData = $post['encryptedData'];
  184. $merchant = WxOpenClass::getGhsWxInfo();
  185. $appId = $merchant['miniAppId'];
  186. $admin = $this->admin->attributes;
  187. $miniOpenId = $admin['miniOpenId'];
  188. if (empty($miniOpenId)) {
  189. util::fail('没有找到管理员信息(miniOpenId)');
  190. }
  191. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  192. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  193. if (empty($sessionKey)) {
  194. util::fail('sesstion key empty');
  195. }
  196. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  197. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  198. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  199. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  200. if ($errCode != 0) {
  201. util::fail('解密失败');
  202. }
  203. $arr = Json::decode($result);
  204. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  205. $originalMobile = $admin['mobile'] ?? '';
  206. if (empty($originalMobile)) {
  207. \biz\admin\classes\AdminClass::updateById($this->adminId, ['mobile' => $mobile]);
  208. }
  209. util::success(['mobile' => $mobile]);
  210. }
  211. //已经存有token,但没有store信息重新获取
  212. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  213. public function actionAppReGetLoginInfo()
  214. {
  215. $admin = $this->admin;
  216. $currentShopId = $admin->currentShopId ?? 0;
  217. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($this->shopAdmin->attributes);
  218. $openShop = $admin['openShop'] ?? 1;
  219. $showDemo = 1;
  220. $skCustomId = $this->shop->skCustomId ?? 0;
  221. $apiHost = Yii::$app->params['ghsHost'];
  222. $imgUploadApi = $apiHost . '/upload/save-file';
  223. //使用手册
  224. $cacheKey = 'close_book_' . $this->shopAdminId;
  225. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  226. $showBook = !empty($hasClose) ? 0 : 1;
  227. $cacheKey = 'has_hit_navigate_' . $this->shopAdminId;
  228. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  229. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  230. util::success([
  231. 'token' => '',
  232. 'admin' => $admin,
  233. 'shopAdminId' => $this->shopAdminId,
  234. 'shopId' => $currentShopId,
  235. 'switchShop' => $switchShop,
  236. 'openShop' => $openShop,
  237. 'showDemo' => $showDemo,
  238. //有小程序新版本提示更新
  239. 'update' => 0,
  240. 'skCustomId' => $skCustomId,
  241. 'apiHost' => $apiHost,
  242. 'imgUploadApi' => $imgUploadApi,
  243. 'showBook' => $showBook,
  244. 'hasHitNavigate' => $hasHitNavigate,
  245. ]);
  246. }
  247. }