123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/3/24
- * Time: 18:34
- */
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\RedisModel;
- use App\Service\DjUserService;
- use App\Service\LicenseService;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- class UserController extends Controller
- {
- /**
- * 检索框内部员工(客服)列表
- * @param Request $request
- * @return array
- */
- public function userList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_name' => 'nullable|string'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userName = $request->input('user_name');
- $status = $request->input('status');
- $data = DjUserService::userList($corpid, $userName, $status);
- return self::returnValue($data);
- }
- public function users(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_name' => 'nullable|string'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userName = $request->input('user_name');
- $isActive = $request->input('is_active');
- $userIds = $request->input('user_ids');
- $departmentList = $request->input('department_list');
- $appId = $request->input('app_id');
- $accountId = $request->input('account_id');
- $operatorId = $request->input('operator_id');// 运营人员ID
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $expireDays = $request->input('expire_days');
- list($data, $count, $yesterdayAdd, $yesterdayLoss, $customerCount) = DjUserService::users(
- $corpid, $userName, $userIds, $departmentList, $page, $pageSize, $isActive, $appId, $accountId, $operatorId,
- $expireDays
- );
- $extra = ['user_count' => $count, 'user_add_yesterday' => $yesterdayAdd, 'user_loss_yesterday' => $yesterdayLoss
- , 'customer_count' => $customerCount];
- return self::returnPageValue($data, $count, $pageSize, $page, $extra);
- }
- /**
- * 成员详情
- * @param Request $request
- * @return array
- */
- public function user_info(Request $request){
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_id' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $user_id = $request->input('user_id');
- $res = DjUserService::user_info($corpid,$user_id);
- return self::returnValue($res);
- }
- /**
- * 成员会话统计
- * @param Request $request
- * @return array
- */
- public function conversation_report(Request $request){
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_id' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $user_id = $request->input('user_id');
- $begin_date = $request->input('begin_date',date("Y-m-d",strtotime("-1days")));
- $end_date = $request->input('end_date',date("Y-m-d",strtotime("-1days")));
- $list = DjUserService::conversation_report($corpid, $user_id, $begin_date, $end_date);
- return self::returnValue(['list'=>$list]);
- }
- /**
- * 成员会话报表汇总
- * @param Request $request
- * @return array
- */
- public function conversation_report_total(Request $request){
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_id' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $user_id = $request->input('user_id');
- $begin_date = $request->input('begin_date',date("Y-m-d",strtotime("-1days")));
- $end_date = $request->input('end_date',date("Y-m-d",strtotime("-1days")));
- $total = DjUserService::conversation_report_total($corpid, $user_id, $begin_date, $end_date);
- return self::returnValue(['total'=>$total]);
- }
- public function departments(Request $request)
- {
- $corpid = $request->input('corpid');
- $data = DjUserService::departments($corpid);
- return self::returnValue($data);
- }
- public function bindUserAdqAccountId(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'user_id' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $accountId = $request->input('account_id');
- $sysGroupId = $request->input('sys_group_id');
- $appId = $request->input('app_id');
- $operatorId = $request->input('operator_id');
- list($res, $code) = DjUserService::bindUserAdqAccountId($corpid, $userId, $accountId, $sysGroupId, $appId
- , $operatorId);
- return self::returnValue($res, $code);
- }
- /**
- * 获取成员可分配许可数量
- * */
- public function licenseCount(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $count = LicenseService::getLicenseCount($corpid);
- return self::returnValue(['count' => $count]);
- }
- /**
- * 分配许可
- * */
- public function activeAccount(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'userid' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userid = $request->input('userid');
- $adminId = $request->input('admin_id');
- $sysGroupId = $request->input('sys_group_id');
- $isSysAdmin = $request->input('is_system_admin');
- # 分配许可
- $errMsg = null;
- $errno = LicenseService::activeAccount($corpid, $userid, $adminId, $sysGroupId, $isSysAdmin, $errMsg);
- return self::returnValue([], $errno, $errMsg);
- }
- /**
- * 批量分配许可
- * */
- public function batchActiveAccount(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'userid_list' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $useridList = $request->input('userid_list');
- $adminId = $request->input('admin_id');
- $sysGroupId = $request->input('sys_group_id');
- $isSysAdmin = $request->input('is_system_admin');
- # 分配许可
- $errMsg = [];
- $success = $failed = 0;
- $errno = LicenseService::batchActiveAccount($corpid, $useridList, $adminId, $sysGroupId, $isSysAdmin, $errMsg, $success, $failed);
- if(!$errno) {
- return self::returnValue(['fail_list' => $errMsg, 'success' => $success, 'failed' => $failed]);
- }
- return self::returnValue([], $errno, $errMsg);
- }
- /**
- * 转移许可
- * */
- public function transfer(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required',
- 'handover_userid' => 'required',
- 'takeover_userid' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $handoverUserid = $request->input('handover_userid');
- $takeoverUserid = $request->input('takeover_userid');
- $adminId = $request->input('admin_id');
- $sysGroupId = $request->input('sys_group_id');
- $isSysAdmin = $request->input('is_system_admin');
- # 分配许可
- $errMsg = null;
- $errno = LicenseService::transfer($corpid, $handoverUserid, $takeoverUserid, $adminId, $sysGroupId, $isSysAdmin, $errMsg);
- return self::returnValue([], $errno, $errMsg);
- }
- public function updateUserStatus(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corp_id' => 'required',
- 'user_id' => 'required',
- 'status' => 'required|in:1, 2, 3',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corp_id');
- $userId = $request->input('user_id');
- $status = $request->input('status');
- $errcode = 0;
- $res = DjUserService::updateUserStatus($corpid, $userId, $status, $errcode);
- return self::returnValue($res, $errcode);
- }
- public function nearExpiredUserList(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'corp_id' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $sysGroupId = $request->input('sys_group_id');
- if(!in_array($sysGroupId, [2, 3])) {
- $list = [];
- } else {
- $list = DjUserService::nearExpiredUserList($corpid);
- }
- return self::returnValue($list);
- }
- # 创建客服许可续期任务
- public function createRenewalJob(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'account_list' => 'required|array',
- 'title' => 'required',
- 'type' => ['nullable', Rule::in([1, 2])],
- ]);
- // Log::logInfo('打印请求参数', $request->all(), 'createRenewalJobParams');
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- $type = $request->input('type', 2);
- $title = $request->input('title');
- $accountList = $request->input('account_list');
- list($res, $code) = DjUserService::createRenewalJob($sysGroupId, $adminId, $title, $type, $accountList);
- return self::returnValue($res, $code);
- }
- # 客服许可续期任务列表
- public function renewalJobList(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'page' => 'required|numeric',
- 'page_size' => 'required|numeric'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $title = $request->input('title');
- $status = $request->input('status');
- $page = $request->input('page');
- $pageSize = $request->input('page_size');
- $errno = 0;
- list($data, $count) = DjUserService::renewalJobList($sysGroupId, $title, $status, $page, $pageSize, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($data, $count, $pageSize, $page);
- }
- # 客服许可任务详情
- public function renewalJobDetail(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'rule_id' => 'required|numeric'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $ruleId = $request->input('rule_id');
- $errno = 0;
- $data = DjUserService::renewalJobDetail($ruleId, $errno);
- return self::returnValue($data, $errno);
- }
- # 取消许可续期任务
- public static function cancelRenewalJob(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'rule_id' => 'required|numeric'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $ruleId = $request->input('rule_id');
- $errno = 0;
- $res = DjUserService::cancelRenewalJob($ruleId, $errno);
- return self::returnValue($res, $errno);
- }
- }
|