海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2 KiB

  1. <?php
  2. namespace App\AdminSupplier\Controllers;
  3. use App\AdminSupplier\Repositories\Agent;
  4. use App\Common\ProductStatus;
  5. use App\Models\Agent as AgentModel;
  6. use App\Common\AgentType;
  7. use App\Common\UserStatus;
  8. use Dcat\Admin\Admin;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use Dcat\Admin\Http\Controllers\AdminController;
  13. class AgentController extends AdminController
  14. {
  15. /**
  16. * Make a grid builder.
  17. *
  18. * @return Grid
  19. */
  20. protected function grid()
  21. {
  22. $model = AgentModel::whereHas('agentProduct', function($query) {
  23. //只统计在售产品的代理商
  24. return $query->where('status', ProductStatus::ON_SALE)
  25. ->whereHas('product', function ($query) {
  26. return $query->where(['supplier_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
  27. });
  28. });
  29. return Grid::make($model, function (Grid $grid) {
  30. $grid->disableRowSelector();
  31. $grid->disableBatchDelete();
  32. $grid->disableCreateButton();
  33. $grid->disableActions();
  34. $grid->column('id')->sortable();
  35. $grid->column('name');
  36. $grid->column('type')->using(AgentType::array());
  37. $grid->column('company_name');
  38. $grid->column('address');
  39. $grid->column('director');
  40. $grid->column('contact_phone');
  41. $grid->column('logo')->image('', 60, 60);
  42. $grid->column('license_pic')->image('', 60, 60);
  43. $grid->column('status')->using(UserStatus::array());
  44. $grid->column('created_at', '注册时间');
  45. $grid->filter(function (Grid\Filter $filter) {
  46. $filter->panel();
  47. $filter->equal('id')->width(2);
  48. $filter->like('name')->width(2);
  49. $filter->like('company_name')->width(3);
  50. $filter->equal('contact_phone')->width(2);
  51. });
  52. });
  53. }
  54. /**
  55. * Make a show builder.
  56. *
  57. * @param mixed $id
  58. *
  59. * @return Show
  60. */
  61. protected function detail($id)
  62. {
  63. return Show::make($id, new Agent(), function (Show $show) {
  64. $show->disableDeleteButton();
  65. $show->disableEditButton();
  66. //目前逻辑是不允许供应商查看详情页,若需要打开详情页查看,需要再判断是不是当前供应商所属的代理商
  67. $show->field('id');
  68. /*$show->field('address');
  69. $show->field('avatar');
  70. $show->field('company_name');
  71. $show->field('contact_phone');
  72. $show->field('director');
  73. $show->field('license_pic');
  74. $show->field('logo');
  75. $show->field('name');
  76. $show->field('rate');
  77. $show->field('status');
  78. $show->field('type');
  79. $show->field('created_at');
  80. $show->field('updated_at');*/
  81. });
  82. }
  83. /**
  84. * Make a form builder.
  85. *
  86. * @return Form
  87. */
  88. protected function form()
  89. {
  90. return Form::make(new Agent(), function (Form $form) {
  91. $form->disableFooter();
  92. $form->disableHeader();
  93. $form->disableDeleteButton();
  94. $form->display('id');
  95. })->saving(function (Form $form) {
  96. return $form->response()->error('操作禁止');
  97. })->deleting(function (Form $form) {
  98. return $form->response()->error('操作禁止');
  99. });
  100. }
  101. }