123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\WelcomeMsgService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class WelcomeMsgController extends Controller
- {
- /**
- * 设置新用户欢迎语
- * */
- public function setRule(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'name' => 'required|string',
- 'is_for_all' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = array();
- $ruleId = $request->input('rule_id');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['corpid'] = $request->input('corpid');
- $params['admin_id'] = $request->input('admin_id', 1);
- $params['is_for_all'] = $request->input('is_for_all'); // 是否通用于全部员工 0:否 1:是
- $params['users'] = $request->input('users'); // 使用成员,当通用于全部员工是,该字段可为空
- $params['name'] = $request->input('name');
- $params['msg_data'] = $request->input('msg_data');
- # 设置新用户欢迎语发送规则
- $errNo = WelcomeMsgService::setRule($ruleId, $params);
- return self::returnValue([], $errNo);
- }
- /**
- * 新用户欢迎语列表
- * */
- public function ruleLists(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $status = $request->input('status');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取群发规则列表
- $errno = 0;
- list($list, $count) = WelcomeMsgService::ruleList($corpid, $userId, $status, $page, $pageSize, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 新用户欢迎语详情
- * */
- public function ruleDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 获取新用户欢迎语详情
- $errno = 0;
- $detail = WelcomeMsgService::ruleDetail($corpid, $ruleId, $errno);
- return self::returnValue($detail, $errno);
- }
- /**
- * 新用户欢迎语规则启用/禁用
- * */
- public function updateStatus(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'status' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $status = $request->input('status');
- $ruleId = $request->input('rule_id');
- $errno = WelcomeMsgService::updateStatus($corpid, $ruleId, $status);
- return self::returnValue([], $errno);
- }
- /**
- * 新用户欢迎语规则删除
- * */
- public function ruleDel(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $errno = WelcomeMsgService::ruleDel($corpid, $ruleId);
- return self::returnValue([], $errno);
- }
- /**
- * 获取字符串的长度
- * */
- public function strLength(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'content' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $content = $request->input('content');
- $length = strlen($content);
- return self::returnValue(['length' => $length]);
- }
- }
|