|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
+use biz\wx\classes\WxOpenClass;
|
|
|
use bizGhs\admin\classes\AdminClass;
|
|
|
use bizGhs\admin\services\AdminService;
|
|
|
use biz\wx\services\WxOpenService;
|
|
|
@@ -12,170 +13,170 @@ use biz\user\classes\UserClass;
|
|
|
|
|
|
class AdminController extends BaseController
|
|
|
{
|
|
|
-
|
|
|
- public $withoutLogin = [];
|
|
|
-
|
|
|
- //获取登陆员工的权限 shish 2019.11.24
|
|
|
- public function actionLoginAuth()
|
|
|
- {
|
|
|
- $auth = AdminService::getAuth($this->adminId, $this->ghsId);
|
|
|
- util::success($auth);
|
|
|
- }
|
|
|
-
|
|
|
- //添加员工 shish 2019.12.8
|
|
|
- public function actionAdd()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $post['merchantId'] = $this->ghsId;
|
|
|
- $admin = AdminService::addAdmin($post);
|
|
|
- $id = $admin['id'];
|
|
|
- $info = AdminService::getDetail($id);
|
|
|
- util::success($info);
|
|
|
- }
|
|
|
-
|
|
|
- //删除员工 shish 2019.12.9
|
|
|
- public function actionDelete()
|
|
|
- {
|
|
|
- Yii::$app->end();
|
|
|
- $id = Yii::$app->request->post('id');
|
|
|
- $admin = AdminClass::getById($id);
|
|
|
- AdminService::valid($admin, $this->ghsId);
|
|
|
- AdminService::deleteAdmin($admin, $this->adminId);
|
|
|
- util::complete();
|
|
|
- }
|
|
|
-
|
|
|
- //查看员工详情 shish 2019.12.9
|
|
|
- public function actionDetail()
|
|
|
- {
|
|
|
- $id = Yii::$app->request->get('id');
|
|
|
- $admin = AdminService::getDetail($id);
|
|
|
- AdminService::valid($admin, $this->ghsId);
|
|
|
- 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;
|
|
|
- $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;
|
|
|
- $adminId = $this->adminId;
|
|
|
- if (!empty($admin['confirmPassword'])) {
|
|
|
- if (empty($old)) {
|
|
|
- util::fail('请填写旧密码');
|
|
|
- }
|
|
|
- if (password_verify($old, $admin['confirmPassword']) == false) {
|
|
|
- util::fail('旧密码错误');
|
|
|
- }
|
|
|
- }
|
|
|
- AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
|
|
|
- util::complete('修改成功');
|
|
|
- }
|
|
|
-
|
|
|
- //登陆员工的详情 shish 2019.12.26
|
|
|
- public function actionLoginDetail()
|
|
|
- {
|
|
|
- $detail = AdminService::getDetail($this->adminId);
|
|
|
- util::success($detail);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //小程序用户完整信息 shish 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;
|
|
|
- $miniOpenId = $admin['miniOpenId'];
|
|
|
- if (empty($miniOpenId)) {
|
|
|
- util::fail('没有找到管理员信息(miniOpenId)');
|
|
|
- }
|
|
|
- $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);
|
|
|
- $originalInfo = Json::decode($result);
|
|
|
- $source = UserClass::$userSourceId['mini']['name'];
|
|
|
- $admin = AdminService::replaceAdmin($originalInfo, $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;
|
|
|
- $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'] : '';
|
|
|
- util::success(['mobile' => $mobile]);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public $withoutLogin = [];
|
|
|
+
|
|
|
+ //获取登陆员工的权限 shish 2019.11.24
|
|
|
+ public function actionLoginAuth()
|
|
|
+ {
|
|
|
+ $auth = AdminService::getAuth($this->adminId, $this->ghsId);
|
|
|
+ util::success($auth);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加员工 shish 2019.12.8
|
|
|
+ public function actionAdd()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $post['merchantId'] = $this->ghsId;
|
|
|
+ $admin = AdminService::addAdmin($post);
|
|
|
+ $id = $admin['id'];
|
|
|
+ $info = AdminService::getDetail($id);
|
|
|
+ util::success($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除员工 shish 2019.12.9
|
|
|
+ public function actionDelete()
|
|
|
+ {
|
|
|
+ Yii::$app->end();
|
|
|
+ $id = Yii::$app->request->post('id');
|
|
|
+ $admin = AdminClass::getById($id);
|
|
|
+ AdminService::valid($admin, $this->ghsId);
|
|
|
+ AdminService::deleteAdmin($admin, $this->adminId);
|
|
|
+ util::complete();
|
|
|
+ }
|
|
|
+
|
|
|
+ //查看员工详情 shish 2019.12.9
|
|
|
+ public function actionDetail()
|
|
|
+ {
|
|
|
+ $id = Yii::$app->request->get('id');
|
|
|
+ $admin = AdminService::getDetail($id);
|
|
|
+ AdminService::valid($admin, $this->ghsId);
|
|
|
+ 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;
|
|
|
+ $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;
|
|
|
+ $adminId = $this->adminId;
|
|
|
+ if (!empty($admin['confirmPassword'])) {
|
|
|
+ if (empty($old)) {
|
|
|
+ util::fail('请填写旧密码');
|
|
|
+ }
|
|
|
+ if (password_verify($old, $admin['confirmPassword']) == false) {
|
|
|
+ util::fail('旧密码错误');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
|
|
|
+ util::complete('修改成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //登陆员工的详情 shish 2019.12.26
|
|
|
+ public function actionLoginDetail()
|
|
|
+ {
|
|
|
+ $detail = AdminService::getDetail($this->adminId);
|
|
|
+ util::success($detail);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //小程序用户完整信息 shish 2019.12.12
|
|
|
+ public function actionMiniFullInfo()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $iv = isset($post['iv']) ? $post['iv'] : '';
|
|
|
+ $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
|
|
|
+ $merchant = WxOpenClass::getGhsWxInfo();
|
|
|
+ $appId = $merchant['miniAppId'];
|
|
|
+ $admin = $this->admin;
|
|
|
+ $miniOpenId = $admin['miniOpenId'];
|
|
|
+ if (empty($miniOpenId)) {
|
|
|
+ util::fail('没有找到管理员信息(miniOpenId)');
|
|
|
+ }
|
|
|
+ $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);
|
|
|
+ $originalInfo = Json::decode($result);
|
|
|
+ $source = UserClass::$userSourceId['mini']['name'];
|
|
|
+ $admin = AdminService::replaceAdmin($originalInfo, $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 = WxOpenClass::getGhsWxInfo();
|
|
|
+ $appId = $merchant['miniAppId'];
|
|
|
+ $admin = $this->admin;
|
|
|
+ $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'] : '';
|
|
|
+ util::success(['mobile' => $mobile]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|