123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- namespace app\wechat\controller;
- use app\common\Tree;
- use app\wechat\IndexController;
- use app\wechat\service\UserService;
- use support\Request;
- use support\Response;
- class UserController extends IndexController
- {
- public $notNeedLogin = ['login'];
- public function index(Request $request)
- {
- $params = $request->post();
- return UserService::getAll($params);
- }
- /**
- * Notes:
- * User: yb
- * Date: 2024/8/8
- * Time: 9:19
- * @param Request $request
- * @return \support\Response
- */
- public function login(Request $request)
- {
- $params = $request->post();
- if (empty($params['mobile'])) {
- return json_fail('手机号不能为空');
- }
- if (empty($params['password'])) {
- return json_fail('密码不能为空');
- }
- return UserService::login($params);
- }
- /**
- * Notes: 验证身份
- * User: yb
- * Date: 2024/8/8
- * Time: 10:08
- * @param Request $request
- */
- public function auth()
- {
- return UserService::auth();
- }
- /**
- * Notes: 统计分析
- * User: yb
- * Date: 2024/8/14
- * Time: 10:22
- */
- public function statistics(Request $request)
- {
- $params = $request->post();
- return UserService::statistics($params);
- }
- /**
- * Notes: 客户数量走势
- * User: yb
- * Date: 2024/8/17
- * Time: 17:51
- */
- public function customTrend(Request $request)
- {
- $params = $request->post();
- return UserService::customTrend($params);
- }
- /**
- * Notes: 用户详情
- * User: yb
- * Date: 2024/8/14
- * Time: 13:34
- */
- public function info()
- {
- return UserService::info();
- }
- /**
- * Notes: 成员详情
- * User: yb
- * Date: 2024/8/15
- * Time: 10:22
- * @param Request $request
- * @return Response
- */
- public function infoById(Request $request)
- {
- $params = $request->post();
- if (empty($params['id'])) {
- return json_fail('成员id不能为空');
- }
- return UserService::getInfoById($params['id']);
- }
- /**
- * Notes: 编辑成员
- * User: yb
- * Date: 2024/8/15
- * Time: 10:27
- * @param Request $request
- */
- public function updateUserById(Request $request)
- {
- $params = $request->post();
- if (empty($params['mobile'])) {
- return json_fail('手机号不能为空');
- }
- if (empty($params['name'])) {
- return json_fail('姓名不能为空');
- }
- if (empty($params['gender'])) {
- return json_fail('性别不能为空');
- }
- if (empty($params['dept_id'])) {
- return json_fail('所属部门不能为空');
- }
- if (empty($params['status'])) {
- return json_fail('状态不能为空');
- }
- return UserService::updateById($params);
- }
- /**
- * Notes: 更新用户
- * User: yb
- * Date: 2024/8/14
- * Time: 14:29
- */
- public function updateUser(Request $request)
- {
- $params = $request->post();
- if (empty($params['mobile'])) {
- return json_fail('手机号不能为空');
- }
- if (empty($params['name'])) {
- return json_fail('姓名不能为空');
- }
- if (empty($params['gender'])) {
- return json_fail('性别不能为空');
- }
- return UserService::update($params);
- }
- /**
- * Notes: 删除成员
- * User: yb
- * Date: 2024/8/15
- * Time: 11:38
- * @param Request $request
- */
- public function deleteUser(Request $request)
- {
- $params = $request->post();
- if (empty($params['id'])) {
- return json_fail('成员id不能为空');
- }
- return UserService::del($params['id']);
- }
- /**
- * Notes: 设置密码
- * User: yb
- * Date: 2024/8/14
- * Time: 14:44
- */
- public function setPassword(Request $request)
- {
- $params = $request->post();
- if (empty($params['old_password'])) {
- return json_fail('旧密码不能为空');
- }
- if (empty($params['new_password'])) {
- return json_fail('新密码不能为空');
- }
- return UserService::editPassword($params);
- }
- /**
- * Notes: 我的成员
- * User: yb
- * Date: 2024/8/14
- * Time: 15:24
- */
- public function userList(Request $request)
- {
- $params = $request->post();
- return UserService::index($params);
- }
- /**
- * Notes: 添加员工
- * User: yb
- * Date: 2024/8/15
- * Time: 9:54
- * @param Request $request
- * @return Response
- */
- public function addUser(Request $request)
- {
- $params = $request->post();
- if (empty($params['mobile'])) {
- return json_fail('手机号不能为空');
- }
- if (empty($params['name'])) {
- return json_fail('姓名不能为空');
- }
- if (empty($params['gender'])) {
- return json_fail('性别不能为空');
- }
- if (empty($params['dept_id'])) {
- return json_fail('所属部门不能为空');
- }
- if (empty($params['status'])) {
- return json_fail('状态不能为空');
- }
- return UserService::add($params);
- }
- /**
- * Notes: 我的团队
- * User: yb
- * Date: 2024/8/14
- * Time: 16:38
- * @return \support\Response
- */
- public function teamList()
- {
- return $this->formatTree(UserService::getTeamList());
- }
- protected function formatTree($items): Response
- {
- $format_items = [];
- foreach ($items as $item) {
- $format_items[] = [
- 'label' => $item->dept_name,
- 'value' => (string)$item->dept_id,
- 'id' => $item->id ?? $item->dept_id,
- 'pid' => $item->pid ?? $item->dept_super_id
- ];
- }
- $tree = new Tree($format_items);
- return json_success('success', $tree->getTree());
- }
- }
|