Skip to content

Commit

Permalink
Merge pull request #30 from marshallgosling/dev
Browse files Browse the repository at this point in the history
Pre-2.3
  • Loading branch information
marshallgosling authored Jun 6, 2024
2 parents 5c8b0a0 + 7d8565e commit 3084589
Show file tree
Hide file tree
Showing 48 changed files with 865 additions and 199 deletions.
4 changes: 2 additions & 2 deletions app/Admin/Actions/Channel/BatchAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function handle(Collection $collection, Request $request)
foreach ($collection as $model)
{
if(in_array($model->status, [Channel::STATUS_READY, Channel::STATUS_DISTRIBUTE])) {
AuditEpgJob::dispatch($model->id, Admin::user()->name);
AuditEpgJob::dispatch($model->id, Admin::user()->name)->onQueue('audit');
$list[] = $model->toArray();
}
}
\App\Tools\Operation::log('批量审核', 'channel/BatchAudit', 'action', $list);
\App\Tools\Operation::log($this->name, 'channel/BatchAudit', 'action', $list);
return $this->response()->success('批量审核任务已提交。')->refresh();
}

Expand Down
4 changes: 4 additions & 0 deletions app/Admin/Actions/Channel/BatchClean.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Admin\Actions\Channel;

use App\Models\Audit;
use App\Models\Channel;
use App\Models\ChannelPrograms;
use Encore\Admin\Actions\BatchAction;
Expand All @@ -27,7 +28,10 @@ public function handle(Collection $collection)
ChannelPrograms::where('channel_id', $model->id)->delete();
$model->status = Channel::STATUS_EMPTY;
$model->start_end = '';
$model->comment = '';
$model->lock_status = Channel::LOCK_EMPTY;
$model->save();
Audit::where('channel_id', $model->id)->delete();
$list[] = $model->toArray();
}

Expand Down
6 changes: 2 additions & 4 deletions app/Admin/Actions/Channel/BatchLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Encore\Admin\Facades\Admin;

class BatchLock extends BatchAction
{
Expand All @@ -27,8 +26,7 @@ public function handle(Collection $collection, Request $request)
}
$model->lock_status = $lock;
if($model->comment == '编单已完成,请加锁并审核!') $model->comment = '';
$model->reviewer = Admin::user()->name;
//$model->audit_date = now();

$model->save();

if($lock == Channel::LOCK_ENABLE) {
Expand All @@ -38,7 +36,7 @@ public function handle(Collection $collection, Request $request)

$list[] = $model->toArray();
}
\App\Tools\Operation::log('批量分发编单', 'channel/BatchClean', 'action', $list);
\App\Tools\Operation::log($this->name, 'channel/BatchLock:'.$lock, 'action', $list);
return $this->response()->success($lock?"加锁成功":"解锁成功")->refresh();
}

Expand Down
52 changes: 52 additions & 0 deletions app/Admin/Actions/Channel/CheckEpg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace App\Admin\Actions\Channel;

use App\Models\Channel;
use App\Tools\ChannelDatabase;
use Illuminate\Contracts\Support\Renderable;

class CheckEpg implements Renderable
{

public function render($key = null)
{
$ch = Channel::find($key);
$msg = '';
$label = '';
if(!$ch) $data = '<tr><td>播出编单不存在</td></tr>';
else {
$data = ChannelDatabase::checkEpgWithChannel($ch);

if( $data['result']) {
$label = '<p>播出编单:'.Channel::GROUPS[$ch->name].' 日期:'.$ch->air_date.' 文件:'.$ch->name.'_'.$ch->air_date.'.xml 检查结果:<span class="label label-success">通过</span> 数据一致</p>';
}
else {
$label = '<p>播出编单:'.Channel::GROUPS[$ch->name].' 日期:'.$ch->air_date.' 文件:'.$ch->name.'_'.$ch->air_date.'.xml 检查结果:<span class="label label-danger">不通过</span> 数据不一致</p>';
$msg = "<tr><td>播放编单数据和格非串联单xml文件存在差异,请重新“加锁”</td></tr>";
$msg .= "<tr><td>原因:".$data['msg']."</td></tr>";
$msg .= "<tr><td>差异数据:</td></tr>";
$item = $data['items'][0];
$msg .= "<tr><td>编单数据: {$item['start_at']} - {$item['name']} - {$item['duration']}</td></tr>";
if(count($data['items']) == 2)
{
$item = $data['items'][1];
$msg .= "<tr><td>串联单数据:{$item['start_at']} - {$item['name']} - {$item['duration']}</td></tr>";
}
}

}

$html = <<<HTML
{$label}
<div class="table-responsive">
<table class="table table-striped">
{$msg}
</table>
</div>
HTML;

return $html;
}


}
8 changes: 7 additions & 1 deletion app/Admin/Actions/Channel/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Admin\Actions\Channel;

use App\Models\Audit;
use App\Models\Channel;
use App\Models\ChannelPrograms;
use Encore\Admin\Actions\RowAction;
Expand All @@ -21,11 +22,16 @@ public function handle(Channel $model)
}

ChannelPrograms::where('channel_id', $model->id)->delete();

$model->status = Channel::STATUS_EMPTY;
$model->start_end = '';
$model->comment = '';
$model->lock_status = Channel::LOCK_EMPTY;
$model->save();
Audit::where('channel_id', $model->id)->delete();


\App\Tools\Operation::log('清空编单', 'channel/Clean', 'action', $model->toArray());

return $this->response()->success(__('Clean success message.'))->refresh();
}

Expand Down
3 changes: 3 additions & 0 deletions app/Admin/Actions/Channel/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function handle(Channel $model)

XkvGeneratorJob::dispatch($model->id)->onQueue('xkv');

\App\Tools\Operation::log($this->name, 'channel/Generator', 'action', $model->toArray());


return $this->response()->success(__('Generator start success message.'))->refresh();
}

Expand Down
39 changes: 39 additions & 0 deletions app/Admin/Actions/Channel/Lock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Admin\Actions\Channel;

use App\Jobs\EpgJob;
use App\Jobs\StatisticJob;
use App\Models\Channel;
use Encore\Admin\Actions\RowAction;

class Lock extends RowAction
{
public $name = '加/解锁';

public function handle(Channel $model)
{
// $model ...
if(!in_array($model->status, [Channel::STATUS_READY, Channel::STATUS_DISTRIBUTE])) {
return $this->response()->error(__('频道编单状态异常'))->refresh();
}

$lock = $model->lock_status;

$model->lock_status = $lock == Channel::LOCK_EMPTY ? Channel::LOCK_ENABLE : Channel::LOCK_EMPTY;
if($model->comment == '编单已完成,请加锁并审核!') $model->comment = '';

$model->save();

if($model->lock_status == Channel::LOCK_ENABLE) {
StatisticJob::dispatch($model->id);
EpgJob::dispatch($model->id);
}

$lock = $model->lock_status;
\App\Tools\Operation::log($this->name, 'channel/BatchLock:'.$lock, 'action', $model);

return $this->response()->success($lock?"加锁成功":"解锁成功")->refresh();
}

}
5 changes: 4 additions & 1 deletion app/Admin/Actions/Channel/ToolEpgList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public function handle(Collection $collection)
$list = [];
foreach ($collection as $model)
{
if($model->lock_status != Channel::LOCK_ENABLE || $model->status != Channel::STATUS_READY) {
if($model->lock_status != Channel::LOCK_ENABLE ) {
// 空编单和停止使用的编单不能通过审核
continue;
}

if(!in_array( $model->status, [ Channel::STATUS_READY, Channel::STATUS_DISTRIBUTE] ))
continue;
//if($model->name == 'xkc')
ExportJob::dispatch($model->id);
$list[] = $model->toArray();
Expand Down
7 changes: 4 additions & 3 deletions app/Admin/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Program;
use App\Models\Template;
use App\Tools\Notify;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -30,7 +31,7 @@ public function treePrograms(Request $request) {
$q = substr($q, 0, 20);
$size = 20;$start = ($p-1)*$size;

$model = DB::table('program');
$model = DB::table('program')->where('status', Program::STATUS_READY);

if($q)
$model = $model->where('name', 'like', "$q")->orWhere('unique_no', 'like', "$q")->orWhere('artist', 'like', "$q");
Expand Down Expand Up @@ -64,7 +65,7 @@ public function records(Request $request) {
$size = 20;
$start = ($p-1)*$size;

$model = DB::table($t);
$model = DB::table($t)->where('status', Program::STATUS_READY);
if($t == 'program')
$sql = 'id, unique_no, duration, name, category, artist, 1 as ep, black';
else
Expand Down Expand Up @@ -100,7 +101,7 @@ public function programs(Request $request) {
$q = $request->get('q');

return DB::table('program')->where('name', 'like', "%$q%")->orWhere('unique_no', 'like', "$q%")->orWhere('artist', 'like', "%$q%")
->select(DB::raw('`unique_no` as id, concat(unique_no, " ", name, " ", artist) as text'))
->where('status', Program::STATUS_READY)->select(DB::raw('`unique_no` as id, concat(unique_no, " ", name, " ", artist) as text'))
->orderBy('seconds', 'desc')->paginate(15);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Admin/Controllers/AuditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function grid()
else {
foreach($data['material']['logs'] as $item) {
$rows[] = [
$item['name'], $item['unique_no'], $item['duration'], '缺失物料'
$item['name'], $item['unique_no'], $item['duration'], array_key_exists('error', $item) ? $item['error'] : '缺失物料'
];
}
$head = ['名称','播出编号','时长',''];
Expand Down
48 changes: 42 additions & 6 deletions app/Admin/Controllers/Channel/XkcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use App\Admin\Actions\Channel\BatchLock;
use App\Admin\Actions\Channel\BatchClean;
use App\Admin\Actions\Channel\BatchDistributor;
use App\Admin\Actions\Channel\CheckEpg;
use App\Admin\Actions\Channel\CheckXml;
use App\Admin\Actions\Channel\Clean;
use App\Admin\Actions\Channel\Lock;
use App\Admin\Actions\Channel\TemplateLink;
use App\Admin\Actions\Channel\ToolExporter;
use App\Admin\Actions\Channel\ToolGenerator;
Expand All @@ -23,6 +25,7 @@
use Illuminate\Support\Str;
use Illuminate\Support\MessageBag;
use App\Tools\ChannelGenerator;
use Encore\Admin\Grid\Displayers\ContextMenuActions;
use Encore\Admin\Widgets\Table;

class XkcController extends AdminController
Expand Down Expand Up @@ -116,7 +119,7 @@ protected function grid()
$labels = ['warning', 'success', 'danger'];
if(!$model->audit) return "<p>无审核记录</p>";
$rows = [];
foreach($model->audit()->orderBy('id','desc')->limit(10)->get() as $item) {
foreach($model->audit()->orderBy('id','desc')->take(10)->get() as $item) {
$rows[] = [
$item->id, '<span class="label label-'.$labels[$item->status].'">'.Audit::STATUS[$item->status].'</span>',
$item->created_at, $item->comment, '<a href="./audit?channel_id='.$model->id.'">查看详细</a>'
Expand All @@ -130,13 +133,14 @@ protected function grid()

$grid->column('audit_date', __('Audit date'))->hide();

$grid->column('check', __('操作'))->display(function() {return '校对';})->modal('检查播出串联单', CheckXml::class)->width(80);
$grid->column('check', __('操作'))->display(function() {return '校对';})->modal('检查播出串联单', CheckEpg::class)->width(80);
$grid->column('distribution_date', __('Distribution date'))->sortable();
$grid->column('comment', __('Comment'));
$grid->column('created_at', __('Created at'))->sortable()->hide();
$grid->column('updated_at', __('Updated at'))->sortable()->hide();

$grid->actions(function ($actions) {
$actions->add(new Lock);
$actions->add(new TemplateLink);
});

Expand All @@ -163,6 +167,8 @@ protected function grid()
$tools->append(new ToolExporter('xkc'));
});

$grid->setActionClass(ContextMenuActions::class);

return $grid;
}

Expand Down Expand Up @@ -258,8 +264,13 @@ public function export(Content $content, Request $request)
$generator = new TableGenerator($this->group);
$st = strtotime($request->get('start_at', ''));
$ed = strtotime($request->get('end_at', ''));
$lang = $request->get('lang', 'zh');
$label_st = '';
$label_ed = '';
$zh_checked = '';
$en_checked = '';
if($lang == 'zh') $zh_checked = "checked";
if($lang == 'en') $en_checked = "checked";

$max = (int)config('MAX_EXPORT_DAYS', 7);

Expand All @@ -275,20 +286,21 @@ public function export(Content $content, Request $request)
$days = $generator->generateDays($st, $ed);
$data = $generator->processData($days);
$template = $generator->loadTemplate();
$table = $generator->export($days, $template, $data);
$table = $generator->export($days, $template, $data, $lang);
}

$filter= <<<FILTER
<div class="box-header with-border filter-box" id="filter-box">
<form action="export" class="form-horizontal" pjax-container method="get">
<div class="row">
<div class="col-md-8">
<div class="col-md-10">
<div class="box-body">
<div class="fields-group">
<div class="form-group">
<div class="form-group">
<label class="col-sm-2 control-label">时间范围</label>
<div class="col-sm-8">
<div class="col-sm-6">
<div class="input-group input-group-sm">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
Expand All @@ -300,6 +312,29 @@ public function export(Content $content, Request $request)
<input type="text" class="form-control" id="start_at_end" placeholder="时间范围" name="end_at" value="{$label_ed}" autocomplete="off">
</div>
</div>
<div class="col-sm-2">
<div class="input-group input-group-sm">
<span class="icheck">
<label class="radio-inline">
<input type="radio" class="language" name="lang" value="zh" {$zh_checked}> 中文
</label>
</span>
<span class="icheck">
<label class="radio-inline">
<input type="radio" class="language" name="lang" value="en" {$en_checked}> En
</label>
</span>
</div>
</div>
<div class="col-sm-2">
<div class="btn-group pull-left">
<button class="btn btn-info submit btn-sm"><i class="fa fa-search"></i> 搜索</button>
Expand Down Expand Up @@ -335,6 +370,7 @@ public function export(Content $content, Request $request)
$("#start_at_end").on("dp.change", function (e) {
$('#start_at_start').data("DateTimePicker").maxDate(e.date);
});
$('.language').iCheck({radioClass:'iradio_minimal-blue'});
DATE;

}
Loading

0 comments on commit 3084589

Please sign in to comment.