init
This commit is contained in:
41
app/Api/Controllers/ArticleController.php
Normal file
41
app/Api/Controllers/ArticleController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Vote;
|
||||
use Jason\Api;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
|
||||
function index()
|
||||
{
|
||||
$files = Article::where('category_id', 2)->select(['id', 'title', 'desc'])->get();
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file->is = $file->audit()->where('user_id', Api::id())->exists();
|
||||
}
|
||||
return $this->success([
|
||||
'user' => Api::user(),
|
||||
'files' => $files,
|
||||
]);
|
||||
}
|
||||
function show(Article $article)
|
||||
{
|
||||
return $this->success([
|
||||
'article' => $article,
|
||||
'audited' => $article->audit()->where('user_id', Api::id())->exists(),
|
||||
]);
|
||||
}
|
||||
|
||||
function audit(Article $article)
|
||||
{
|
||||
$article->audit()->firstOrCreate([
|
||||
'user_id' => Api::id(),
|
||||
]);
|
||||
|
||||
return $this->success('审阅成功');
|
||||
}
|
||||
|
||||
}
|
||||
77
app/Api/Controllers/AuthController.php
Normal file
77
app/Api/Controllers/AuthController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Jason\Api;
|
||||
use Sms;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
public function license()
|
||||
{
|
||||
return $this->success([
|
||||
'agreement' => Article::where('id', 7)->value('content'),
|
||||
'privacy' => Article::where('id', 7)->value('content'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 干事登录,type必须大于1的
|
||||
*
|
||||
* @Date : 2022/4/30 15:49
|
||||
* @Author : <Jason.C>
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
function code2(Request $request)
|
||||
{
|
||||
$username = $request->username;
|
||||
|
||||
$user = User::where('mobile', $username)->where('type', '>=', 1)->first();
|
||||
if (!$user) {
|
||||
return $this->failed('对不起,您无权登录');
|
||||
} else {
|
||||
Sms::send($username);
|
||||
|
||||
return $this->success('发送成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function code(Request $request)
|
||||
{
|
||||
$username = $request->username;
|
||||
|
||||
$user = User::where('mobile', $username)->where('type', 0)->first();
|
||||
if (!$user) {
|
||||
return $this->failed('对不起,您无权登录');
|
||||
} else {
|
||||
Sms::send($username);
|
||||
|
||||
return $this->success('发送成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function loginByCode(Request $request)
|
||||
{
|
||||
$username = $request->username;
|
||||
$code = $request->verify;
|
||||
|
||||
if (Sms::check($username, $code)) {
|
||||
$user = User::where('mobile', $username)->first();
|
||||
|
||||
$token = Api::login($user);
|
||||
|
||||
return $this->success([
|
||||
'access_token' => 'Bearer ' . $token,
|
||||
]);
|
||||
} else {
|
||||
return $this->failed('验证码不正确');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
12
app/Api/Controllers/Controller.php
Normal file
12
app/Api/Controllers/Controller.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Jason\Api\Traits\ApiResponse;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
||||
use ApiResponse;
|
||||
}
|
||||
76
app/Api/Controllers/IndexController.php
Normal file
76
app/Api/Controllers/IndexController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\User;
|
||||
use App\Models\Vote;
|
||||
use Illuminate\Http\Request;
|
||||
use Jason\Api;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Api::user();
|
||||
$license = Article::where('id', 1)->value('content');
|
||||
$license = str_replace('{username}', $user->name, $license);
|
||||
$license = str_replace('{mobile}', $user->mobile, $license);
|
||||
|
||||
$voteShow = false;
|
||||
|
||||
$vote = Vote::where('status', 1)->first();
|
||||
|
||||
if ($vote && ! $vote->logs()->where('user_id', Api::id())->exists()) {
|
||||
$voteShow = true;
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'user' => Api::user(),
|
||||
'sign' => Api::user()->sign,
|
||||
'can_sign' => config('open_sign'),
|
||||
'license' => $license,
|
||||
'vote' => $voteShow,
|
||||
'dested' => (bool) config('dested'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function sign()
|
||||
{
|
||||
if (config('open_sign')) {
|
||||
$user = Api::user();
|
||||
|
||||
$user->sign = 1;
|
||||
$user->save();
|
||||
|
||||
return $this->success('签到成功');
|
||||
} else {
|
||||
return $this->failed('签到已关闭');
|
||||
}
|
||||
}
|
||||
|
||||
function agent()
|
||||
{
|
||||
if (Api::user()->type == 1) {
|
||||
$users = User::where('parent_id', Api::id())->select(['id', 'mobile', 'name', 'sign'])->get();
|
||||
} else {
|
||||
$users = User::where('type', 0)->select(['id', 'mobile', 'name', 'sign'])->get();
|
||||
}
|
||||
|
||||
$vote = Vote::where('status', 1)->first();
|
||||
|
||||
if ($vote) {
|
||||
foreach ($users as $user) {
|
||||
$user->vote = $vote->logs()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'now_vote' => $vote->title ?? '',
|
||||
'user' => Api::user(),
|
||||
'desserts' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
74
app/Api/Controllers/VoteController.php
Normal file
74
app/Api/Controllers/VoteController.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\ItemResource;
|
||||
use App\Models\Vote;
|
||||
use Illuminate\Http\Request;
|
||||
use Jason\Api;
|
||||
|
||||
class VoteController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$vote = Vote::where('status', 1)->first();
|
||||
|
||||
return $this->success([
|
||||
'vote' => $vote,
|
||||
'lock' => $vote->logs()->where('user_id', Api::id())->exists(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Vote $vote, Request $request)
|
||||
{
|
||||
return $this->success([
|
||||
'lock' => $vote->logs()->where('user_id', Api::id())->exists(),
|
||||
'info' => $vote,
|
||||
'list' => ItemResource::collection($vote->items()->orderBy('sort', 'asc')->get()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Vote $vote, Request $request)
|
||||
{
|
||||
if ($vote->status != 1) {
|
||||
return $this->success([
|
||||
'icon' => 'mdi-close-circle',
|
||||
'msg' => '投票通道已关闭',
|
||||
'tips' => '本轮推举已结束,您在规定时间内未提交结果。'
|
||||
]);
|
||||
}
|
||||
if ($vote->logs()->where('user_id', Api::id())->exists()) {
|
||||
return $this->success([
|
||||
'icon' => 'mdi-close-circle',
|
||||
'msg' => '重复提交',
|
||||
'tips' => '您已经参与过推举,请不要重复提交。'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($vote->type == 'equal') {
|
||||
foreach ($request->data as $item) {
|
||||
$vote->logs()->create([
|
||||
'user_id' => Api::id(),
|
||||
'item_id' => $item['id'],
|
||||
'result' => $item['result'],
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
foreach ($request->data as $item) {
|
||||
$vote->logs()->create([
|
||||
'user_id' => Api::id(),
|
||||
'item_id' => $item,
|
||||
'result' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'icon' => 'mdi-checkbox-marked-circle',
|
||||
'msg' => '投票成功,感谢您的参与',
|
||||
'tips' => '您已提交本轮次推举票,为保密,已隐藏您的推举结果,任何人无法查询。'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user