| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 | 
							- <?php
 
- namespace App\Admin\Controllers\Company;
 
- use App\Admin\Extensions\Tools\DialogTool;
 
- use App\Admin\Extensions\Tools\GridView;
 
- use App\Http\Controllers\Controller;
 
- use App\Models\Admin\AdminRole;
 
- use App\Models\AuditReason;
 
- use App\Models\Company;
 
- use App\Models\CompanyImg;
 
- use App\Models\Subsite;
 
- use App\Repositories\CompanyImgRepository;
 
- use App\Services\Common\PmsService;
 
- use Encore\Admin\Auth\Permission;
 
- use Encore\Admin\Controllers\HasResourceActions;
 
- use Encore\Admin\Facades\Admin;
 
- use Encore\Admin\Form;
 
- use Encore\Admin\Grid;
 
- use Encore\Admin\Layout\Content;
 
- use Encore\Admin\Show;
 
- use Illuminate\Http\Request as Req;
 
- use Illuminate\Support\Facades\Request;
 
- class CompanyImgController extends Controller
 
- {
 
-     use HasResourceActions;
 
-     protected $companyImgRepository;
 
-     protected $pmsService;
 
-     /**
 
-      * CompanyImgController constructor.
 
-      * @param $companyImgRepository
 
-      * @param $pmsService
 
-      */
 
-     public function __construct(CompanyImgRepository $companyImgRepository, PmsService $pmsService)
 
-     {
 
-         $this->companyImgRepository = $companyImgRepository;
 
-         $this->pmsService = $pmsService;
 
-     }
 
-     /**
 
-      * Index interface.
 
-      *
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function index(Content $content)
 
-     {
 
-         Permission::check('companyImg_manager');
 
-         return $content
 
-             ->header('企业风采')
 
-             ->description('列表')
 
-             ->body($this->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));
 
-     }
 
-     /**
 
-      * Edit interface.
 
-      *
 
-      * @param mixed $id
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function edit($id, Content $content)
 
-     {
 
-         Permission::check('companyImg_manager_edit');
 
-         return $content
 
-             ->header('企业风采')
 
-             ->description('编辑')
 
-             ->body($this->editForm()->edit($id));
 
-     }
 
-     /**
 
-      * Create interface.
 
-      *
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function create(Content $content)
 
-     {
 
-         return $content
 
-             ->header('企业风采')
 
-             ->description('新增')
 
-             ->body($this->form());
 
-     }
 
-     /**
 
-      * Make a grid builder.
 
-      *
 
-      * @return Grid
 
-      */
 
-     protected function grid()
 
-     {
 
-         $grid = new Grid(new CompanyImg);
 
-         $grid->model()->when(get_subsite_id()>0, function ($query) {
 
-             $query->where('subsite_id', get_subsite_id());
 
-         })->whereHas('companys')->when(Admin::user()->isRole(AdminRole::$consultantSlug), function ($query) {
 
-             $query->whereHas('companyConsultant',function ($query){
 
-                 $query->where('consultant_id', isset(Admin::user()->consultant->id) ? Admin::user()->consultant->id : -1);
 
-             });
 
-         })->orderByRaw('field(audit,0,2,1,3)')->orderBy('created_at', 'desc');
 
-         $grid->id('ID');
 
-         $grid->image()->image();
 
-         $grid->company_id('企业名称')->display(function ($company_id) {
 
-             $companyname = Company::where('id', $company_id)->select(['companyname'])->first();
 
-             return $companyname['companyname'];
 
-         })->width(200);
 
-         $grid->audit('审核状态')->display(function ($audit) {
 
-             switch ($audit) {
 
-                 case 1:
 
-                     return '<span style="color:#009900">审核通过</span>';
 
-                     break;
 
-                 case 2:
 
-                     return '<span style="color:#FF6600">审核中</span>';
 
-                     break;
 
-                 case 3:
 
-                     return '<span style="color:#FF0000">审核未通过</span>';
 
-                     break;
 
-                 case 0:
 
-                     return '<span style="color:#FF6600">未审核</span>';
 
-                     break;
 
-             }
 
-         });
 
-         $grid->subsite_id('所属分站')->display(function ($subsite_id) {
 
-             if ($subsite_id == 0) {
 
-                 return "总站";
 
-             } else {
 
-                 $subsite = Subsite::findOrFail($subsite_id);
 
-                 return $subsite->sitename;
 
-             }
 
-         });
 
-         $grid->created_at('添加时间');
 
-         $grid->tools(function (Grid\Tools $tools) {
 
-             if (Admin::user()->can('companyImg_manager_audit')) {
 
-                 $form = new \Encore\Admin\Widgets\Form();
 
-                 $form->action(route('companyimg.audit'));
 
-                 $form->radio('audit1', '审核状态')->options([1=>'审核通过', 2=>'审核中', 3=>'审核未通过'])->default(1);
 
-                 $states = [
 
-                     'on'  => ['value' => 1, 'text' => '是', 'color' => 'success'],
 
-                     'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
 
-                 ];
 
-                 $form->textarea('reason', '备注');
 
-                 $form->html("<input type='checkbox' name='is_send' checked value='1'/>站内信通知");
 
-                 $config = array(
 
-                     'button' => "审核",//添加的按钮文字
 
-                     'title' => "将所选企业",//弹窗标题
 
-                     'dialog_cancel' => "取消",//取消文字
 
-                     'dialog_ok' => "确认",//确认文字
 
-                     'is_batch' => true//是否批量操作,如果是批量操作则提交表单时会带上ids参数
 
-                 );
 
-                 $tools->append(new DialogTool($form, $config));
 
-             }
 
-             $tools->append(new GridView());
 
-         });
 
-         if (Request::get('view') !== 'table') {
 
-             $grid->setView('admin.grid.card');
 
-         }
 
-         $grid->actions(function (Grid\Displayers\Actions $actions) {
 
-             if(Request::get('view') !== 'table') {
 
-                 if (Admin::user()->can('companyImg_manager_audit')) {
 
-                     $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">审核</button>");
 
-                 }
 
-             }
 
-             if (Admin::user()->can('companyImg_manager_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-             if (Admin::user()->can('companyImg_manager_delete')) {
 
-                 $actions->disableDelete(false);
 
-             }
 
-         });
 
-         $grid->filter(function ($filter) {
 
-             $filter->where(function ($query) {
 
-                 $query->whereHas('companys', function ($query) {
 
-                     $query->where('companyname', 'like', "%{$this->input}%");
 
-                 });
 
-             }, '公司名称');
 
-             $filter->equal('company_id', '企业ID');
 
-             $filter->column(1/2, function ($filter) {
 
-                 $filter->equal('audit', '审核状态')->select([0=>'未审核',1=>'审核通过',2=>'审核中',3=>'审核未通过']);
 
-             });
 
-             $filter->column(1/2, function ($filter) {
 
-                 $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_id()== 0) {
 
-                     $filter->equal('subsite_id', '所属分站')->select($subsiteArr);
 
-                 }
 
-                 $filter->between('created_at', '添加时间')->datetime();
 
-             });
 
-         });
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(CompanyImg::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->title('标题');
 
-         $show->image('图片')->image();
 
-         $show->audit('审核状态')->as(function ($audit) {
 
-             switch ($audit) {
 
-                 case 0:
 
-                     return '未审核';
 
-                     break;
 
-                 case 1:
 
-                     return '审核通过';
 
-                     break;
 
-                 case 2:
 
-                     return '审核中';
 
-                     break;
 
-                 case 3:
 
-                     return '审核未通过';
 
-                     break;
 
-             }
 
-         });
 
-         $show->created_at('创建时间');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new CompanyImg);
 
-         $form->display('id');
 
-         $form->text('title', '标题');
 
-         $form->image('image', '图片')->rules('required');
 
-         $form->radio('audit', '审核状态')->options([0=>'未审核',1=>'审核通过',2=>'审核中',3=>'审核未通过',]);
 
-         $form->display('created_at', '上传时间');
 
-         return $form;
 
-     }
 
-     public function editForm()
 
-     {
 
-         $form = new Form(new CompanyImg);
 
-         $form->display('id');
 
-         $form->text('title', '标题');
 
-         $form->image('image', '图片')->rules('required');
 
-         $form->radio('audit', '审核状态')->options([0=>'未审核',1=>'审核通过',2=>'审核中',3=>'审核未通过',]);
 
-         $form->display('created_at', '上传时间');
 
-         return $form;
 
-     }
 
-     public function update($id)
 
-     {
 
-         if (request()->has(Form\Field::FILE_DELETE_FLAG)) {
 
-             return $this->editForm($id)->update($id);
 
-         }
 
-         return $this->editForm($id)->update($id);
 
-     }
 
-     public function companyImgAudit(Req $request)
 
-     {
 
-         $ids = $request->ids;
 
-         if (!$ids) {
 
-             return admin_toastr('请选择要审核的企业', 'error');
 
-         }
 
-         $id = explode(',', $ids);
 
-         $img_com_ids =$this->companyImgRepository->findWhereIn('id', $id, ['company_id','id'])->toArray();
 
-         $reason = $request->reason;
 
-         $data = ['audit'=>$request->audit1];
 
-         if (CompanyImg::whereIn('id', $id)->update($data)) {
 
-             //审核日志$reason
 
-             $auditData= [];
 
-             $auditData['ids'] = $id;
 
-             $auditData['status'] = $request->audit1;
 
-             $auditData['type'] = 9;
 
-             $auditData['reason'] = $reason;
 
-             AuditReason::addData($auditData);
 
-             if ($request->is_send) {
 
-                 //站内信
 
-                 $insertData = [];
 
-                 switch ($request->audit1) {
 
-                     case 1:
 
-                         $html = "通过审核";
 
-                         break;
 
-                     case 2:
 
-                         $html = "审核中";
 
-                         break;
 
-                     case 3:
 
-                         $html = "未通过审核";
 
-                         break;
 
-                 }
 
-                 foreach ($img_com_ids as $key => $val) {
 
-                     $insertData[$key] = array(
 
-                         'utype'      => 1,
 
-                         'msgtype'    => 1,
 
-                         'msgfromuid' => admin::user()->id,
 
-                         'msgfrom'     => admin::user()->username,
 
-                         'msgtoname'   =>getComUserName($val['company_id']),
 
-                         'msgtouid'    => $val['company_id'],
 
-                         'message'     => '企业风采'.$val['id'].$html.'【备注】'.$reason,
 
-                         'new'          => 1,
 
-                         'created_at' =>date('Y-m-d H:i:s', time()),
 
-                         'updated_at' =>date('Y-m-d H:i:s', time()),
 
-                     );
 
-                 }
 
-                 $this->pmsService->addBatchPms($insertData);
 
-             }
 
-             if($request->type) {
 
-                 admin_toastr('企业风采审核成功', 'success');
 
-                 return back();
 
-             } else{
 
-                 return admin_toastr('企业风采审核成功', 'success');
 
-             }
 
-         } else {
 
-             if($request->type) {
 
-                 admin_toastr('企业风采审核失败', 'error');
 
-                 return back();
 
-             } else{
 
-                 return admin_toastr('企业风采审核失败', 'error');
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |