海南旅游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.

109 lines
3.1 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('type')->using(AgentType::array());
  36. $grid->column('company_name');
  37. $grid->column('address');
  38. $grid->column('director');
  39. $grid->column('contact_phone');
  40. $grid->column('logo')->image('', 60, 60);
  41. $grid->column('license_pic')->image('', 60, 60);
  42. $grid->column('status')->using(UserStatus::array());
  43. $grid->column('created_at', '注册时间');
  44. $grid->filter(function (Grid\Filter $filter) {
  45. $filter->panel();
  46. $filter->equal('id')->width(2);
  47. $filter->like('company_name')->width(3);
  48. $filter->equal('contact_phone')->width(2);
  49. });
  50. });
  51. }
  52. /**
  53. * Make a show builder.
  54. *
  55. * @param mixed $id
  56. *
  57. * @return Show
  58. */
  59. protected function detail($id)
  60. {
  61. return Show::make($id, new Agent(), function (Show $show) {
  62. $show->disableDeleteButton();
  63. $show->disableEditButton();
  64. //目前逻辑是不允许供应商查看详情页,若需要打开详情页查看,需要再判断是不是当前供应商所属的代理商
  65. $show->field('id');
  66. /*$show->field('address');
  67. $show->field('avatar');
  68. $show->field('company_name');
  69. $show->field('contact_phone');
  70. $show->field('director');
  71. $show->field('license_pic');
  72. $show->field('logo');
  73. $show->field('name');
  74. $show->field('rate');
  75. $show->field('status');
  76. $show->field('type');
  77. $show->field('created_at');
  78. $show->field('updated_at');*/
  79. });
  80. }
  81. /**
  82. * Make a form builder.
  83. *
  84. * @return Form
  85. */
  86. protected function form()
  87. {
  88. return Form::make(new Agent(), function (Form $form) {
  89. $form->disableFooter();
  90. $form->disableHeader();
  91. $form->disableDeleteButton();
  92. $form->display('id');
  93. })->saving(function (Form $form) {
  94. return $form->response()->error('操作禁止');
  95. })->deleting(function (Form $form) {
  96. return $form->response()->error('操作禁止');
  97. });
  98. }
  99. }