<?php
namespace App\Admin\Controllers;
use App\Company;
use App\Http\Controllers\Controller;
use App\Service;
use App\User;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Table;
class ChannelMyController extends Controller
{
public function company(Content $content) {
return $content->header('我的')
->description('公司')
->body($this->getCompanyShow());
}
public function adviser(Content $content) {
return $content->header('专属')
->description('顾问')
->body($this->getAdviserShow());
}
public function equity(Content $content){
$url = url('img/qudaoquanyi.jpg');
$box = new Box();
$box->title('');
$box->content("<img src='$url'>");
return $content->header("我的企业")
->description('渠道权益')
->body($box);
}
public function workbench(Content $content){
return $content->header('法务工作台')
->row(function (Row $row){
$row->column(4, function (Column $column) {
$column->append($this->getAdviserShow());
});
$row->column(4, function (Column $column) {
$column->append($this->getCompanyShow());
});
});
}
protected function getAdviserShow(){
$company = Company::find(Admin::user()->company_id);
if (empty($company->service_user_id)) {
return '尚未分配专属顾问';
}
return Admin::show(User::findOrFail($company->service_user_id), function (Show $show) {
$show->name('名称');
$show->avatar('头像')->image('', 50,50);
$show->name('姓名');
$show->qq('QQ');
$show->telephone('座机');
$show->mail('邮箱');
$show->desc('详细介绍')->textarea();
$show->panel()->title('我的客服')->tools(function ($tools) {
$tools->disableEdit();
$tools->disableList();
$tools->disableDelete();
});
});
}
protected function getCompanyShow(){
return Admin::show(Company::findOrFail(Admin::user()->company_id), function (Show $show){
$show->name('名称');
$show->logo('Logo')->image('', 50,50);
$show->registration_number('注册号');
$show->registration_amount('注册资金');
$show->contact_name('联系人');
$show->contact_phone('联系电话');
$show->address('地址');
$show->panel()->title('我的公司')->tools(function ($tools) {
$tools->disableEdit();
$tools->disableList();
$tools->disableDelete();
});
});
}
protected function grid()
{
$grid = new Grid(new Service);
$grid->tools(function ($tools) {
$tools->batch(function ($batch) {
$batch->disableDelete();
});
});
$grid->model()->where('user_id', Admin::user()->id);
$grid->disableCreateButton();
$grid->disableExport();
$grid->disableFilter();
$grid->disableRowSelector();
$grid->actions(function ($actions) {
$actions->disableDelete();
$actions->disableEdit(); });
$grid->status('状态')->using([1=>'进行中', 2 => '已回复']);
$grid->type()->name('类型')->label();
$grid->service_user()->name('客服')->label();
$grid->content('内容')->display(function($content){
return '查看';
})->modal('内容', function ($model) {
$columns = [];
$values = [];
foreach ($model->content as $item) {
array_push($columns,$item['name']);
if ($item['type'] == 'file') {
$fileName = empty($item['fileName'])? '未命名' : $item['fileName'] ;
$url =url('uploads/files/'.$item['value']);
array_push($values, "<a href='$url' target='_blank' download='$fileName'>下载</a>");
} else {
array_push($values,$item['value']);
}
}
return new Table($columns, [$values]);;
});
$grid->column('回复')->display(function (){
return '查看';
})->modal('已回复', function ($model) {
$replies = $model->replies()->take(10)->get()->map(function ($reply) {
return $reply->only([ 'title', 'desc', 'file']);
});
$rows= [];
foreach ($replies as &$reply){
$a = '';
if (!empty($reply['file'])) {
$url =url('uploads/files/'.$reply['file']);
$fileName = $reply['title'];
$a = "<a href='$url' target='_blank' download='$fileName'>下载</a>";
}
array_push($rows, [
$reply['title'],
$reply['desc'],
$a
]);
}
return new Table([ '标题', '详情', '附件'], $rows);
});
$grid->created_at('创建时间');
$grid->updated_at('更新时间');
return $grid;
}
public function personal(){
}
}