Commit 17dfde88 authored by zhoujun's avatar zhoujun

Merge branch 'test'

parents 7631dbec 4573e02b
Pipeline #1600 passed with stage
in 0 seconds
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Models\WxUserImg;
use App\Services\UploadServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class UploadOOSImg extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'UploadOOSImg';
/**
* The console command description.
*
* @var string
*/
protected $description = '上传云图片';
/**
* @var ActivityOrder
*/
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$imgs = WxUserImg::where('is_upload', 0)->where('status',1)->select('id','loacl_url','img_url','is_upload')->limit(300)->get();
foreach($imgs as $img){
if($img->loacl_url != ''){
$url = UploadServer::getUploadAliyun('aldzn-img', $img->loacl_url,public_path().'/'.$img->loacl_url);
if($url){
$img->is_upload = 1;
$img->img_url = $url;
$img->save();
if($img->loacl_url != '' && file_exists(public_path().'/'.$img->loacl_url)) unlink(public_path().'/'.$img->loacl_url);
}
}
}
$this->line('结束');
}
}
\ No newline at end of file
...@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel ...@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
* @var array * @var array
*/ */
protected $commands = [ protected $commands = [
// 'App\Console\Commands\UploadOOSImg',
]; ];
/** /**
...@@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel ...@@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
// $schedule->command('inspire') $schedule->command('UploadOOSImg')->everyMinute()->withoutOverlapping(5);
// ->hourly();
} }
/** /**
......
...@@ -95,7 +95,7 @@ class AdminController extends Controller ...@@ -95,7 +95,7 @@ class AdminController extends Controller
return $query->where('updated_at','<',$endTime); return $query->where('updated_at','<',$endTime);
})->when($status == 0, function ($query) use ($status) { })->when($status == 0, function ($query) use ($status) {
return $query->orderBy('status','ASC'); return $query->orderBy('status','ASC');
})->orderBy('updated_at','DESC')->select('id', 'uid', 'img_url', 'status', 'updated_at')->paginate($pageNum); })->orderBy('updated_at','DESC')->select('id', 'uid', 'loacl_url','img_url', 'status','is_upload', 'updated_at')->paginate($pageNum);
if($startTime != '') $paginateAppends['startTime'] = $startTime; if($startTime != '') $paginateAppends['startTime'] = $startTime;
if($endTime != '') $paginateAppends['endTime'] = $endTime; if($endTime != '') $paginateAppends['endTime'] = $endTime;
if($userName != '') $paginateAppends['user'] = $userName; if($userName != '') $paginateAppends['user'] = $userName;
...@@ -144,6 +144,16 @@ class AdminController extends Controller ...@@ -144,6 +144,16 @@ class AdminController extends Controller
$ids = explode('#',$postData['ids']); $ids = explode('#',$postData['ids']);
$status = $postData['status']; $status = $postData['status'];
if(!in_array($status,[1,2]) || empty($ids)) return $this->getErrorMsg('10060', '参数错误'); if(!in_array($status,[1,2]) || empty($ids)) return $this->getErrorMsg('10060', '参数错误');
// $imgs = WxUserImg::whereIn('id',$ids)->select('id','loacl_url','status')->get();
// $result = true;
// foreach($imgs as $img){
// $img->status = 1;
// if($img->save()){
// if($status == 2) unlink(storage_path('app').'/'.$img->loacl_url);
// }else{
// $result = false;
// }
// }
$result = WxUserImg::whereIn('id',$ids)->update(['status' => $status]); $result = WxUserImg::whereIn('id',$ids)->update(['status' => $status]);
if($result) return $this->getSuccessMsg([]); if($result) return $this->getSuccessMsg([]);
return $this->getErrorMsg('10063', '审核失败'); return $this->getErrorMsg('10063', '审核失败');
......
...@@ -82,6 +82,7 @@ class CardController extends Controller ...@@ -82,6 +82,7 @@ class CardController extends Controller
$userId = $request->session()->get("uid"); $userId = $request->session()->get("uid");
$result = $this->getVerityLogin($userId); $result = $this->getVerityLogin($userId);
if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']); if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']);
if(Cache::has($userId.':card:bind:role')) return $this->jsonReturn(10022, '绑定角色过于频繁,请稍后再试');
$roleId = $request->input('roleId'); $roleId = $request->input('roleId');
$serverId = $request->input('serverId'); $serverId = $request->input('serverId');
...@@ -91,8 +92,11 @@ class CardController extends Controller ...@@ -91,8 +92,11 @@ class CardController extends Controller
$this->getCheckRoleInfoTable($tableName); $this->getCheckRoleInfoTable($tableName);
$verity = DB::connection('wx_mysql')->table($tableName)->where('uid',$userId)->where('role_id',$roleId)->select('id')->first(); $verity = DB::connection('wx_mysql')->table($tableName)->where('uid',$userId)->where('role_id',$roleId)->select('id')->first();
if($verity) return $this->jsonReturn(0, '角色绑定成功'); if($verity) return $this->jsonReturn(0, '角色绑定成功');
Cache::put($userId.':card:bind:role',1,30);
$insert = $this->getInsertRoleInfo($userId,$roleId,$serverId,$serverName,$tableName); $insert = $this->getInsertRoleInfo($userId,$roleId,$serverId,$serverName,$tableName);
if($insert['code'] == 200) return $this->jsonReturn(0, '角色绑定成功'); if($insert['code'] == 200) return $this->jsonReturn(0, '角色绑定成功');
Cache::forget($userId.':card:bind:role');
return $this->jsonReturn($insert['code'], $insert['msg']); return $this->jsonReturn($insert['code'], $insert['msg']);
} }
...@@ -277,17 +281,21 @@ class CardController extends Controller ...@@ -277,17 +281,21 @@ class CardController extends Controller
$serverId = $request->input('serverId'); $serverId = $request->input('serverId');
$result = $this->getVerityLogin($userId); $result = $this->getVerityLogin($userId);
if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']); if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']);
if(Cache::has($userId.':card:upload:image')) return $this->jsonReturn(10022, '上传图片过于频繁,请稍后再试');
$postData = $request->all(); $postData = $request->all();
if($request->hasFile('imgFile') && $request->file('imgFile')->isValid()){ if($request->hasFile('imgFile') && $request->file('imgFile')->isValid()){
$file = $request->file('imgFile'); $file = $request->file('imgFile');
$upload = new UploadServer(); $upload = new UploadServer();
$result = $upload->getUpload($postData,$file); $result = $upload->getUpload($postData,$file);
if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']); if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']);
Cache::put($userId.':card:upload:image',1,30);
$tableName = 'wx_card_role_'.$serverId; $tableName = 'wx_card_role_'.$serverId;
$role = DB::connection('wx_mysql')->table($tableName)->where('uid',$userId)->where('role_id',$roleId)->select('id')->first(); $role = DB::connection('wx_mysql')->table($tableName)->where('uid',$userId)->where('role_id',$roleId)->select('id')->first();
$img = $this->getUpdateImg($result['data'],$userId,$role->id,$serverId); $img = $this->getUpdateImg($result['data'],$userId,$role->id,$serverId);
if($img) return $this->jsonReturn(0, '上传成功',['src'=>$result['data']]); if($img) return $this->jsonReturn(0, '上传成功');
Cache::forget($userId.':card:upload:image');
return $this->jsonReturn(10060, '上传失败'); return $this->jsonReturn(10060, '上传失败');
} }
return $this->jsonReturn(10056, '请选择要上传的图片'); return $this->jsonReturn(10056, '请选择要上传的图片');
...@@ -302,9 +310,11 @@ class CardController extends Controller ...@@ -302,9 +310,11 @@ class CardController extends Controller
{ {
$img = WxUserImg::where('uid',$userId)->where('role_id',$roleId)->where('server_id',$serverId)->first(); $img = WxUserImg::where('uid',$userId)->where('role_id',$roleId)->where('server_id',$serverId)->first();
if($img){ if($img){
if($img->loacl_url != '' && file_exists(public_path().'/'.$img->loacl_url)) unlink(public_path().'/'.$img->loacl_url);
$img->loacl_url = $data['url']; $img->loacl_url = $data['url'];
$img->img_url = $data['yunUrl']; $img->img_url = $data['yunUrl'];
$img->status = 0; $img->status = 0;
$img->is_upload = 0;
if($img->save()) return true; if($img->save()) return true;
}else{ }else{
$row = new WxUserImg(); $row = new WxUserImg();
...@@ -314,6 +324,7 @@ class CardController extends Controller ...@@ -314,6 +324,7 @@ class CardController extends Controller
$row->loacl_url = $data['url']; $row->loacl_url = $data['url'];
$row->img_url = $data['yunUrl']; $row->img_url = $data['yunUrl'];
$row->status = 0; $row->status = 0;
$row->is_upload = 0;
$row->remark = ''; $row->remark = '';
if($row->save()) return true; if($row->save()) return true;
} }
...@@ -328,10 +339,13 @@ class CardController extends Controller ...@@ -328,10 +339,13 @@ class CardController extends Controller
public function getCardHtml(Request $request) public function getCardHtml(Request $request)
{ {
$userId = $request->session()->get("uid"); $userId = $request->session()->get("uid");
$result = $this->getVerityLogin($userId);
if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']);
$roleId = $request->input('roleId'); $roleId = $request->input('roleId');
$serverId = $request->input('serverId'); $serverId = $request->input('serverId');
if(Cache::has('card:info:'.$userId.':'.$roleId)){
$data = Cache::get('card:info:'.$userId.':'.$roleId,[]);
}else{
$result = $this->getVerityLogin($userId);
if($result['code'] != 200) return $this->jsonReturn($result['code'], $result['msg']);
if (empty($roleId) || empty($serverId)) return $this->jsonReturn(7002, '参数错误'); if (empty($roleId) || empty($serverId)) return $this->jsonReturn(7002, '参数错误');
if (!Schema::connection('wx_mysql')->hasTable('wx_card_role_'.$serverId)) return redirect(route('index')); if (!Schema::connection('wx_mysql')->hasTable('wx_card_role_'.$serverId)) return redirect(route('index'));
$info = DB::connection('wx_mysql')->table('wx_card_role_'.$serverId)->where('uid',$userId)->where('role_id',$roleId)->where('server_id',$serverId)->first(); $info = DB::connection('wx_mysql')->table('wx_card_role_'.$serverId)->where('uid',$userId)->where('role_id',$roleId)->where('server_id',$serverId)->first();
...@@ -439,6 +453,8 @@ class CardController extends Controller ...@@ -439,6 +453,8 @@ class CardController extends Controller
}else{ }else{
$data['braveTime'] = '00:00'; $data['braveTime'] = '00:00';
} }
Cache::put('card:info:'.$userId.':'.$roleId,300,$data);
}
return view('card.card', $data); return view('card.card', $data);
} }
} }
\ No newline at end of file
...@@ -141,8 +141,8 @@ class AldGmService { ...@@ -141,8 +141,8 @@ class AldGmService {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, count($submitData)); curl_setopt($curl, CURLOPT_POST, count($submitData));
curl_setopt($curl, CURLOPT_POSTFIELDS, $submitData); curl_setopt($curl, CURLOPT_POSTFIELDS, $submitData);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
curl_close($curl); curl_close($curl);
...@@ -160,8 +160,8 @@ class AldGmService { ...@@ -160,8 +160,8 @@ class AldGmService {
$url .= "?" . http_build_query($submitData); $url .= "?" . http_build_query($submitData);
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
curl_close($curl); curl_close($curl);
......
...@@ -38,7 +38,7 @@ class UploadServer ...@@ -38,7 +38,7 @@ class UploadServer
return $array; return $array;
} }
$originName = $file->getClientOriginalName(); $originName = $file->getClientOriginalName();
self::getCheckDir( storage_path('app'),'card'); self::getCheckDir(public_path(),'card');
$fileUrl = self::getUploadFile($file,'card','aldzn-img',$originName); $fileUrl = self::getUploadFile($file,'card','aldzn-img',$originName);
if($fileUrl['error'] != ''){ if($fileUrl['error'] != ''){
$array['code'] = 10059; $array['code'] = 10059;
...@@ -102,7 +102,8 @@ class UploadServer ...@@ -102,7 +102,8 @@ class UploadServer
$realPath = $file->getRealPath(); $realPath = $file->getRealPath();
if(Storage::disk('upload')->put($path.'/'.$fileName, file_get_contents($realPath))){ if(Storage::disk('upload')->put($path.'/'.$fileName, file_get_contents($realPath))){
$imgUrl['url'] = $folder.'/'.date('Ym').'/'.date('d').'/'.$fileName; $imgUrl['url'] = $folder.'/'.date('Ym').'/'.date('d').'/'.$fileName;
$imgUrl['yunUrl'] = self::getUploadAliyun($bucket, $folder.'/'.date('Ym').'/'.date('d').'/'.$fileName,storage_path('app').'/'.$imgUrl['url']); $imgUrl['yunUrl'] = '';
//$imgUrl['yunUrl'] = self::getUploadAliyun($bucket, $folder.'/'.date('Ym').'/'.date('d').'/'.$fileName,storage_path('app').'/'.$imgUrl['url']);
}else{ }else{
$imgUrl['error'] = '文件上传失败!'; $imgUrl['error'] = '文件上传失败!';
} }
...@@ -128,10 +129,7 @@ class UploadServer ...@@ -128,10 +129,7 @@ class UploadServer
$client = $manager->init($aliyunConfig); $client = $manager->init($aliyunConfig);
$result = $client->uploadFile($object, $fileUrl); $result = $client->uploadFile($object, $fileUrl);
if($result == false){ if($result == false) return false;
exit($client->getError());
}
unset($result,$manager,$client); unset($result,$manager,$client);
return config('sign.OSS_CDN').$object; return config('sign.OSS_CDN').$object;
} }
......
...@@ -50,7 +50,7 @@ return [ ...@@ -50,7 +50,7 @@ return [
'upload' => [ 'upload' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app'), 'root' => public_path(),
], ],
'public' => [ 'public' => [
......
...@@ -67,9 +67,21 @@ ...@@ -67,9 +67,21 @@
@if($li->status == 1) 审核通过 @endif @if($li->status == 1) 审核通过 @endif
@if($li->status == 2) 审核拒绝 @endif @if($li->status == 2) 审核拒绝 @endif
</td> </td>
<td><img src="{{ $li->img_url }}" width="50px" height="30px"></td> <td>
@if($li->status == 1 && $li->is_upload)
<img src="{{ $li->img_url }}" width="50px" height="30px">
@else
<img src="/{{ $li->loacl_url }}" width="50px" height="30px">
@endif
</td>
<td>{{ @$li->updated_at }}</td> <td>{{ @$li->updated_at }}</td>
<td> <button type="button" class="btn btn-default" onclick="return showImg('{{ $li->img_url }}');">查看</button></td> <td>
@if($li->status == 1 && $li->is_upload)
<button type="button" class="btn btn-default" onclick="return showImg('{{ $li->img_url }}');">查看</button>
@else
<button type="button" class="btn btn-default" onclick="return showImg('/{{ $li->loacl_url }}');">查看</button>
@endif
</td>
</tr> </tr>
@endforeach @endforeach
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment