AdminController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\admin\classes\AdminClass;
  4. use bizGhs\admin\services\AdminService;
  5. use biz\wx\services\WxOpenService;
  6. use common\components\util;
  7. use Yii;
  8. use yii\helpers\Json;
  9. use biz\user\classes\UserClass;
  10. class AdminController extends BaseController
  11. {
  12. public $withoutLogin = [];
  13. //获取登陆员工的权限 shish 2019.11.24
  14. public function actionLoginAuth()
  15. {
  16. $auth = AdminService::getAuth($this->adminId, $this->ghsId);
  17. util::success($auth);
  18. }
  19. //添加员工 shish 2019.12.8
  20. public function actionAdd()
  21. {
  22. $post = Yii::$app->request->post();
  23. $post['merchantId'] = $this->ghsId;
  24. $admin = AdminService::addAdmin($post);
  25. $id = $admin['id'];
  26. $info = AdminService::getDetail($id);
  27. util::success($info);
  28. }
  29. //删除员工 shish 2019.12.9
  30. public function actionDelete()
  31. {
  32. $id = Yii::$app->request->post('id');
  33. $admin = AdminClass::getById($id);
  34. AdminService::valid($admin, $this->ghsId);
  35. AdminService::deleteAdmin($admin, $this->adminId);
  36. util::complete();
  37. }
  38. //修改员工 shish 2019.12.9
  39. public function actionUpdate()
  40. {
  41. }
  42. //查看员工详情 shish 2019.12.9
  43. public function actionDetail()
  44. {
  45. $id = Yii::$app->request->get('id');
  46. $admin = AdminService::getDetail($id);
  47. AdminService::valid($admin, $this->ghsId);
  48. util::success($admin);
  49. }
  50. //密码修改
  51. public function actionPassword()
  52. {
  53. $post = Yii::$app->request->post();
  54. $old = isset($post['old']) ? $post['old'] : '';
  55. $new = isset($post['new']) ? $post['new'] : '';
  56. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  57. if (empty($new)) {
  58. util::fail('请输入新密码');
  59. }
  60. if ($new != $confirm) {
  61. util::fail('二次密码不一致');
  62. }
  63. $admin = $this->admin;
  64. $adminId = $this->adminId;
  65. if (!empty($admin['password'])) {
  66. if (empty($old)) {
  67. util::fail('请填写旧密码');
  68. }
  69. if (password_verify($old, $admin['password']) == false) {
  70. util::fail('旧密码错误');
  71. }
  72. }
  73. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  74. util::complete('修改成功');
  75. }
  76. //确认密码修改
  77. public function actionConfirmPassword()
  78. {
  79. $post = Yii::$app->request->post();
  80. $old = isset($post['old']) ? $post['old'] : '';
  81. $new = isset($post['new']) ? $post['new'] : '';
  82. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  83. if (empty($new)) {
  84. util::fail('请输入新密码');
  85. }
  86. if ($new != $confirm) {
  87. util::fail('二次密码不一致');
  88. }
  89. $admin = $this->admin;
  90. $adminId = $this->adminId;
  91. if (!empty($admin['confirmPassword'])) {
  92. if (empty($old)) {
  93. util::fail('请填写旧密码');
  94. }
  95. if (password_verify($old, $admin['confirmPassword']) == false) {
  96. util::fail('旧密码错误');
  97. }
  98. }
  99. AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  100. util::complete('修改成功');
  101. }
  102. //登陆员工的详情 shish 2019.12.26
  103. public function actionLoginDetail()
  104. {
  105. $detail = AdminService::getDetail($this->adminId);
  106. util::success($detail);
  107. }
  108. //小程序用户完整信息 shish 2019.12.12
  109. public function actionMiniFullInfo()
  110. {
  111. $post = Yii::$app->request->post();
  112. $iv = isset($post['iv']) ? $post['iv'] : '';
  113. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  114. $merchant = WxOpenService::getWxInfo();
  115. $appId = $merchant['miniAppId'];
  116. $admin = $this->admin;
  117. $miniOpenId = $admin['miniOpenId'];
  118. if (empty($miniOpenId)) {
  119. util::fail('没有找到管理员信息(miniOpenId)');
  120. }
  121. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  122. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  123. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  124. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  125. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  126. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  127. if ($errCode != 0) {
  128. Yii::info($result . ' ' . $errCode);
  129. util::fail('获取用户信息失败');
  130. }
  131. Yii::info('小程序获取用户信息:' . $result);
  132. $originalInfo = Json::decode($result);
  133. $source = UserClass::$userSourceId['mini']['name'];
  134. $admin = AdminService::replaceAdmin($originalInfo, $source);
  135. $adminId = $admin['id'];
  136. $admin = AdminService::getAdminById($adminId);
  137. util::success($admin);
  138. }
  139. //小程序用户手机号
  140. public function actionMiniMobile()
  141. {
  142. $post = Yii::$app->request->post();
  143. $iv = $post['iv'];
  144. $encryptedData = $post['encryptedData'];
  145. $merchant = WxOpenService::getWxInfo();
  146. $appId = $merchant['miniAppId'];
  147. $admin = $this->admin;
  148. $miniOpenId = $admin['miniOpenId'];
  149. if (empty($miniOpenId)) {
  150. util::fail('没有找到管理员信息(miniOpenId)');
  151. }
  152. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  153. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  154. if (empty($sessionKey)) {
  155. util::fail('sesstion key empty');
  156. }
  157. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  158. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  159. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  160. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  161. if ($errCode != 0) {
  162. util::fail('解密失败');
  163. }
  164. $arr = Json::decode($result);
  165. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  166. util::success(['mobile' => $mobile]);
  167. }
  168. }