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

261 lines
7.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminGuide\Controllers;
  3. use App\AdminAgent\Repositories\Workorder;
  4. use App\Common\AgentType;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Agent;
  7. use App\Models\AgentProductItem;
  8. use App\Models\Guide;
  9. use App\Models\OrderProductItem;
  10. use App\Models\Supplier;
  11. use App\Models\WorkorderItem;
  12. use App\Traits\DemandTraits;
  13. use App\Traits\WorkorderTraits;
  14. use Dcat\Admin\Admin;
  15. use Dcat\Admin\Form;
  16. use Dcat\Admin\Grid;
  17. use Dcat\Admin\Layout\Content;
  18. use Dcat\Admin\Show;
  19. use Dcat\Admin\Http\Controllers\AdminController;
  20. use Illuminate\Http\Request;
  21. use App\Traits\ResponseHelper;
  22. use Illuminate\Support\Facades\Storage;
  23. use Illuminate\Support\Facades\Validator;
  24. class WorkorderController extends AdminController
  25. {
  26. use ResponseHelper;
  27. public function index(Content $content)
  28. {
  29. $workorderId = \request('workorder_id',0);
  30. $userList = $msgList = [];
  31. $workorder = \App\Models\Workorder::query()
  32. ->with(['point','publisher'])
  33. ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]])
  34. ->orWhere(function ($query) {
  35. $query->where('point_id',Admin::user()->id)
  36. ->where('point_type',DemandTraits::$col[2]);
  37. })
  38. ->orderByDesc('updated_at')
  39. ->get();
  40. // 先这么处理吧
  41. if ($workorderId == 0 && !empty($workorder)) {
  42. return redirect('/admin-agent/workorder_item?workorder_id='.$workorder[0]->id);
  43. }
  44. foreach ($workorder as $v) {
  45. $item = WorkorderItem::query()->where('workorder_id',$v->id)->orderByDesc('updated_at')->first();
  46. $arr = [
  47. 'workorder_id' => $v->id,
  48. 'unread' => true,
  49. 'avatar' => Storage::url($v->publisher_type == DemandTraits::$col[2] ? $v->point->avatar : $v->publisher->avatar),
  50. 'name' => $v->publisher_type == DemandTraits::$col[2] ? $v->point->name : $v->publisher->name,
  51. 'content' => $v->title,
  52. 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '',
  53. 'last_message_time' => $item->created_at ?? '',
  54. ];
  55. $userList [] = $arr;
  56. }
  57. $workorderItem = WorkorderItem::query()
  58. ->with(['publisher'])
  59. ->where('workorder_id',$workorderId)
  60. ->get();
  61. foreach ($workorderItem as $v) {
  62. $arr = [
  63. 'type' => $v->publisher_type == DemandTraits::$col[2] ? 'my' : 'op',
  64. 'it_type' => $v->type,
  65. 'avatar' => Storage::url($v->publisher->avatar),
  66. 'name' => $v->publisher->name,
  67. 'content' => $v->content,
  68. 'created_at_text' => $v->created_at,
  69. ];
  70. $msgList [] = $arr;
  71. }
  72. $currentWorkorder = \App\Models\Workorder::find($workorderId);
  73. array_unshift($msgList, [
  74. 'type' => 'op',
  75. 'it_type' => 1,
  76. 'avatar' => Storage::url($currentWorkorder->publisher->avatar),
  77. 'name' => $currentWorkorder->publisher->name,
  78. 'content' => $currentWorkorder->content,
  79. 'created_at_text' => $currentWorkorder->created_at,
  80. ]);
  81. $data = [
  82. 'user_list' => $userList,
  83. 'msg_list' => $msgList,
  84. 'user' => Admin::user(),
  85. 'workorder' => [
  86. 'workorder_id' => $workorderId
  87. ],
  88. ];
  89. return $content
  90. ->header('工单')
  91. ->description('列表')
  92. ->body(admin_view('admin.pages.guide-index',$data));
  93. }
  94. ///**
  95. // * Make a grid builder.
  96. // *
  97. // * @return Grid
  98. // */
  99. //protected function grid()
  100. //{
  101. // return Grid::make(new Workorder(['publisher','point']), function (Grid $grid) {
  102. // $grid->model()
  103. // ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]])
  104. // ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[2]]);
  105. // $grid->column('id')->sortable();
  106. // $grid->column('title');
  107. // $grid->column('content_modal','内容')->modal('详情',function ($modal) {
  108. // $modal->xl();
  109. // return $this->content;
  110. // });
  111. // $grid->column('publisher_type')->using(DemandTraits::$polymorphic);
  112. // $grid->column('publisher.name','发布人');
  113. // $grid->column('point_type')->using(DemandTraits::$polymorphic);
  114. // $grid->column('point.name','接收人');
  115. // $grid->column('status')
  116. // ->using(WorkorderTraits::$stateText)
  117. // ->dot(
  118. // [
  119. // 1 => 'yellow',
  120. // 2 => 'danger',
  121. // 3 => 'success',
  122. // ]);
  123. // $grid->column('close_time');
  124. // $grid->column('created_at');
  125. // $grid->column('updated_at')->sortable();
  126. // $grid->disableActions();
  127. // $grid->filter(function (Grid\Filter $filter) {
  128. // $filter->equal('id');
  129. //
  130. // });
  131. // });
  132. //}
  133. //
  134. ///**
  135. // * Make a show builder.
  136. // *
  137. // * @param mixed $id
  138. // *
  139. // * @return Show
  140. // */
  141. //protected function detail($id)
  142. //{
  143. // return Show::make($id, new Workorder(), function (Show $show) {
  144. // $show->field('id');
  145. // $show->field('title');
  146. // $show->field('content');
  147. // $show->field('publisher_type');
  148. // $show->field('publisher_id');
  149. // $show->field('point_type');
  150. // $show->field('point_id');
  151. // $show->field('status');
  152. // $show->field('close_time');
  153. // $show->field('created_at');
  154. // $show->field('updated_at');
  155. // });
  156. //}
  157. /**
  158. * Make a form builder.
  159. *
  160. * @return Form
  161. */
  162. protected function form()
  163. {
  164. return Form::make(new Workorder(), function (Form $form) {
  165. $form->display('id');
  166. $form->text('title')->required();
  167. $form->textarea('content')->required();
  168. $form->select('point_type')
  169. ->options([
  170. 0 => '代理商',
  171. ])
  172. ->default(0)
  173. ->required();
  174. $form->select('point_id', '代理商')->options(function () {
  175. return Agent::query()->where('type',AgentType::CLUSTER)->pluck('name','id');
  176. })
  177. ->required();
  178. $form->hidden('publisher_type');
  179. $form->hidden('publisher_id');
  180. $form->saving(function (Form $form) {
  181. // 判断是否是新增操作
  182. if ($form->isCreating()) {
  183. $form->point_type = DemandTraits::$col[$form->point_type];
  184. //发布人身份
  185. $form->publisher_type = DemandTraits::$col[2];
  186. $form->publisher_id = Admin::user()->id;
  187. }
  188. });
  189. });
  190. }
  191. public function sendImage(Request $request)
  192. {
  193. $validator = Validator::make(request()->all(), [
  194. 'workorder_id' => 'required|int',
  195. ], [
  196. '*' => '参数异常',
  197. ]);
  198. if ($validator->fails()) {
  199. return $this->jsonFailValidated('数据不全:'.$validator->errors()->first());
  200. }
  201. $image = $request->file('image');
  202. if (empty($image) || !$image->isValid()) {
  203. return $this->error('您未上传任何文件');
  204. }
  205. $mime = $image->getMimeType();
  206. if (!in_array($mime, ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg'])) {
  207. return $this->error('上传图片格式错误');
  208. }
  209. $path = $request->image->store('public/images/workorder');
  210. $path = (Storage::url($path));
  211. $item = new WorkorderItem();
  212. $item->workorder_id = request('workorder_id',0);
  213. $item->content = $path;
  214. $item->type = 2;
  215. $item->publisher_type = DemandTraits::$col[2];
  216. $item->publisher_id = Admin::user()->id;
  217. $item->save();
  218. return $this->jsonSuccess($item);
  219. }
  220. public function sendText(Request $request)
  221. {
  222. $validator = Validator::make(request()->all(), [
  223. 'workorder_id' => 'required|int',
  224. 'content' => 'required',
  225. ], [
  226. '*' => '参数异常',
  227. ]);
  228. if ($validator->fails()) {
  229. return $this->jsonFailValidated('数据不全:'.$validator->errors()->first());
  230. }
  231. $item = new WorkorderItem();
  232. $item->workorder_id = request('workorder_id',0);
  233. $item->content = request('content','');
  234. $item->type = 1;
  235. $item->publisher_type = DemandTraits::$col[2];
  236. $item->publisher_id = Admin::user()->id;
  237. $item->save();
  238. return $this->jsonSuccess($item);
  239. }
  240. }