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

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