AdminController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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['merchantId'] = $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;
  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;
  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;
  121. $miniOpenId = $admin['miniOpenId'];
  122. if (empty($miniOpenId)) {
  123. util::fail('没有找到管理员信息(miniOpenId)');
  124. }
  125. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  126. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  127. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  128. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  129. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  130. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  131. if ($errCode != 0) {
  132. Yii::info($result . ' ' . $errCode);
  133. util::fail('获取用户信息失败');
  134. }
  135. Yii::info('小程序获取用户信息:' . $result);
  136. $wxInfo = Json::decode($result);
  137. $source = UserClass::$userSourceId['mini']['name'];
  138. $wxInfo['miniOpenId'] = $admin['miniOpenId'] ?? '';
  139. $admin = AdminService::replaceAdmin($wxInfo, $source);
  140. $adminId = $admin['id'];
  141. $admin = AdminService::getAdminById($adminId);
  142. util::success($admin);
  143. }
  144. //小程序用户手机号
  145. public function actionMiniMobile()
  146. {
  147. $post = Yii::$app->request->post();
  148. $iv = $post['iv'];
  149. $encryptedData = $post['encryptedData'];
  150. $merchant = WxOpenClass::getGhsWxInfo();
  151. $appId = $merchant['miniAppId'];
  152. $admin = $this->admin;
  153. $miniOpenId = $admin['miniOpenId'];
  154. if (empty($miniOpenId)) {
  155. util::fail('没有找到管理员信息(miniOpenId)');
  156. }
  157. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  158. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  159. if (empty($sessionKey)) {
  160. util::fail('sesstion key empty');
  161. }
  162. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  163. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  164. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  165. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  166. if ($errCode != 0) {
  167. util::fail('解密失败');
  168. }
  169. $arr = Json::decode($result);
  170. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  171. $originalMobile = $admin['mobile'] ?? '';
  172. if (empty($originalMobile)) {
  173. \biz\admin\classes\AdminClass::updateById($this->adminId, ['mobile' => $mobile]);
  174. }
  175. util::success(['mobile' => $mobile]);
  176. }
  177. }