AdminController.php 7.7 KB

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