AdminController.php 5.3 KB

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