AdminController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace shop\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\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->merchantId);
  17. util::success($auth);
  18. }
  19. //员工列表 shish 2019.12.8
  20. public function actionList()
  21. {
  22. $get = Yii::$app->request->get();
  23. $where = [];
  24. $where['merchantId'] = $this->merchantId;
  25. $where['delStatus'] = 0;
  26. $list = AdminService::getAdminList($where);
  27. util::success($list);
  28. }
  29. //添加员工 shish 2019.12.8
  30. public function actionAdd()
  31. {
  32. $post = Yii::$app->request->post();
  33. $post['merchantId'] = $this->merchantId;
  34. $admin = AdminService::addAdmin($post);
  35. $id = $admin['id'];
  36. $info = AdminService::getDetail($id);
  37. util::success($info);
  38. }
  39. //删除员工 shish 2019.12.9
  40. public function actionDelete()
  41. {
  42. $id = Yii::$app->request->post('id');
  43. $admin = AdminClass::getById($id);
  44. AdminService::valid($admin, $this->merchantId);
  45. AdminService::deleteAdmin($admin, $this->adminId);
  46. util::complete();
  47. }
  48. //修改员工 shish 2019.12.9
  49. public function actionUpdate()
  50. {
  51. $post = Yii::$app->request->post();
  52. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  53. unset($post['id']);
  54. $originalAdmin = AdminService::getById($id);
  55. $post['merchantId'] = $this->merchantId;
  56. AdminService::updateAdmin($originalAdmin, $post);
  57. util::complete('修改成功');
  58. }
  59. //查看员工详情 shish 2019.12.9
  60. public function actionDetail()
  61. {
  62. $id = Yii::$app->request->get('id');
  63. $admin = AdminService::getDetail($id);
  64. AdminService::valid($admin, $this->merchantId);
  65. util::success($admin);
  66. }
  67. //密码修改
  68. public function actionPassword()
  69. {
  70. $post = Yii::$app->request->post();
  71. $old = isset($post['old']) ? $post['old'] : '';
  72. $new = isset($post['new']) ? $post['new'] : '';
  73. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  74. if (empty($new)) {
  75. util::fail('请输入新密码');
  76. }
  77. if ($new != $confirm) {
  78. util::fail('二次密码不一致');
  79. }
  80. $admin = $this->admin;
  81. $adminId = $this->adminId;
  82. if (!empty($admin['password'])) {
  83. if (empty($old)) {
  84. util::fail('请填写旧密码');
  85. }
  86. if (password_verify($old, $admin['password']) == false) {
  87. util::fail('旧密码错误');
  88. }
  89. }
  90. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  91. util::complete('修改成功');
  92. }
  93. //确认密码修改
  94. public function actionConfirmPassword()
  95. {
  96. $post = Yii::$app->request->post();
  97. $old = isset($post['old']) ? $post['old'] : '';
  98. $new = isset($post['new']) ? $post['new'] : '';
  99. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  100. if (empty($new)) {
  101. util::fail('请输入新密码');
  102. }
  103. if ($new != $confirm) {
  104. util::fail('二次密码不一致');
  105. }
  106. $admin = $this->admin;
  107. $adminId = $this->adminId;
  108. if (!empty($admin['confirmPassword'])) {
  109. if (empty($old)) {
  110. util::fail('请填写旧密码');
  111. }
  112. if (password_verify($old, $admin['confirmPassword']) == false) {
  113. util::fail('旧密码错误');
  114. }
  115. }
  116. AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  117. util::complete('修改成功');
  118. }
  119. //登陆员工的详情 shish 2019.12.26
  120. public function actionLoginDetail()
  121. {
  122. $detail = AdminService::getDetail($this->adminId);
  123. util::success($detail);
  124. }
  125. //收款通知 shish 2020.1.4
  126. public function actionUpdateRemind()
  127. {
  128. $get = Yii::$app->request->get();
  129. $id = isset($get['id']) ? $get['id'] : 0;
  130. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  131. $admin = AdminService::getAdminById($id);
  132. AdminService::valid($admin, $this->merchantId);
  133. AdminService::updateById($id, ['remind' => $remind]);
  134. util::complete();
  135. }
  136. //启用与停用 shish 2020.1.4
  137. public function actionUpdateStatus()
  138. {
  139. $get = Yii::$app->request->get();
  140. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  141. $status = isset($get['status']) ? $get['status'] : 0;
  142. $admin = AdminService::getAdminById($id);
  143. AdminService::valid($admin, $this->merchantId);
  144. AdminService::updateById($id, ['status' => $status]);
  145. util::complete();
  146. }
  147. //小程序用户完整信息 shish 2019.12.12
  148. public function actionMiniFullInfo()
  149. {
  150. $post = Yii::$app->request->post();
  151. $iv = isset($post['iv']) ? $post['iv'] : '';
  152. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  153. $merchant = WxOpenService::getWxInfo();
  154. $appId = $merchant['miniAppId'];
  155. $admin = $this->admin;
  156. $miniOpenId = $admin['miniOpenId'];
  157. if (empty($miniOpenId)) {
  158. util::fail('没有找到管理员信息(miniOpenId)');
  159. }
  160. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  161. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  162. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  163. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  164. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  165. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  166. if ($errCode != 0) {
  167. Yii::info($result . ' ' . $errCode);
  168. util::fail('获取用户信息失败');
  169. }
  170. Yii::info('小程序获取用户信息:' . $result);
  171. $originalInfo = Json::decode($result);
  172. $source = UserClass::$userSourceId['mini']['name'];
  173. $admin = AdminService::replaceAdmin($originalInfo, $source);
  174. $adminId = $admin['id'];
  175. $admin = AdminService::getAdminById($adminId);
  176. util::success($admin);
  177. }
  178. //小程序用户手机号
  179. public function actionMiniMobile()
  180. {
  181. $post = Yii::$app->request->post();
  182. $iv = $post['iv'];
  183. $encryptedData = $post['encryptedData'];
  184. $merchant = WxOpenService::getWxInfo();
  185. $appId = $merchant['miniAppId'];
  186. $admin = $this->admin;
  187. $miniOpenId = $admin['miniOpenId'];
  188. if (empty($miniOpenId)) {
  189. util::fail('没有找到管理员信息(miniOpenId)');
  190. }
  191. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  192. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  193. if (empty($sessionKey)) {
  194. util::fail('sesstion key empty');
  195. }
  196. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  197. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  198. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  199. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  200. if ($errCode != 0) {
  201. util::fail('解密失败');
  202. }
  203. $arr = Json::decode($result);
  204. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  205. util::success(['mobile' => $mobile]);
  206. }
  207. }