AdminController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 $guestAccessAction = ['recent-shop'];
  14. //最近店铺 shish 2021.2.27
  15. public function actionRecentShop()
  16. {
  17. $respond = AdminClass::getRecentShop($this->admin);
  18. util::success($respond);
  19. }
  20. //获取登陆员工的权限 shish 2019.11.24
  21. public function actionLoginAuth()
  22. {
  23. $auth = AdminService::getAuth($this->adminId, $this->sjId);
  24. util::success($auth);
  25. }
  26. //添加员工 shish 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. //删除员工 shish 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. //查看员工详情 shish 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['confirmPassword'])) {
  96. if (empty($old)) {
  97. util::fail('请填写旧密码');
  98. }
  99. if (password_verify($old, $admin['confirmPassword']) == false) {
  100. util::fail('旧密码错误');
  101. }
  102. }
  103. AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  104. util::complete('修改成功');
  105. }
  106. //登陆员工的详情 shish 2019.12.26
  107. public function actionLoginDetail()
  108. {
  109. $detail = AdminService::getDetail($this->adminId);
  110. util::success($detail);
  111. }
  112. //小程序用户完整信息 shish 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. $originalInfo = Json::decode($result);
  137. $source = UserClass::$userSourceId['mini']['name'];
  138. $admin = AdminService::replaceAdmin($originalInfo, $source);
  139. $adminId = $admin['id'];
  140. $admin = AdminService::getAdminById($adminId);
  141. util::success($admin);
  142. }
  143. //小程序用户手机号
  144. public function actionMiniMobile()
  145. {
  146. $post = Yii::$app->request->post();
  147. $iv = $post['iv'];
  148. $encryptedData = $post['encryptedData'];
  149. $merchant = WxOpenClass::getGhsWxInfo();
  150. $appId = $merchant['miniAppId'];
  151. $admin = $this->admin;
  152. $miniOpenId = $admin['miniOpenId'];
  153. if (empty($miniOpenId)) {
  154. util::fail('没有找到管理员信息(miniOpenId)');
  155. }
  156. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  157. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  158. if (empty($sessionKey)) {
  159. util::fail('sesstion key empty');
  160. }
  161. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  162. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  163. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  164. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  165. if ($errCode != 0) {
  166. util::fail('解密失败');
  167. }
  168. $arr = Json::decode($result);
  169. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  170. util::success(['mobile' => $mobile]);
  171. }
  172. }