| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- namespace hd\controllers;
- use bizHd\admin\classes\AdminClass;
- use bizHd\admin\services\AdminService;
- use bizHd\wx\services\WxOpenService;
- use common\components\util;
- use Yii;
- use yii\helpers\Json;
- use bizHd\user\classes\UserClass;
- class AdminController extends BaseController
- {
- public $guestAccess = ['mini-full-info', 'mini-mobile', 'login-detail'];
- //最近店铺 ssh 2021.2.27
- public function actionRecentShop()
- {
- util::success([]);
- }
- //获取登陆员工的权限 ssh 2019.11.24
- public function actionLoginAuth()
- {
- $auth = AdminService::getAuth($this->adminId, $this->sjId);
- util::success($auth);
- }
- //添加员工 ssh 2019.12.8
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $admin = AdminService::addAdmin($post);
- $id = $admin['id'];
- $info = AdminService::getDetail($id);
- util::success($info);
- }
- //删除员工 ssh 2019.12.9
- public function actionDelete()
- {
- $id = Yii::$app->request->post('id');
- $admin = AdminClass::getById($id);
- AdminService::valid($admin, $this->sjId);
- AdminService::deleteAdmin($admin, $this->adminId);
- util::complete();
- }
- //修改员工 ssh 2019.12.9
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
- unset($post['id']);
- $originalAdmin = AdminService::getById($id);
- $post['sjId'] = $this->sjId;
- AdminService::updateAdmin($originalAdmin, $post);
- util::complete('修改成功');
- }
- //查看员工详情 ssh 2019.12.9
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id');
- $admin = AdminService::getDetail($id);
- AdminService::valid($admin, $this->sjId);
- util::success($admin);
- }
- //密码修改
- public function actionPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $admin = $this->admin->attributes;
- $adminId = $this->adminId;
- if (!empty($admin['password'])) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $admin['password']) == false) {
- util::fail('旧密码错误');
- }
- }
- AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
- util::complete('修改成功');
- }
- //确认密码修改
- public function actionConfirmPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $admin = $this->admin->attributes;
- $adminId = $this->adminId;
- if (!empty($admin['payPassword'])) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $admin['payPassword']) == false) {
- util::fail('旧密码错误');
- }
- }
- AdminService::updateById($adminId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT)]);
- util::complete('修改成功');
- }
- //登陆员工的详情 ssh 2019.12.26
- public function actionLoginDetail()
- {
- $detail = AdminService::getDetail($this->adminId);
- util::success($detail);
- }
- //授权信息并实现自动登录 shish 20210121
- public function actionAuthToAutoLogin()
- {
- $post = Yii::$app->request->post();
- $iv = isset($post['iv']) ? $post['iv'] : '';
- $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
- $merchant = WxOpenService::getWxInfo();
- $appId = $merchant['miniAppId'];
- $miniOpenId = $post['miniOpenId'];
- if (empty($miniOpenId)) {
- util::fail('启用失败');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::info($result . ' ' . $errCode);
- util::fail('获取用户信息失败');
- }
- Yii::info('小程序获取用户信息:' . $result);
- $wxInfo = Json::decode($result);
- print_r($wxInfo);
- }
- //小程序用户完整信息 ssh 2019.12.12
- public function actionMiniFullInfo()
- {
- $post = Yii::$app->request->post();
- $iv = isset($post['iv']) ? $post['iv'] : '';
- $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
- $merchant = WxOpenService::getWxInfo();
- $appId = $merchant['miniAppId'];
- $admin = $this->admin->attributes;
- $miniOpenId = $admin['miniOpenId'];
- if (empty($miniOpenId)) {
- util::fail('没有找到管理员信息(miniOpenId)');
- }
- $unionId = $admin['unionId'] ?? '';
- if (empty($unionId)) {
- util::fail('没有找到管理员信息(unionId)');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::info($result . ' ' . $errCode);
- util::fail('获取用户信息失败');
- }
- Yii::info('小程序获取用户信息:' . $result);
- $wxInfo = Json::decode($result);
- $source = UserClass::$userSourceId['mini']['name'];
- $wxInfo['miniOpenId'] = $admin['miniOpenId'] ?? '';
- //这个接口没有提供unionId,这边补充一下
- $wxInfo['unionId'] = $unionId;
- $admin = AdminService::replaceAdmin($wxInfo, $source);
- $adminId = $admin['id'];
- $admin = AdminService::getAdminById($adminId);
- util::success($admin);
- }
- //小程序用户手机号
- public function actionMiniMobile()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'];
- $encryptedData = $post['encryptedData'];
- $merchant = WxOpenService::getWxInfo();
- $appId = $merchant['miniAppId'];
- $admin = $this->admin->attributes;
- $miniOpenId = $admin['miniOpenId'];
- if (empty($miniOpenId)) {
- util::fail('没有找到管理员信息(miniOpenId)');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- util::fail('sesstion key empty');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- util::fail('解密失败');
- }
- $arr = Json::decode($result);
- $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
- $originalMobile = $admin['mobile'] ?? '';
- if (empty($originalMobile)) {
- \biz\admin\classes\AdminClass::updateById($this->adminId, ['mobile' => $mobile]);
- }
- util::success(['mobile' => $mobile]);
- }
- //设置支付密码 ssh 2021.1.24
- public function actionSetPayPassword()
- {
- $get = Yii::$app->request->get();
- $adminId = $this->adminId;
- $info = AdminClass::getAdminById($adminId);
- if (isset($info['payPassword']) && !empty($info['payPassword'])) {
- util::fail('您已经设置了支付密码');
- }
- $password = $get['password'] ?? '';
- if (empty($password)) {
- util::fail('请输入支付密码');
- }
- $string = password_hash($password, PASSWORD_BCRYPT);
- AdminClass::updateById($adminId, ['payPassword' => $string]);
- $data = ['payPassword' => $string];
- util::success($data);
- }
- }
|