You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.2 KiB
132 lines
4.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\kefu\controller;
|
|
|
|
use app\kefu\controller\AuthController;
|
|
use app\kefu\model\KefuModel;
|
|
use app\kefu\services\KefuChatService;
|
|
use service\FormBuilder as Form;
|
|
use service\JsonService as Json;
|
|
use service\UploadService as Upload;
|
|
use think\Request;
|
|
use think\Url;
|
|
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
|
use app\admin\model\article\Article as ArticleModel;
|
|
use app\kefu\model\user\UserGroupModel;
|
|
use think\Session;
|
|
use service\JwtService;
|
|
use app\kefu\services\KefuRecordService;
|
|
use app\kefu\model\user\UserLabelModel;
|
|
use app\kefu\model\user\UserLabelCate;
|
|
use app\admin\model\user\User as UserModel;
|
|
use app\kefu\model\user\UserLabelRelation;
|
|
|
|
class User extends AuthController
|
|
{
|
|
public function set_group($uid, $id)
|
|
{
|
|
$user = UserModel::get($uid);
|
|
if (!$user) return Json::fail("用户不存在!");
|
|
|
|
$group = UserGroupModel::get($id);
|
|
if (!$group) return Json::fail("分组不存在!");
|
|
|
|
$user->group_id = $id;
|
|
$user->save();
|
|
|
|
return Json::successful("设置成功!");
|
|
}
|
|
|
|
public function get_user_group()
|
|
{
|
|
$data = (new UserGroupModel)->select();
|
|
|
|
return Json::successful($data);
|
|
}
|
|
|
|
public function get_user_info($uid)
|
|
{
|
|
$info = (new UserModel)->field('nickname, avatar, spread_uid, is_promoter, now_money, user_type, is_h5user, level, phone, group_id')->find($uid);
|
|
|
|
if (!$info->user_type) {
|
|
if ($info->is_h5user === 1) {
|
|
$info->user_type = "h5";
|
|
} else if ($info->is_h5user === 2) {
|
|
$info->user_type = "pc";
|
|
}
|
|
}
|
|
|
|
$group_info = $info->groupInfo()->find();
|
|
|
|
$user_labels = $info->userLabel()
|
|
->select()
|
|
->each(function ($relation) {
|
|
$relation->label_name = $relation->userLabel()->find()->label_name;
|
|
})
|
|
->toArray();
|
|
|
|
$info->labelNames = array_column($user_labels, 'label_name');
|
|
|
|
$info->group_name = $group_info && $group_info->group_name ? $group_info->group_name : "";
|
|
|
|
return Json::successful($info);
|
|
}
|
|
|
|
public function get_label($uid)
|
|
{
|
|
$user = UserModel::get($uid);
|
|
if (!$user) return Json::fail("用户不存在!");
|
|
|
|
$user_label_list = $user->userLabel()->select()->toArray();
|
|
$user_label_id_list = array_column($user_label_list, 'label_id');
|
|
|
|
$all_label_cate = (new UserLabelCate)
|
|
->select()
|
|
->each(function ($cate) use ($user_label_id_list) {
|
|
$cate->label = $cate
|
|
->labelList()
|
|
->select()
|
|
->each(function ($label) use ($user_label_id_list) {
|
|
$label->disabled = in_array($label->id, $user_label_id_list);
|
|
});
|
|
})
|
|
->filter(function ($cate) {
|
|
return count($cate->label) > 0;
|
|
});
|
|
|
|
return Json::successful($all_label_cate);
|
|
}
|
|
|
|
public function save_user_label($uid = '', $label_ids = [], $un_label_ids = [])
|
|
{
|
|
$user = UserModel::get($uid);
|
|
if (!$user) return Json::fail("用户不存在!");
|
|
|
|
(new UserLabelRelation)
|
|
->where('uid', $uid)
|
|
->delete();
|
|
|
|
if (count($label_ids)) {
|
|
$allData = [];
|
|
|
|
foreach ($label_ids as $v) {
|
|
$allData[] = [
|
|
'label_id' => $v,
|
|
'uid' => $uid
|
|
];
|
|
}
|
|
(new UserLabelRelation)->saveAll($allData);
|
|
}
|
|
|
|
return Json::successful("保存成功!");
|
|
}
|
|
}
|
|
|