链街Dcat后台
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.

129 lines
3.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\LanzuServiceSpeaker;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\v3\Market as MarketModel;
  9. use App\Models\v3\Store as StoreModel;
  10. use Illuminate\Http\Request;
  11. class LanzuServiceSpeakerController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected $title = '播报机管理';
  19. protected $storeList = [];
  20. protected function grid()
  21. {
  22. return Grid::make(new LanzuServiceSpeaker(['store']), function (Grid $grid) {
  23. $this->storeList = StoreModel::getStoreArray();
  24. $grid->model()->orderBy('updated_at', 'desc');
  25. $grid->id->sortable();
  26. $grid->column('device_name', '设备编号');
  27. $grid->column('store_id', '商户ID');
  28. $grid->column('store.name', '商户名');
  29. $grid->column('is_bind', '是否绑定')->switch();
  30. // $grid->column('is_bind')
  31. // ->using([0 => '未绑定', 1 => '已绑定'])
  32. // ->label([0 => 'danger', 1 => 'success']);
  33. $grid->column('bind_time_text', '绑定时间')->sortable();
  34. $grid->filter(function (Grid\Filter $filter) {
  35. $filter->equal('id');
  36. $filter->like('device_name', '设备编号');
  37. $filter->equal('store_id','商户')->select($this->storeList);
  38. });
  39. });
  40. }
  41. /**
  42. * Make a show builder.
  43. *
  44. * @param mixed $id
  45. *
  46. * @return Show
  47. */
  48. protected function detail($id)
  49. {
  50. return Show::make($id, new LanzuServiceSpeaker(), function (Show $show) {
  51. $show->id;
  52. $show->created_at->as(function ($time) {
  53. if ($time) {
  54. return date('Y-m-d H:i', $time);
  55. } else {
  56. return '-';
  57. }
  58. });
  59. $show->updated_at->as(function ($time) {
  60. if ($time) {
  61. return date('Y-m-d H:i', $time);
  62. } else {
  63. return '-';
  64. }
  65. });
  66. });
  67. }
  68. /**
  69. * Make a form builder.
  70. *
  71. * @return Form
  72. */
  73. protected function form()
  74. {
  75. return Form::make(new LanzuServiceSpeaker(), function (Form $form) {
  76. $form->hidden('id');
  77. $form->text("device_name", '设备编号')->required();
  78. //$form->number("store_id",'商户ID')->required();
  79. // $form->select('market_id','所在市场')->options('/api/getAllMarket');
  80. // $storeList = StoreModel::getStoreArray();
  81. $form->select('store_id', '商户')->options($this->storeList);
  82. $form->switch('is_bind', '是否绑定')
  83. ->customFormat(function ($v) {
  84. return $v == 1 ? 1 : 0;
  85. })
  86. ->saving(function ($v) {
  87. return $v == 1 ? 1 : 0;
  88. });
  89. //$form->image("device_name")->disk('oss');
  90. $form->disableResetButton();
  91. $form->disableViewCheck();
  92. $form->disableEditingCheck();
  93. $form->disableCreatingCheck();
  94. });
  95. }
  96. public function getAllMarkets()
  97. {
  98. $data = [];
  99. $markets = MarketModel::all();
  100. foreach ($markets as $market) {
  101. $item = [];
  102. $item['id'] = $market->id;
  103. $item['text'] = $market->name;
  104. $data[] = $item;
  105. }
  106. return response()->json($data);
  107. }
  108. public function getStores(Request $request)
  109. {
  110. $q = $request->get('q');
  111. return StoreModel::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
  112. }
  113. }