企微短剧业务系统

WelcomeMsgController.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\WelcomeMsgService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Validation\Rule;
  7. class WelcomeMsgController extends Controller
  8. {
  9. /**
  10. * 设置新用户欢迎语
  11. * */
  12. public function setRule(Request $request)
  13. {
  14. $validator = \Validator::make($request->all(),[
  15. 'corpid' => 'required|string',
  16. 'name' => 'required|string',
  17. 'is_for_all' => ['required', Rule::in([0, 1])],
  18. ]);
  19. if ($validator->fails()) {
  20. return self::returnValue($validator->getMessageBag(), 1102);
  21. }
  22. $params = array();
  23. $ruleId = $request->input('rule_id');
  24. $params['sys_group_id'] = $request->input('sys_group_id');
  25. $params['corpid'] = $request->input('corpid');
  26. $params['admin_id'] = $request->input('admin_id', 1);
  27. $params['is_for_all'] = $request->input('is_for_all'); // 是否通用于全部员工 0:否 1:是
  28. $params['users'] = $request->input('users'); // 使用成员,当通用于全部员工是,该字段可为空
  29. $params['name'] = $request->input('name');
  30. $params['msg_data'] = $request->input('msg_data');
  31. # 设置新用户欢迎语发送规则
  32. $errNo = WelcomeMsgService::setRule($ruleId, $params);
  33. return self::returnValue([], $errNo);
  34. }
  35. /**
  36. * 新用户欢迎语列表
  37. * */
  38. public function ruleLists(Request $request)
  39. {
  40. $validator = \Validator::make($request->all(),[
  41. 'corpid' => 'required|string',
  42. ]);
  43. if ($validator->fails()) {
  44. return self::returnValue($validator->getMessageBag(), 1102);
  45. }
  46. $corpid = $request->input('corpid');
  47. $userId = $request->input('user_id');
  48. $status = $request->input('status');
  49. $page = $request->input('page', 1);
  50. $pageSize = $request->input('page_size', 20);
  51. # 获取群发规则列表
  52. $errno = 0;
  53. list($list, $count) = WelcomeMsgService::ruleList($corpid, $userId, $status, $page, $pageSize, $errno);
  54. if($errno) return self::returnValue([], $errno);
  55. return self::returnPageValue($list, $count, $pageSize, $page);
  56. }
  57. /**
  58. * 新用户欢迎语详情
  59. * */
  60. public function ruleDetail(Request $request)
  61. {
  62. $validator = \Validator::make($request->all(),[
  63. 'corpid' => 'required|string',
  64. 'rule_id' => 'required|integer',
  65. ]);
  66. if ($validator->fails()) {
  67. return self::returnValue($validator->getMessageBag(), 1102);
  68. }
  69. $corpid = $request->input('corpid');
  70. $ruleId = $request->input('rule_id');
  71. # 获取新用户欢迎语详情
  72. $errno = 0;
  73. $detail = WelcomeMsgService::ruleDetail($corpid, $ruleId, $errno);
  74. return self::returnValue($detail, $errno);
  75. }
  76. /**
  77. * 新用户欢迎语规则启用/禁用
  78. * */
  79. public function updateStatus(Request $request)
  80. {
  81. $validator = \Validator::make($request->all(),[
  82. 'corpid' => 'required|string',
  83. 'rule_id' => 'required|integer',
  84. 'status' => ['required', Rule::in([0, 1])],
  85. ]);
  86. if ($validator->fails()) {
  87. return self::returnValue($validator->getMessageBag(), 1102);
  88. }
  89. $corpid = $request->input('corpid');
  90. $status = $request->input('status');
  91. $ruleId = $request->input('rule_id');
  92. $errno = WelcomeMsgService::updateStatus($corpid, $ruleId, $status);
  93. return self::returnValue([], $errno);
  94. }
  95. /**
  96. * 新用户欢迎语规则删除
  97. * */
  98. public function ruleDel(Request $request)
  99. {
  100. $validator = \Validator::make($request->all(),[
  101. 'corpid' => 'required|string',
  102. 'rule_id' => 'required|integer',
  103. ]);
  104. if ($validator->fails()) {
  105. return self::returnValue($validator->getMessageBag(), 1102);
  106. }
  107. $corpid = $request->input('corpid');
  108. $ruleId = $request->input('rule_id');
  109. $errno = WelcomeMsgService::ruleDel($corpid, $ruleId);
  110. return self::returnValue([], $errno);
  111. }
  112. /**
  113. * 获取字符串的长度
  114. * */
  115. public function strLength(Request $request)
  116. {
  117. $validator = \Validator::make($request->all(),[
  118. 'content' => 'required|string',
  119. ]);
  120. if ($validator->fails()) {
  121. return self::returnValue($validator->getMessageBag(), 1102);
  122. }
  123. $content = $request->input('content');
  124. $length = strlen($content);
  125. return self::returnValue(['length' => $length]);
  126. }
  127. }