AdminController.php 8.7 KB

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