123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- namespace App\Http\Controllers\Deed;
- use App\Exceptions\AlertException;
- use App\Http\Controllers\Controller;
- use App\Http\Controllers\Core\Auth;
- use App\Models\Invite\QuestionTemplateModel;
- use App\Models\User\InviteConfigModel;
- use App\Models\User\LikeInviteQuestionModel;
- use App\Models\User\UserModel;
- use App\Services\Deed\InvitationService;
- use Illuminate\Http\Request;
- class InvitationController extends Controller
- {
- /**
- * 发起心动邀请
- * @param Request $request
- * @return array
- * @throws AlertException
- */
- public function create(Request $request)
- {
- $uid = Auth::auth();
- $this->validate($request, [
- 'invite_uid' => 'required|integer',
- 'question_type' => 'in:0,1,2,3,4',
- 'question_answer' => '',
- 'question_id' => 'integer',
- 'say_hello' => '',
- 'kk' => '',
- 'paint_id' => ''
- ]);
- $invite_uid = $request->post('invite_uid');
- $question_type = $request->post('question_type', 0);
- $question_id = $request->post('question_id', 0);
- $question_answer = $request->post('question_answer');
- $kk = $request->post('kk');
- $paint_id = $request->post('paint_id', 0);
- $request_content = $request->post('request_content');
- $question = array(
- 'question_id' => $question_id,
- 'question_answer' => $question_answer
- );
- $say_hello = $request->post("say_hello", null);
- $is = new InvitationService();
- $invite_id = $is->create(
- $uid,
- $invite_uid,
- $question_type,
- $question,
- $say_hello,
- $paint_id,
- $request_content,
- $kk
- );
- return response([
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'invitate_id' => $invite_id
- ]
- ]);
- }
- /**
- * 通过id获取邀请信息
- * @param int $id
- * @return array
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function getbyid(int $id)
- {
- $uid = Auth::auth();
- $is = new InvitationService();
- $data = $is->getById($uid, $id);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 查看收到的待处理邀请列表
- * @param Request $request
- * @return array
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function receivesByUnHandle(Request $request)
- {
- $uid = Auth::auth();
- $pages = array(
- 'page' => $request->get('page') ?? 1,
- 'limit' => 100
- );
- $is = new InvitationService();
- $data = $is->receivesByUnhandle($uid, $pages);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 查看待处理邀请列表
- * @param Request $request
- * @return array
- * @throws \Exception
- */
- public function unhandle(Request $request)
- {
- $uid = Auth::auth();
- $pages = array(
- 'page' => $request->get('page') ?? 1,
- 'limit' => 100
- );
- $is = new InvitationService();
- $data = $is->unhandle($uid, $pages);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 为心动考验支付小花
- * @param Request $request
- * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
- * @throws AlertException
- */
- public function pay(Request $request)
- {
- $this->validate($request, ['invite_uid' => 'required', 'type' => 'required']);
- $type = $request->post('type', 1);
- $invite_uid = $request->post('invite_uid', 0);
- $uid = Auth::auth();
- $is = new InvitationService();
- $is->pay($uid, $invite_uid, $type);
- return response([
- 'code' => 200,
- 'message' => 'success'
- ]);
- }
- /**
- * 查看收到的邀请列表
- * @param Request $request
- * @return array
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function receives(Request $request)
- {
- $uid = Auth::auth();
- $pages = array(
- 'page' => $request->get('page') ?? 1,
- 'limit' => 10
- );
- $onlyreceive = $request->get('onlyreceive') ?? false;
- $is = new InvitationService();
- $data = $is->receives($uid, $pages, $onlyreceive);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 查看发出的邀请列表
- * @param Request $request
- * @return array
- */
- public function sends(Request $request)
- {
- $uid = Auth::auth();
- $pages = array(
- 'page' => $request->get('page') ?? 1,
- 'limit' => 20
- );
- $onlyreceive = $request->get('onlyreceive') ?? false;
- $is = new InvitationService();
- $data = $is->sends($uid, $pages, $onlyreceive);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 查看邀请列表
- * @param Request $request
- * @return array
- */
- public function list(Request $request)
- {
- $uid = Auth::auth();
- $pages = array(
- 'page' => $request->get('page') ?? 1,
- 'limit' => 20
- );
- $is = new InvitationService();
- $data = $is->list($uid, $pages);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 心动邀请同意
- * @param int $invite_id
- * @param Request $request
- * @return array
- * @throws AlertException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function fixstate(int $invite_id, Request $request)
- {
- $this->validate($request, [
- 'state' => 'required|in:-1,1',
- ]);
- $state = $request->post('state');
- $uid = Auth::auth();
- $is = new InvitationService();
- $is->fixstate($invite_id, $uid, $state);
- return [
- 'code' => 200,
- 'message' => 'success'
- ];
- }
- /**
- * 查阅心动邀请
- * @param int $invite_id
- * @return array
- * @throws AlertException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function fixread(int $invite_id)
- {
- $uid = Auth::auth();
- $is = new InvitationService();
- $is->fixread($invite_id, $uid);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 获取某人设置的心动问题和
- * @param Request $request
- * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
- */
- public function questions(Request $request)
- {
- $type = $request->get('type', 'text');
- $uid = $request->get('uid');
- $sex = UserModel::where('uid', $uid)->value('sex') ?: 2;
- $config = InviteConfigModel::select('task_question_data', 'task_sing_data')->where('uid', $uid)->first();
- $template_ids = [];
- if ($config) {
- switch ($type) {
- case "text":
- $template_ids = collect($config->task_question_data)->pluck('id')->toArray();
- break;
- case 'music':
- $template_ids = collect($config->task_sing_data)->pluck('id')->toArray();
- break;
- }
- }
- if (!$template_ids) {
- $template_ids = array_random(QuestionTemplateModel::where(['type' => $type])->where(
- 'select_count',
- '>',
- 0
- )->pluck('id')->toArray(), 20);
- }
- $templates = QuestionTemplateModel::whereIn('id', $template_ids)
- ->where('type', $type)
- ->where('select_count', '>', 0)
- ->get();
- foreach ($templates as $template) {
- $voice = LikeInviteQuestionModel::where([
- 'template_id' => $template->id,
- 'select' => 1,
- 'sex' => $sex
- ])->inRandomOrder()->first();
- unset($voice->question);
- $template->voice = $voice;
- }
- return response([
- 'code' => 200,
- 'message' => 'OK',
- 'data' => $templates,
- ]);
- }
- }
|