123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- namespace App\Admin\Controllers\Recycle;
- use App\Admin\Extensions\Form\ValidateForm;
- use App\Admin\Extensions\Tools\DialogTool;
- use App\Http\Controllers\Controller;
- use App\Models\Company;
- use App\Repositories\CompanyRepository;
- use App\Services\SubsiteService;
- use Encore\Admin\Auth\Permission;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Validation\Rule;
- use Encore\Admin\Admin;
- use App\Models\Subsite;
- use App\Models\Setmeal;
- use Encore\Admin\Facades\Admin as userAdmin;
- class CompanyController extends Controller
- {
- use HasResourceActions;
- public $companyRepository;
- public $subsiteService;
- public function __construct(SubsiteService $subsiteService, CompanyRepository $companyRepository)
- {
- $this->companyRepository = $companyRepository;
- $this->subsiteService = $subsiteService;
- }
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- $grid = $this->grid()->render();
- return $content
- ->header('企业会员')
- ->description('列表')
- ->body(view('admin.recycle.company')->with('grid', $grid));
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('企业会员')
- ->description(' ')
- ->body($this->detail($id));
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Company::withTrashed()->findOrFail($id));
- $show->id('ID');
- $show->username('用户名');
- $show->mobile('联系电话');
- $show->landline_tel('固定电话')->as(function ($landline_tel) {
- if ($landline_tel == '--' || $landline_tel == '---') {
- return '';
- } else {
- return $landline_tel;
- }
- });
- $show->email('电子邮箱');
- $show->contact('企业联系人');
- if(get_subsite_open()){
- $show->subsite_id('分站')->as(function ($subsite_id) {
- if ($subsite_id == 0) {
- return '总站';
- } else {
- $subsite_name = $this->subsiteService->find($subsite_id);
- return $subsite_name->sitename;
- }
- });
- }
- $show->companyname('公司名称');
- $show->short_name('公司简称');
- $show->audit('审核状态')->as(function ($audit) {
- switch ($audit) {
- case 1:
- return '审核通过';
- break;
- case 2:
- return '待审核';
- break;
- case 3:
- return '审核未通过';
- break;
- }
- });
- $show->nature('企业性质')->as(function ($nature) {
- return get_category($nature);
- });
- $show->trade('企业行业')->as(function ($trade) {
- return get_category($trade);
- });
- $show->district('所在地区')->as(function ($district) {
- return get_district_cn($district);
- });
- $show->scale('企业规模')->as(function ($scale) {
- return get_category($scale);
- });
- $show->registered('注册资金');
- $show->currency('资金形式');
- $show->tag('企业福利')->as(function ($tag) {
- foreach ($tag as $key => $val) {
- $tag_cn[] = get_tag_cn($val);
- }
- return implode('+', $tag_cn);
- });
- $show->website('企业网站');
- $show->address('企业地址');
- $show->contents('企业详情');
- $show->logo('企业Logo')->image();
- $show->created_at('Created at');
- $show->updated_at('Updated at');
- return $show;
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Company);
- $grid->model()->onlyTrashed()->orderBy('deleted_at', 'DESC');
- $grid->id('ID');
- $grid->companyname('公司名称')->display(function ($companyname) {
- $html = $companyname;
- if ($this->logo) {
- $html .= ' <span style="padding-left:5px;color: #3c8dbc;" class="vtip" title="<img src=\'' . upload_asset($this->logo) . '\' width=120 height=120>"><i class="fa fa-file-image-o"></i></span>';
- }
- return $html;
- })->width(200);
- $grid->certificate_img('营业执照')->display(function ($certificate_img) {
- if ($certificate_img) {
- return '<span style="padding-left:5px;color: #3c8dbc;" class="vtip" title="<img src=\'' . upload_asset($certificate_img) . '\' width=120 height=120>"><i class="fa fa-file-image-o"></i></span>';
- } else {
- return "未上传";
- }
- });
- $grid->audit('企业认证')->display(function ($audit) {
- switch ($audit) {
- case 1:
- return '<span style="color: green">认证通过</span>';
- break;
- case 2:
- return '<span style="color: red">待认证</span>';
- break;
- case 3:
- return '<span style="color: black">认证未通过</span>';
- break;
- case 0:
- return '<span style="color: gray">未认证</span>';
- break;
- }
- });
- if(get_subsite_open()){
- $grid->subsite_id('所属分站')->display(function ($subsite_id) {
- if ($subsite_id == 0) {
- return "总站";
- } else {
- $subsite = Subsite::findOrFail($subsite_id);
- return $subsite->sitename;
- }
- });
- }
- $grid->setmeal_name('套餐名称')->display(function ($setmeal_name) {
- if (!$setmeal_name) {
- return "--";
- } else {
- return $setmeal_name;
- }
- });
- $grid->created_at('注册时间');
- $grid->deleted_at('删除时间')->display(function ($deleted_at) {
- return $deleted_at;
- });
- $grid->actions(function ($actions) {
- if (userAdmin::user()->can('recycle_company_delete')) {
- $actions->disableDelete(false);
- }
- if (userAdmin::user()->can('recycle_company_restore')) {
- $actions->append("<button class='btn btn-primary btn-xs restore_company' data-id=" . $actions->row['id'] . "><i class='fa fa-audio-description'></i>还原</button>");
- }
- });
- if (userAdmin::user()->can('recycle_company_restore') || userAdmin::user()->can('recycle_company_delete')) {
- $grid->tools(function ($tools) {
- if (userAdmin::user()->can('recycle_company_restore')) {
- $but = <<<EOT
- <div class="btn-group" data-toggle="buttons">
- <label class="btn btn-sm grid-batch-restore btn-primary" title="还原">
- <i class="fa fa-audio-description"></i>
- <input type="radio" class="user-gender">还原
- </label>
- </div>
- EOT;
- $tools->append($but);
- }
- if (userAdmin::user()->can('recycle_company_delete')) {
- $tools->batch(function ($batch) {
- $batch->disableDelete(false);
- });
- }
- });
- } else {
- $grid->disableRowSelector();
- }
- $grid->filter(function ($filter) {
- $filter->column(1/2, function ($filter) {
- // 在这里添加字段过滤器
- $filter->like('companyname', '企业名称');
- $filter->equal('id', '企业ID');
- $filter->like('username', '会员名称');
- $filter->like('mobile', '手机');
- $filter->like('address', '地址');
- });
- $filter->column(1/2, function ($filter) {
- $filter->equal('setmeal_id', '套餐类型')->select(Setmeal::get()->pluck('setmeal_name', 'id'));
- $filter->equal('audit', '企业认证')->select(['1' => '已认证', '2' => '待认证', '3' => '认证未通过','0'=>"未认证"]);
- $subsite = Subsite::where('effective', 1)->select('id', 'sitename')->get();
- $subsiteArr=[];
- if ($subsite) {
- $subsiteArr = $subsite->toArray();
- $subsiteArr = array_column($subsiteArr, 'sitename', 'id');
- }
- $subsiteArr[0] = "总站";
- ksort($subsiteArr);
- if(get_subsite_open()){
- $filter->equal('subsite_id', '所属分站')->select($subsiteArr);
- }
- $filter->equal('certificate_img_audit', '营业执照认证')->select(['1' => '已认证', '2' => '待认证', '3' => '认证未通过', '0' => '未认证']);
- $filter->between('created_at', '注册时间')->datetime();
- });
- });
- return $grid;
- }
- //还原企业
- public function restore($id)
- {
- $ids = array();
- if ($id) {
- $ids = explode(',', $id);
- }
- if (!$ids) {
- return admin_toastr('请勾选需要还原的企业会员', 'error');
- }
- if (Company::whereIn('id', $ids)->restore()) {
- $condition = [['whereIn','id', $ids]];
- event_search_update(Company::class, $condition, 'update');
- $data = [
- 'status' => true,
- 'message' => '还原成功',
- ];
- } else {
- $data = [
- 'status' => false,
- 'message' => '还原失败',
- ];
- }
- return response()->json($data);
- }
- public function destroy($id)
- {
- $ids = array();
- if ($id) {
- $ids = explode(',', $id);
- }
- if (!$ids) {
- return admin_toastr('请勾选需要删除的企业会员', 'error');
- }
- if (Company::withTrashed()->whereIn('id', $ids)->forceDelete()) {
- $data = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- } else {
- $data = [
- 'status' => false,
- 'message' => trans('admin.delete_failed'),
- ];
- }
- return response()->json($data);
- }
- }
|