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

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