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

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