更新 后台 健康问卷
parent
2fe6a0ac8c
commit
22b4bef7a3
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class QuestionListController extends Controller
|
||||
{
|
||||
public function create(Request $request)
|
||||
{
|
||||
$name = $request->post('name');
|
||||
$desc = $request->post('desc');
|
||||
$icon = $request->post('icon');
|
||||
$order = $request->post('order');
|
||||
$question = $request->post('question');
|
||||
if (!$question) {
|
||||
return \Yz::echoError('请选择问卷');
|
||||
}
|
||||
if (!$name) {
|
||||
return \Yz::echoError('请填写名称');
|
||||
}
|
||||
if (mb_strlen($name) > 20) {
|
||||
return \Yz::echoError('名称过长');
|
||||
}
|
||||
if (mb_strlen($desc) > 200) {
|
||||
return \Yz::echoError('说明过长');
|
||||
}
|
||||
if (!$icon) {
|
||||
return \Yz::echoError('请上传图片');
|
||||
}
|
||||
if (mb_strlen($icon) > 200) {
|
||||
return \Yz::echoError('图片链接过长');
|
||||
}
|
||||
DB::table('question_lists')->insert([
|
||||
'name' => $name,
|
||||
'desc' => $desc ?? '',
|
||||
'icon' => $icon,
|
||||
'order' => $order ?? 0,
|
||||
'question' => $question ?? 0,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
return \Yz::Return(true, '操作完成');
|
||||
}
|
||||
public function update(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$name = $request->post('name');
|
||||
$desc = $request->post('desc');
|
||||
$icon = $request->post('icon');
|
||||
$order = $request->post('order');
|
||||
$question = $request->post('question');
|
||||
if (!$question) {
|
||||
return \Yz::echoError('请选择问卷');
|
||||
}
|
||||
if (!$name) {
|
||||
return \Yz::echoError('请填写名称');
|
||||
}
|
||||
if (mb_strlen($name) > 20) {
|
||||
return \Yz::echoError('名称过长');
|
||||
}
|
||||
if (mb_strlen($desc) > 200) {
|
||||
return \Yz::echoError('说明过长');
|
||||
}
|
||||
if (!$icon) {
|
||||
return \Yz::echoError('请上传图片');
|
||||
}
|
||||
if (mb_strlen($icon) > 200) {
|
||||
return \Yz::echoError('图片链接过长');
|
||||
}
|
||||
DB::table('question_lists')->where('id', $id)->update([
|
||||
'name' => $name,
|
||||
'desc' => $desc ?? '',
|
||||
'icon' => $icon,
|
||||
'order' => $order ?? 0,
|
||||
'question' => $question ?? 0,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
return \Yz::Return(true, '操作完成');
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
DB::table('question_lists')->where('id', $id)->delete();
|
||||
return \Yz::Return(true, '操作完成');
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$search = $request->post('search');
|
||||
$db = DB::table('question_lists');
|
||||
if (!!$search) {
|
||||
$db->where('name', 'like', "%$search%");
|
||||
}
|
||||
$list = $db->orderBy('order', 'desc')->get();
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'list' => $list
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class QuestionList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateQuestionListsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('question_lists', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 50);
|
||||
$table->string('desc', 200);
|
||||
$table->string('icon', 200);
|
||||
$table->bigInteger('order');
|
||||
$table->bigInteger('question');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('question_lists');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue