企微短剧业务系统

UserController.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/3/24
  6. * Time: 18:34
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Log;
  11. use App\RedisModel;
  12. use App\Service\DjUserService;
  13. use App\Service\LicenseService;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Validation\Rule;
  16. class UserController extends Controller
  17. {
  18. /**
  19. * 检索框内部员工(客服)列表
  20. * @param Request $request
  21. * @return array
  22. */
  23. public function userList(Request $request)
  24. {
  25. $validator = \Validator::make($request->all(),[
  26. 'corpid' => 'required',
  27. 'user_name' => 'nullable|string'
  28. ]);
  29. if ($validator->fails()) {
  30. return self::returnValue($validator->getMessageBag(), 1102);
  31. }
  32. $corpid = $request->input('corpid');
  33. $userName = $request->input('user_name');
  34. $status = $request->input('status');
  35. $data = DjUserService::userList($corpid, $userName, $status);
  36. return self::returnValue($data);
  37. }
  38. public function users(Request $request)
  39. {
  40. $validator = \Validator::make($request->all(),[
  41. 'corpid' => 'required',
  42. 'user_name' => 'nullable|string'
  43. ]);
  44. if ($validator->fails()) {
  45. return self::returnValue($validator->getMessageBag(), 1102);
  46. }
  47. $corpid = $request->input('corpid');
  48. $userName = $request->input('user_name');
  49. $isActive = $request->input('is_active');
  50. $userIds = $request->input('user_ids');
  51. $departmentList = $request->input('department_list');
  52. $appId = $request->input('app_id');
  53. $accountId = $request->input('account_id');
  54. $operatorId = $request->input('operator_id');// 运营人员ID
  55. $page = $request->input('page', 1);
  56. $pageSize = $request->input('page_size', 20);
  57. $expireDays = $request->input('expire_days');
  58. list($data, $count, $yesterdayAdd, $yesterdayLoss, $customerCount) = DjUserService::users(
  59. $corpid, $userName, $userIds, $departmentList, $page, $pageSize, $isActive, $appId, $accountId, $operatorId,
  60. $expireDays
  61. );
  62. $extra = ['user_count' => $count, 'user_add_yesterday' => $yesterdayAdd, 'user_loss_yesterday' => $yesterdayLoss
  63. , 'customer_count' => $customerCount];
  64. return self::returnPageValue($data, $count, $pageSize, $page, $extra);
  65. }
  66. /**
  67. * 成员详情
  68. * @param Request $request
  69. * @return array
  70. */
  71. public function user_info(Request $request){
  72. $validator = \Validator::make($request->all(),[
  73. 'corpid' => 'required',
  74. 'user_id' => 'required'
  75. ]);
  76. if ($validator->fails()) {
  77. return self::returnValue($validator->getMessageBag(), 1102);
  78. }
  79. $corpid = $request->input('corpid');
  80. $user_id = $request->input('user_id');
  81. $res = DjUserService::user_info($corpid,$user_id);
  82. return self::returnValue($res);
  83. }
  84. /**
  85. * 成员会话统计
  86. * @param Request $request
  87. * @return array
  88. */
  89. public function conversation_report(Request $request){
  90. $validator = \Validator::make($request->all(),[
  91. 'corpid' => 'required',
  92. 'user_id' => 'required'
  93. ]);
  94. if ($validator->fails()) {
  95. return self::returnValue($validator->getMessageBag(), 1102);
  96. }
  97. $corpid = $request->input('corpid');
  98. $user_id = $request->input('user_id');
  99. $begin_date = $request->input('begin_date',date("Y-m-d",strtotime("-1days")));
  100. $end_date = $request->input('end_date',date("Y-m-d",strtotime("-1days")));
  101. $list = DjUserService::conversation_report($corpid, $user_id, $begin_date, $end_date);
  102. return self::returnValue(['list'=>$list]);
  103. }
  104. /**
  105. * 成员会话报表汇总
  106. * @param Request $request
  107. * @return array
  108. */
  109. public function conversation_report_total(Request $request){
  110. $validator = \Validator::make($request->all(),[
  111. 'corpid' => 'required',
  112. 'user_id' => 'required'
  113. ]);
  114. if ($validator->fails()) {
  115. return self::returnValue($validator->getMessageBag(), 1102);
  116. }
  117. $corpid = $request->input('corpid');
  118. $user_id = $request->input('user_id');
  119. $begin_date = $request->input('begin_date',date("Y-m-d",strtotime("-1days")));
  120. $end_date = $request->input('end_date',date("Y-m-d",strtotime("-1days")));
  121. $total = DjUserService::conversation_report_total($corpid, $user_id, $begin_date, $end_date);
  122. return self::returnValue(['total'=>$total]);
  123. }
  124. public function departments(Request $request)
  125. {
  126. $corpid = $request->input('corpid');
  127. $data = DjUserService::departments($corpid);
  128. return self::returnValue($data);
  129. }
  130. public function bindUserAdqAccountId(Request $request)
  131. {
  132. $validator = \Validator::make($request->all(),[
  133. 'corpid' => 'required',
  134. 'user_id' => 'required',
  135. ]);
  136. if ($validator->fails()) {
  137. return self::returnValue($validator->getMessageBag(), 1102);
  138. }
  139. $corpid = $request->input('corpid');
  140. $userId = $request->input('user_id');
  141. $accountId = $request->input('account_id');
  142. $sysGroupId = $request->input('sys_group_id');
  143. $appId = $request->input('app_id');
  144. $operatorId = $request->input('operator_id');
  145. list($res, $code) = DjUserService::bindUserAdqAccountId($corpid, $userId, $accountId, $sysGroupId, $appId
  146. , $operatorId);
  147. return self::returnValue($res, $code);
  148. }
  149. /**
  150. * 获取成员可分配许可数量
  151. * */
  152. public function licenseCount(Request $request)
  153. {
  154. $validator = \Validator::make($request->all(),[
  155. 'corpid' => 'required',
  156. ]);
  157. if ($validator->fails()) {
  158. return self::returnValue($validator->getMessageBag(), 1102);
  159. }
  160. $corpid = $request->input('corpid');
  161. $count = LicenseService::getLicenseCount($corpid);
  162. return self::returnValue(['count' => $count]);
  163. }
  164. /**
  165. * 分配许可
  166. * */
  167. public function activeAccount(Request $request)
  168. {
  169. $validator = \Validator::make($request->all(),[
  170. 'corpid' => 'required',
  171. 'userid' => 'required',
  172. ]);
  173. if ($validator->fails()) {
  174. return self::returnValue($validator->getMessageBag(), 1102);
  175. }
  176. $corpid = $request->input('corpid');
  177. $userid = $request->input('userid');
  178. $adminId = $request->input('admin_id');
  179. $sysGroupId = $request->input('sys_group_id');
  180. $isSysAdmin = $request->input('is_system_admin');
  181. # 分配许可
  182. $errMsg = null;
  183. $errno = LicenseService::activeAccount($corpid, $userid, $adminId, $sysGroupId, $isSysAdmin, $errMsg);
  184. return self::returnValue([], $errno, $errMsg);
  185. }
  186. /**
  187. * 批量分配许可
  188. * */
  189. public function batchActiveAccount(Request $request)
  190. {
  191. $validator = \Validator::make($request->all(),[
  192. 'corpid' => 'required',
  193. 'userid_list' => 'required',
  194. ]);
  195. if ($validator->fails()) {
  196. return self::returnValue($validator->getMessageBag(), 1102);
  197. }
  198. $corpid = $request->input('corpid');
  199. $useridList = $request->input('userid_list');
  200. $adminId = $request->input('admin_id');
  201. $sysGroupId = $request->input('sys_group_id');
  202. $isSysAdmin = $request->input('is_system_admin');
  203. # 分配许可
  204. $errMsg = [];
  205. $success = $failed = 0;
  206. $errno = LicenseService::batchActiveAccount($corpid, $useridList, $adminId, $sysGroupId, $isSysAdmin, $errMsg, $success, $failed);
  207. if(!$errno) {
  208. return self::returnValue(['fail_list' => $errMsg, 'success' => $success, 'failed' => $failed]);
  209. }
  210. return self::returnValue([], $errno, $errMsg);
  211. }
  212. /**
  213. * 转移许可
  214. * */
  215. public function transfer(Request $request)
  216. {
  217. $validator = \Validator::make($request->all(),[
  218. 'corpid' => 'required',
  219. 'handover_userid' => 'required',
  220. 'takeover_userid' => 'required',
  221. ]);
  222. if ($validator->fails()) {
  223. return self::returnValue($validator->getMessageBag(), 1102);
  224. }
  225. $corpid = $request->input('corpid');
  226. $handoverUserid = $request->input('handover_userid');
  227. $takeoverUserid = $request->input('takeover_userid');
  228. $adminId = $request->input('admin_id');
  229. $sysGroupId = $request->input('sys_group_id');
  230. $isSysAdmin = $request->input('is_system_admin');
  231. # 分配许可
  232. $errMsg = null;
  233. $errno = LicenseService::transfer($corpid, $handoverUserid, $takeoverUserid, $adminId, $sysGroupId, $isSysAdmin, $errMsg);
  234. return self::returnValue([], $errno, $errMsg);
  235. }
  236. public function updateUserStatus(Request $request)
  237. {
  238. $validator = \Validator::make($request->all(),[
  239. 'corp_id' => 'required',
  240. 'user_id' => 'required',
  241. 'status' => 'required|in:1, 2, 3',
  242. ]);
  243. if ($validator->fails()) {
  244. return self::returnValue($validator->getMessageBag(), 1102);
  245. }
  246. $corpid = $request->input('corp_id');
  247. $userId = $request->input('user_id');
  248. $status = $request->input('status');
  249. $errcode = 0;
  250. $res = DjUserService::updateUserStatus($corpid, $userId, $status, $errcode);
  251. return self::returnValue($res, $errcode);
  252. }
  253. public function nearExpiredUserList(Request $request) {
  254. $validator = \Validator::make($request->all(),[
  255. 'corp_id' => 'required',
  256. ]);
  257. if ($validator->fails()) {
  258. return self::returnValue($validator->getMessageBag(), 1102);
  259. }
  260. $corpid = $request->input('corpid');
  261. $sysGroupId = $request->input('sys_group_id');
  262. if(!in_array($sysGroupId, [2, 3])) {
  263. $list = [];
  264. } else {
  265. $list = DjUserService::nearExpiredUserList($corpid);
  266. }
  267. return self::returnValue($list);
  268. }
  269. # 创建客服许可续期任务
  270. public function createRenewalJob(Request $request) {
  271. $validator = \Validator::make($request->all(),[
  272. 'account_list' => 'required|array',
  273. 'title' => 'required',
  274. 'type' => ['nullable', Rule::in([1, 2])],
  275. ]);
  276. // Log::logInfo('打印请求参数', $request->all(), 'createRenewalJobParams');
  277. if ($validator->fails()) {
  278. return self::returnValue($validator->getMessageBag(), 1102);
  279. }
  280. $sysGroupId = $request->input('sys_group_id');
  281. $adminId = $request->input('admin_id');
  282. $type = $request->input('type', 2);
  283. $title = $request->input('title');
  284. $accountList = $request->input('account_list');
  285. list($res, $code) = DjUserService::createRenewalJob($sysGroupId, $adminId, $title, $type, $accountList);
  286. return self::returnValue($res, $code);
  287. }
  288. # 客服许可续期任务列表
  289. public function renewalJobList(Request $request) {
  290. $validator = \Validator::make($request->all(),[
  291. 'page' => 'required|numeric',
  292. 'page_size' => 'required|numeric'
  293. ]);
  294. if ($validator->fails()) {
  295. return self::returnValue($validator->getMessageBag(), 1102);
  296. }
  297. $sysGroupId = $request->input('sys_group_id');
  298. $title = $request->input('title');
  299. $status = $request->input('status');
  300. $page = $request->input('page');
  301. $pageSize = $request->input('page_size');
  302. $errno = 0;
  303. list($data, $count) = DjUserService::renewalJobList($sysGroupId, $title, $status, $page, $pageSize, $errno);
  304. if($errno) return self::returnValue([], $errno);
  305. return self::returnPageValue($data, $count, $pageSize, $page);
  306. }
  307. # 客服许可任务详情
  308. public function renewalJobDetail(Request $request) {
  309. $validator = \Validator::make($request->all(),[
  310. 'rule_id' => 'required|numeric'
  311. ]);
  312. if ($validator->fails()) {
  313. return self::returnValue($validator->getMessageBag(), 1102);
  314. }
  315. $sysGroupId = $request->input('sys_group_id');
  316. $ruleId = $request->input('rule_id');
  317. $errno = 0;
  318. $data = DjUserService::renewalJobDetail($ruleId, $errno);
  319. return self::returnValue($data, $errno);
  320. }
  321. # 取消许可续期任务
  322. public static function cancelRenewalJob(Request $request)
  323. {
  324. $validator = \Validator::make($request->all(),[
  325. 'rule_id' => 'required|numeric'
  326. ]);
  327. if ($validator->fails()) {
  328. return self::returnValue($validator->getMessageBag(), 1102);
  329. }
  330. $sysGroupId = $request->input('sys_group_id');
  331. $ruleId = $request->input('rule_id');
  332. $errno = 0;
  333. $res = DjUserService::cancelRenewalJob($ruleId, $errno);
  334. return self::returnValue($res, $errno);
  335. }
  336. }