AdminController.php 8.8 KB

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