Skip to content

Commit

Permalink
完成了会员管理功能的开发(异步上传)
Browse files Browse the repository at this point in the history
  • Loading branch information
MacsenChu committed Feb 8, 2020
1 parent cd5933b commit 29124b6
Show file tree
Hide file tree
Showing 41 changed files with 53,236 additions and 68 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .idea/edu_platform.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

916 changes: 857 additions & 59 deletions README.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions app/Admin/Member.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Admin;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
// 定义关联的表
protected $table = 'member';
}
61 changes: 61 additions & 0 deletions app/Http/Controllers/Admin/MemberController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Admin\Member;
use Symfony\Component\Console\Input\Input;
use DB;

class MemberController extends Controller
{
// 列表方法
public function index() {
// 查询数据
$data = Member::get();
// 展示视图
return view('admin.member.index', compact('data'));
}

// 添加方法
public function add(Request $request) {
// 判断请求类型
if ($request -> isMethod('POST')) {
// 实现数据的保存
// 自动验证
$result = Member::insert([
'username' => $request -> get('username'),
'password' => bcrypt('password'),
'gender' => $request -> get('gender'),
'mobile' => $request -> get('mobile'),
'email' => $request -> get('email'),
'avatar' => $request -> get('avatar'),
'country_id'=> $request -> get('country_id'),
'province_id'=> $request -> get('province_id'),
'city_id' => $request -> get('city_id'),
'county_id' => $request -> get('type'),
'type' => $request -> get('status'),
'status' => $request -> get('status'),
'created_at'=> date('Y-m-d H:i:s')
]);
// 返回输出
return $result ? '1' : '0';
} else {
// 查询数据(国家的数据)
$country = DB::table('area') -> where('pid', '0') -> get();
// 展示视图
return view('admin.member.add', compact('country'));
}
}

// ajax 四级联动获取下属地区
public function getAreaById(Request $request) {
// 接收 id
$id = $request -> get('id');
// 根据 id 去查询下属地区
$data = DB::table('area') -> where('pid', $id) -> get();
// 返回 json 数据
return response() -> json($data);
}
}
62 changes: 62 additions & 0 deletions app/Http/Controllers/Admin/UploaderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Storage;

class UploaderController extends Controller
{
// 上传文件的处理
function webuploader(Request $request) {
// 判断是否有文件上传成功
if ($request -> hasFile('file') && $request -> file('file') -> isValid()) {
// 有文件上传
$filename = sha1(time() . $request -> file('file') -> getClientOriginalName()) . '.' . $request -> file('file') -> getClientOriginalExtension();
// 文件保存
Storage::disk('public') -> put($filename, file_get_contents($request -> file('file') -> path()));
// 返回数据
$result = [
'errCode' => '0',
'errMsg' => '',
'succMsg' => '文件上传成功',
'path' => '/storage/' . $filename
];
} else {
// 没有文件上传或者出错
$result = [
'errCode' => '000001',
'errMsg' => $request -> file('file') -> getErrorMessage(),
];
}
// 返回信息
return response() -> json($result);
}

// 上传文件的处理
function qiniu(Request $request) {
// 判断是否有文件上传成功
if ($request -> hasFile('file') && $request -> file('file') -> isValid()) {
// 有文件上传
$filename = sha1(time() . $request -> file('file') -> getClientOriginalName()) . '.' . $request -> file('file') -> getClientOriginalExtension();
// 文件保存
Storage::disk('qiniu') -> put($filename, file_get_contents($request -> file('file') -> path()));
// 返回数据
$result = [
'errCode' => '0',
'errMsg' => '',
'succMsg' => '文件上传成功',
'path' => Storage::disk('qiniu') -> getDriver() -> downloadUrl($filename),
];
} else {
// 没有文件上传或者出错
$result = [
'errCode' => '000001',
'errMsg' => $request -> file('file') -> getErrorMessage(),
];
}
// 返回信息
return response() -> json($result);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.2",
"laravel/tinker": "^2.0",
"mews/captcha": "^3.0"
"mews/captcha": "^3.0",
"zgldh/qiniu-laravel-storage": "^0.10.3"
},
"require-dev": {
"facade/ignition": "^1.4",
Expand Down
124 changes: 123 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
*/
Barryvdh\Debugbar\ServiceProvider::class,
Mews\Captcha\CaptchaServiceProvider::class,
zgldh\QiniuStorage\QiniuFilesystemServiceProvider::class,
/*
* Application Service Providers...
*/
Expand Down
15 changes: 15 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
'url' => env('AWS_URL'),
],

'qiniu' => [
'driver' => 'qiniu',
'domains' => [
'default' => 'q5dv3r5b0.bkt.clouddn.com', //你的七牛域名
'https' => '', //你的HTTPS域名
'custom' => '', //Useless 没啥用,请直接使用上面的 default 项
],
'access_key'=> 'Nx0h1k9vo6Soj8rlKu3QcZ_OcWLHq2bRW2Whp6YK', //AccessKey
'secret_key'=> '7dSgE7byJQVZl5GMkcZULKVDkFyQLyp7KrubUv5L', //SecretKey
'bucket' => 'laravel-edu-platform', //Bucket名字
'notify_url'=> '', //持久化处理回调地址
'access' => 'public', //空间访问控制 public 或 private
'hotlink_prevention_key' => '', // CDN 时间戳防盗链的 key。 设置为 null 则不启用本功能。
// 'hotlink_prevention_key' => 'cbab68a279xxxxxxxxxxab509a', // 同上,备用
],
],

];
40 changes: 40 additions & 0 deletions database/migrations/2020_02_06_143944_create_member_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMemberTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('member', function (Blueprint $table) {
$table -> bigIncrements('id');
$table -> string('username', 20) -> notNull();
$table -> string('password') -> notNull();
$table -> enum('gender', [1, 2, 3]) -> notNull() -> default('1');
$table -> string('mobile', 11);
$table -> string('email', 40);
$table -> string('avatar');
$table -> timestamps();
$table -> rememberToken();
$table -> enum('type', [1, 2]) -> notNull() -> default('1');
$table -> enum('status', [1, 2]) -> notNull() -> default('2');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('member');
}
}
Loading

0 comments on commit 29124b6

Please sign in to comment.