CompanyController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. namespace App\Admin\Controllers\Recycle;
  3. use App\Admin\Extensions\Form\ValidateForm;
  4. use App\Admin\Extensions\Tools\DialogTool;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Company;
  7. use App\Repositories\CompanyRepository;
  8. use App\Services\SubsiteService;
  9. use Encore\Admin\Auth\Permission;
  10. use Encore\Admin\Controllers\HasResourceActions;
  11. use Encore\Admin\Form;
  12. use Encore\Admin\Grid;
  13. use Encore\Admin\Layout\Content;
  14. use Encore\Admin\Show;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\Auth;
  17. use Illuminate\Support\Facades\DB;
  18. use Illuminate\Validation\Rule;
  19. use Encore\Admin\Admin;
  20. use App\Models\Subsite;
  21. use App\Models\Setmeal;
  22. use Encore\Admin\Facades\Admin as userAdmin;
  23. class CompanyController extends Controller
  24. {
  25. use HasResourceActions;
  26. public $companyRepository;
  27. public $subsiteService;
  28. public function __construct(SubsiteService $subsiteService, CompanyRepository $companyRepository)
  29. {
  30. $this->companyRepository = $companyRepository;
  31. $this->subsiteService = $subsiteService;
  32. }
  33. /**
  34. * Index interface.
  35. *
  36. * @param Content $content
  37. * @return Content
  38. */
  39. public function index(Content $content)
  40. {
  41. $grid = $this->grid()->render();
  42. return $content
  43. ->header('企业会员')
  44. ->description('列表')
  45. ->body(view('admin.recycle.company')->with('grid', $grid));
  46. }
  47. /**
  48. * Show interface.
  49. *
  50. * @param mixed $id
  51. * @param Content $content
  52. * @return Content
  53. */
  54. public function show($id, Content $content)
  55. {
  56. return $content
  57. ->header('企业会员')
  58. ->description(' ')
  59. ->body($this->detail($id));
  60. }
  61. /**
  62. * Make a show builder.
  63. *
  64. * @param mixed $id
  65. * @return Show
  66. */
  67. protected function detail($id)
  68. {
  69. $show = new Show(Company::withTrashed()->findOrFail($id));
  70. $show->id('ID');
  71. $show->username('用户名');
  72. $show->mobile('联系电话');
  73. $show->landline_tel('固定电话')->as(function ($landline_tel) {
  74. if ($landline_tel == '--' || $landline_tel == '---') {
  75. return '';
  76. } else {
  77. return $landline_tel;
  78. }
  79. });
  80. $show->email('电子邮箱');
  81. $show->contact('企业联系人');
  82. if(get_subsite_open()){
  83. $show->subsite_id('分站')->as(function ($subsite_id) {
  84. if ($subsite_id == 0) {
  85. return '总站';
  86. } else {
  87. $subsite_name = $this->subsiteService->find($subsite_id);
  88. return $subsite_name->sitename;
  89. }
  90. });
  91. }
  92. $show->companyname('公司名称');
  93. $show->short_name('公司简称');
  94. $show->audit('审核状态')->as(function ($audit) {
  95. switch ($audit) {
  96. case 1:
  97. return '审核通过';
  98. break;
  99. case 2:
  100. return '待审核';
  101. break;
  102. case 3:
  103. return '审核未通过';
  104. break;
  105. }
  106. });
  107. $show->nature('企业性质')->as(function ($nature) {
  108. return get_category($nature);
  109. });
  110. $show->trade('企业行业')->as(function ($trade) {
  111. return get_category($trade);
  112. });
  113. $show->district('所在地区')->as(function ($district) {
  114. return get_district_cn($district);
  115. });
  116. $show->scale('企业规模')->as(function ($scale) {
  117. return get_category($scale);
  118. });
  119. $show->registered('注册资金');
  120. $show->currency('资金形式');
  121. $show->tag('企业福利')->as(function ($tag) {
  122. foreach ($tag as $key => $val) {
  123. $tag_cn[] = get_tag_cn($val);
  124. }
  125. return implode('+', $tag_cn);
  126. });
  127. $show->website('企业网站');
  128. $show->address('企业地址');
  129. $show->contents('企业详情');
  130. $show->logo('企业Logo')->image();
  131. $show->created_at('Created at');
  132. $show->updated_at('Updated at');
  133. return $show;
  134. }
  135. /**
  136. * Make a grid builder.
  137. *
  138. * @return Grid
  139. */
  140. protected function grid()
  141. {
  142. $grid = new Grid(new Company);
  143. $grid->model()->onlyTrashed()->orderBy('deleted_at', 'DESC');
  144. $grid->id('ID');
  145. $grid->companyname('公司名称')->display(function ($companyname) {
  146. $html = $companyname;
  147. if ($this->logo) {
  148. $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>';
  149. }
  150. return $html;
  151. })->width(200);
  152. $grid->certificate_img('营业执照')->display(function ($certificate_img) {
  153. if ($certificate_img) {
  154. 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>';
  155. } else {
  156. return "未上传";
  157. }
  158. });
  159. $grid->audit('企业认证')->display(function ($audit) {
  160. switch ($audit) {
  161. case 1:
  162. return '<span style="color: green">认证通过</span>';
  163. break;
  164. case 2:
  165. return '<span style="color: red">待认证</span>';
  166. break;
  167. case 3:
  168. return '<span style="color: black">认证未通过</span>';
  169. break;
  170. case 0:
  171. return '<span style="color: gray">未认证</span>';
  172. break;
  173. }
  174. });
  175. if(get_subsite_open()){
  176. $grid->subsite_id('所属分站')->display(function ($subsite_id) {
  177. if ($subsite_id == 0) {
  178. return "总站";
  179. } else {
  180. $subsite = Subsite::findOrFail($subsite_id);
  181. return $subsite->sitename;
  182. }
  183. });
  184. }
  185. $grid->setmeal_name('套餐名称')->display(function ($setmeal_name) {
  186. if (!$setmeal_name) {
  187. return "--";
  188. } else {
  189. return $setmeal_name;
  190. }
  191. });
  192. $grid->created_at('注册时间');
  193. $grid->deleted_at('删除时间')->display(function ($deleted_at) {
  194. return $deleted_at;
  195. });
  196. $grid->actions(function ($actions) {
  197. if (userAdmin::user()->can('recycle_company_delete')) {
  198. $actions->disableDelete(false);
  199. }
  200. if (userAdmin::user()->can('recycle_company_restore')) {
  201. $actions->append("<button class='btn btn-primary btn-xs restore_company' data-id=" . $actions->row['id'] . "><i class='fa fa-audio-description'></i>还原</button>");
  202. }
  203. });
  204. if (userAdmin::user()->can('recycle_company_restore') || userAdmin::user()->can('recycle_company_delete')) {
  205. $grid->tools(function ($tools) {
  206. if (userAdmin::user()->can('recycle_company_restore')) {
  207. $but = <<<EOT
  208. <div class="btn-group" data-toggle="buttons">
  209. <label class="btn btn-sm grid-batch-restore btn-primary" title="还原">
  210. <i class="fa fa-audio-description"></i>
  211. <input type="radio" class="user-gender">还原
  212. </label>
  213. </div>
  214. EOT;
  215. $tools->append($but);
  216. }
  217. if (userAdmin::user()->can('recycle_company_delete')) {
  218. $tools->batch(function ($batch) {
  219. $batch->disableDelete(false);
  220. });
  221. }
  222. });
  223. } else {
  224. $grid->disableRowSelector();
  225. }
  226. $grid->filter(function ($filter) {
  227. $filter->column(1/2, function ($filter) {
  228. // 在这里添加字段过滤器
  229. $filter->like('companyname', '企业名称');
  230. $filter->equal('id', '企业ID');
  231. $filter->like('username', '会员名称');
  232. $filter->like('mobile', '手机');
  233. $filter->like('address', '地址');
  234. });
  235. $filter->column(1/2, function ($filter) {
  236. $filter->equal('setmeal_id', '套餐类型')->select(Setmeal::get()->pluck('setmeal_name', 'id'));
  237. $filter->equal('audit', '企业认证')->select(['1' => '已认证', '2' => '待认证', '3' => '认证未通过','0'=>"未认证"]);
  238. $subsite = Subsite::where('effective', 1)->select('id', 'sitename')->get();
  239. $subsiteArr=[];
  240. if ($subsite) {
  241. $subsiteArr = $subsite->toArray();
  242. $subsiteArr = array_column($subsiteArr, 'sitename', 'id');
  243. }
  244. $subsiteArr[0] = "总站";
  245. ksort($subsiteArr);
  246. if(get_subsite_open()){
  247. $filter->equal('subsite_id', '所属分站')->select($subsiteArr);
  248. }
  249. $filter->equal('certificate_img_audit', '营业执照认证')->select(['1' => '已认证', '2' => '待认证', '3' => '认证未通过', '0' => '未认证']);
  250. $filter->between('created_at', '注册时间')->datetime();
  251. });
  252. });
  253. return $grid;
  254. }
  255. //还原企业
  256. public function restore($id)
  257. {
  258. $ids = array();
  259. if ($id) {
  260. $ids = explode(',', $id);
  261. }
  262. if (!$ids) {
  263. return admin_toastr('请勾选需要还原的企业会员', 'error');
  264. }
  265. if (Company::whereIn('id', $ids)->restore()) {
  266. $condition = [['whereIn','id', $ids]];
  267. event_search_update(Company::class, $condition, 'update');
  268. $data = [
  269. 'status' => true,
  270. 'message' => '还原成功',
  271. ];
  272. } else {
  273. $data = [
  274. 'status' => false,
  275. 'message' => '还原失败',
  276. ];
  277. }
  278. return response()->json($data);
  279. }
  280. public function destroy($id)
  281. {
  282. $ids = array();
  283. if ($id) {
  284. $ids = explode(',', $id);
  285. }
  286. if (!$ids) {
  287. return admin_toastr('请勾选需要删除的企业会员', 'error');
  288. }
  289. if (Company::withTrashed()->whereIn('id', $ids)->forceDelete()) {
  290. $data = [
  291. 'status' => true,
  292. 'message' => trans('admin.delete_succeeded'),
  293. ];
  294. } else {
  295. $data = [
  296. 'status' => false,
  297. 'message' => trans('admin.delete_failed'),
  298. ];
  299. }
  300. return response()->json($data);
  301. }
  302. }