diff --git a/app/AdminAgent/Controllers/WorkorderController.php b/app/AdminAgent/Controllers/WorkorderController.php index bd03685..0999571 100755 --- a/app/AdminAgent/Controllers/WorkorderController.php +++ b/app/AdminAgent/Controllers/WorkorderController.php @@ -70,7 +70,10 @@ class WorkorderController extends AdminController $data = [ 'user_list' => $userList, 'msg_list' => $msgList, - 'user' => Admin::user() + 'user' => Admin::user(), + 'workorder' => [ + 'workorder_id' => $workorderId + ], ]; return $content @@ -78,70 +81,70 @@ class WorkorderController extends AdminController ->description('列表') ->body(admin_view('admin.pages.index',$data)); } - - /** - * Make a grid builder. - * - * @return Grid - */ - protected function grid() - { - return Grid::make(new Workorder(['publisher','point']), function (Grid $grid) { - $grid->model() - ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]]) - ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[0]]); - $grid->column('id')->sortable(); - $grid->column('title'); - $grid->column('content_modal','内容')->modal('详情',function ($modal) { - $modal->xl(); - return $this->content; - }); - $grid->column('publisher_type')->using(DemandTraits::$polymorphic); - $grid->column('publisher.name','发布人'); - $grid->column('point_type')->using(DemandTraits::$polymorphic); - $grid->column('point.name','接收人'); - $grid->column('status') - ->using(WorkorderTraits::$stateText) - ->dot( - [ - 1 => 'yellow', - 2 => 'danger', - 3 => 'success', - ]); - $grid->column('close_time'); - $grid->column('created_at'); - $grid->column('updated_at')->sortable(); - $grid->disableActions(); - $grid->filter(function (Grid\Filter $filter) { - $filter->equal('id'); - - }); - }); - } - - /** - * Make a show builder. - * - * @param mixed $id - * - * @return Show - */ - protected function detail($id) - { - return Show::make($id, new Workorder(), function (Show $show) { - $show->field('id'); - $show->field('title'); - $show->field('content'); - $show->field('publisher_type'); - $show->field('publisher_id'); - $show->field('point_type'); - $show->field('point_id'); - $show->field('status'); - $show->field('close_time'); - $show->field('created_at'); - $show->field('updated_at'); - }); - } + // + ///** + // * Make a grid builder. + // * + // * @return Grid + // */ + //protected function grid() + //{ + // return Grid::make(new Workorder(['publisher','point']), function (Grid $grid) { + // $grid->model() + // ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]]) + // ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[0]]); + // $grid->column('id')->sortable(); + // $grid->column('title'); + // $grid->column('content_modal','内容')->modal('详情',function ($modal) { + // $modal->xl(); + // return $this->content; + // }); + // $grid->column('publisher_type')->using(DemandTraits::$polymorphic); + // $grid->column('publisher.name','发布人'); + // $grid->column('point_type')->using(DemandTraits::$polymorphic); + // $grid->column('point.name','接收人'); + // $grid->column('status') + // ->using(WorkorderTraits::$stateText) + // ->dot( + // [ + // 1 => 'yellow', + // 2 => 'danger', + // 3 => 'success', + // ]); + // $grid->column('close_time'); + // $grid->column('created_at'); + // $grid->column('updated_at')->sortable(); + // $grid->disableActions(); + // $grid->filter(function (Grid\Filter $filter) { + // $filter->equal('id'); + // + // }); + // }); + //} + // + ///** + // * Make a show builder. + // * + // * @param mixed $id + // * + // * @return Show + // */ + //protected function detail($id) + //{ + // return Show::make($id, new Workorder(), function (Show $show) { + // $show->field('id'); + // $show->field('title'); + // $show->field('content'); + // $show->field('publisher_type'); + // $show->field('publisher_id'); + // $show->field('point_type'); + // $show->field('point_id'); + // $show->field('status'); + // $show->field('close_time'); + // $show->field('created_at'); + // $show->field('updated_at'); + // }); + //} /** * Make a form builder. @@ -251,32 +254,4 @@ class WorkorderController extends AdminController $item->save(); return $this->jsonSuccess($item); } - - public function render() - { - $validator = Validator::make(request()->all(), [ - 'workorder_id' => 'required|int', - ], [ - '*' => '参数异常', - ]); - - if ($validator->fails()) { - return $this->jsonFailValidated('数据不全:'.$validator->errors()->first()); - } - $data = WorkorderItem::query() - ->with('publisher') - ->where('workorder_id',request('workorder_id',0)) - ->orderBy('created_at') - ->get(); - - foreach ($data as &$v) { - if ($v->publisher_type == DemandTraits::$col[0]) { - $v->location = 'right'; - } else { - $v->location = 'left'; - } - } - - return $this->jsonSuccess($data); - } } diff --git a/app/AdminSupplier/Controllers/WorkorderController.php b/app/AdminSupplier/Controllers/WorkorderController.php new file mode 100755 index 0000000..d5d8458 --- /dev/null +++ b/app/AdminSupplier/Controllers/WorkorderController.php @@ -0,0 +1,248 @@ +with(['point','publisher']) + ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]]) + ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[1]]) + ->orderByDesc('updated_at') + ->get(); + + foreach ($workorder as $v) { + $item = WorkorderItem::query()->where('workorder_id',$v->id)->orderByDesc('updated_at')->first(); + $arr = [ + 'workorder_id' => $v->id, + 'unread' => true, + 'avatar' => $v->publisher_type == DemandTraits::$col[1] ? $v->point->avatar : $v->publisher->avatar, + 'name' => $v->publisher_type == DemandTraits::$col[1] ? $v->point->name : $v->publisher->name, + 'content' => $v->title, + 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '', + 'last_message_time' => $item->created_at ?? '', + ]; + $userList [] = $arr; + } + + $workorderItem = WorkorderItem::query() + ->with(['publisher']) + ->where('workorder_id',$workorderId) + ->get(); + + foreach ($workorderItem as $v) { + $arr = [ + 'type' => $v->publisher_type == DemandTraits::$col[1] ? 'my' : 'op', + 'it_type' => $v->type, + 'avatar' => $v->publisher->avatar, + 'name' => $v->publisher->name, + 'content' => $v->content, + ]; + $msgList [] = $arr; + } + + $data = [ + 'user_list' => $userList, + 'msg_list' => $msgList, + 'user' => Admin::user(), + 'workorder' => [ + 'workorder_id' => $workorderId + ], + ]; + + return $content + ->header('工单') + ->description('列表') + ->body(admin_view('admin.pages.supplier-index',$data)); + } + + ///** + // * Make a grid builder. + // * + // * @return Grid + // */ + //protected function grid() + //{ + // return Grid::make(new Workorder(['publisher','point']), function (Grid $grid) { + // $grid->model() + // ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]]) + // ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[1]]); + // $grid->column('id')->sortable(); + // $grid->column('title'); + // $grid->column('content_modal','内容')->modal('详情',function ($modal) { + // $modal->xl(); + // return $this->content; + // }); + // $grid->column('publisher_type')->using(DemandTraits::$polymorphic); + // $grid->column('publisher.name','发布人'); + // $grid->column('point_type')->using(DemandTraits::$polymorphic); + // $grid->column('point.name','接收人'); + // $grid->column('status') + // ->using(WorkorderTraits::$stateText) + // ->dot( + // [ + // 1 => 'yellow', + // 2 => 'danger', + // 3 => 'success', + // ]); + // $grid->column('close_time'); + // $grid->column('created_at'); + // $grid->column('updated_at')->sortable(); + // $grid->disableActions(); + // $grid->filter(function (Grid\Filter $filter) { + // $filter->equal('id'); + // + // }); + // }); + //} + // + ///** + // * Make a show builder. + // * + // * @param mixed $id + // * + // * @return Show + // */ + //protected function detail($id) + //{ + // return Show::make($id, new Workorder(), function (Show $show) { + // $show->field('id'); + // $show->field('title'); + // $show->field('content'); + // $show->field('publisher_type'); + // $show->field('publisher_id'); + // $show->field('point_type'); + // $show->field('point_id'); + // $show->field('status'); + // $show->field('close_time'); + // $show->field('created_at'); + // $show->field('updated_at'); + // }); + //} + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new Workorder(), function (Form $form) { + $form->display('id'); + $form->text('title'); + $form->textarea('content'); + $form->select('point_type') + ->options([ + 1 => '代理商', + ]) + ->default(1); + $form->select('supplier_id', '代理商')->options(function () { + $agentIds = AgentProductItem::query()->where('supplier_id',Admin::user()->id)->distinct()->pluck('agent_id'); + return Agent::query()->whereIn('id',$agentIds)->pluck('name','id'); + }); + $form->hidden('point_id'); + $form->hidden('publisher_type'); + $form->hidden('publisher_id'); + $form->saving(function (Form $form) { + // 判断是否是新增操作 + if ($form->isCreating()) { + if ($form->point_type == 1) { + $form->point_id = $form->supplier_id; + } elseif ($form->point_type == 2) { + $form->point_id = $form->guide_id; + } + $form->deleteInput('supplier_id'); + $form->deleteInput('guide_id'); + $form->point_type = DemandTraits::$col[$form->point_type]; + //发布人身份 + $form->publisher_type = DemandTraits::$col[1]; + $form->publisher_id = Admin::user()->id; + } + }); + }); + } + + public function sendImage(Request $request) + { + $validator = Validator::make(request()->all(), [ + 'workorder_id' => 'required|int', + ], [ + '*' => '参数异常', + ]); + + if ($validator->fails()) { + return $this->jsonFailValidated('数据不全:'.$validator->errors()->first()); + } + + $image = $request->file('image'); + if (empty($image) || !$image->isValid()) { + return $this->error('您未上传任何文件'); + } + + $mime = $image->getMimeType(); + if (!in_array($mime, ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg'])) { + return $this->error('上传图片格式错误'); + } + + $path = $request->image->store('public/images/workorder'); + $path = (Storage::url($path)); + $item = new WorkorderItem(); + $item->workorder_id = request('workorder_id',0); + $item->content = $path; + $item->type = 2; + $item->publisher_type = DemandTraits::$col[1]; + $item->publisher_id = Admin::user()->id; + $item->save(); + return $this->jsonSuccess($item); + } + + public function sendText(Request $request) + { + $validator = Validator::make(request()->all(), [ + 'workorder_id' => 'required|int', + 'content' => 'required', + ], [ + '*' => '参数异常', + ]); + + if ($validator->fails()) { + return $this->jsonFailValidated('数据不全:'.$validator->errors()->first()); + } + + $item = new WorkorderItem(); + $item->workorder_id = request('workorder_id',0); + $item->content = request('content',''); + $item->type = 1; + $item->publisher_type = DemandTraits::$col[1]; + $item->publisher_id = Admin::user()->id; + $item->save(); + return $this->jsonSuccess($item); + } +} diff --git a/app/AdminSupplier/routes.php b/app/AdminSupplier/routes.php index 7f7b9c9..d6f5e40 100644 --- a/app/AdminSupplier/routes.php +++ b/app/AdminSupplier/routes.php @@ -29,4 +29,12 @@ Route::group([ $router->resource('finance_statistics', 'FinanceStatisticsController'); $router->resource('order_statistics', 'OrderStatisticsController'); $router->resource('product_statistics', 'ProductStatisticsController'); + + $router->resource('workorder', 'WorkorderController'); + + //api + $router->any('send_text', 'WorkorderController@sendText'); + $router->any('send_image', 'WorkorderController@sendImage'); + + $router->any('workorder_item', 'WorkorderController@index'); }); diff --git a/resources/views/admin/pages/supplier-index.blade.php b/resources/views/admin/pages/supplier-index.blade.php new file mode 100644 index 0000000..6081904 --- /dev/null +++ b/resources/views/admin/pages/supplier-index.blade.php @@ -0,0 +1,241 @@ + + +