海南旅游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.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
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminSupplier\Controllers;
  3. use App\AdminAgent\Repositories\Workorder;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Agent;
  6. use App\Models\AgentProductItem;
  7. use App\Models\Guide;
  8. use App\Models\OrderProductItem;
  9. use App\Models\Supplier;
  10. use App\Models\WorkorderItem;
  11. use App\Traits\DemandTraits;
  12. use App\Traits\WorkorderTraits;
  13. use Dcat\Admin\Admin;
  14. use Dcat\Admin\Form;
  15. use Dcat\Admin\Grid;
  16. use Dcat\Admin\Layout\Content;
  17. use Dcat\Admin\Show;
  18. use Dcat\Admin\Http\Controllers\AdminController;
  19. use Illuminate\Http\Request;
  20. use App\Traits\ResponseHelper;
  21. use Illuminate\Support\Facades\Storage;
  22. use Illuminate\Support\Facades\Validator;
  23. class WorkorderController extends AdminController
  24. {
  25. use ResponseHelper;
  26. public function index(Content $content)
  27. {
  28. $workorderId = \request('workorder_id',0);
  29. $userList = $msgList = [];
  30. $workorder = \App\Models\Workorder::query()
  31. ->with(['point','publisher'])
  32. ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]])
  33. ->orWhere(function ($query) {
  34. $query->where('point_id',Admin::user()->id)
  35. ->where('point_type',DemandTraits::$col[1]);
  36. })
  37. ->orderByDesc('updated_at')
  38. ->get();
  39. foreach ($workorder as $v) {
  40. $item = WorkorderItem::query()->where('workorder_id',$v->id)->orderByDesc('updated_at')->first();
  41. $arr = [
  42. 'workorder_id' => $v->id,
  43. 'unread' => true,
  44. 'avatar' => Storage::url($v->publisher_type == DemandTraits::$col[1] ? $v->point->avatar : $v->publisher->avatar),
  45. 'name' => $v->publisher_type == DemandTraits::$col[1] ? $v->point->name : $v->publisher->name,
  46. 'content' => $v->title,
  47. 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '',
  48. 'last_message_time' => $item->created_at ?? '',
  49. ];
  50. $userList [] = $arr;
  51. }
  52. $workorderItem = WorkorderItem::query()
  53. ->with(['publisher'])
  54. ->where('workorder_id',$workorderId)
  55. ->get();
  56. foreach ($workorderItem as $v) {
  57. $arr = [
  58. 'type' => $v->publisher_type == DemandTraits::$col[1] ? 'my' : 'op',
  59. 'it_type' => $v->type,
  60. 'avatar' => Storage::url($v->publisher->avatar),
  61. 'name' => $v->publisher->name,
  62. 'content' => $v->content,
  63. 'created_at_text' => $v->created_at,
  64. ];
  65. $msgList [] = $arr;
  66. }
  67. $currentWorkorder = \App\Models\Workorder::find($workorderId);
  68. array_unshift($msgList, [
  69. 'type' => 'op',
  70. 'it_type' => 1,
  71. 'avatar' => Storage::url($currentWorkorder->publisher->avatar),
  72. 'name' => $currentWorkorder->publisher->name,
  73. 'content' => $currentWorkorder->content,
  74. 'created_at_text' => $currentWorkorder->created_at,
  75. ]);
  76. $data = [
  77. 'user_list' => $userList,
  78. 'msg_list' => $msgList,
  79. 'user' => Admin::user(),
  80. 'workorder' => [
  81. 'workorder_id' => $workorderId
  82. ],
  83. ];
  84. return $content
  85. ->header('工单')
  86. ->description('列表')
  87. ->body(admin_view('admin.pages.supplier-index',$data));
  88. }
  89. ///**
  90. // * Make a grid builder.
  91. // *
  92. // * @return Grid
  93. // */
  94. //protected function grid()
  95. //{
  96. // return Grid::make(new Workorder(['publisher','point']), function (Grid $grid) {
  97. // $grid->model()
  98. // ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]])
  99. // ->orWhere(['point_id' => Admin::user()->id,'point_type' => DemandTraits::$col[1]]);
  100. // $grid->column('id')->sortable();
  101. // $grid->column('title');
  102. // $grid->column('content_modal','内容')->modal('详情',function ($modal) {
  103. // $modal->xl();
  104. // return $this->content;
  105. // });
  106. // $grid->column('publisher_type')->using(DemandTraits::$polymorphic);
  107. // $grid->column('publisher.name','发布人');
  108. // $grid->column('point_type')->using(DemandTraits::$polymorphic);
  109. // $grid->column('point.name','接收人');
  110. // $grid->column('status')
  111. // ->using(WorkorderTraits::$stateText)
  112. // ->dot(
  113. // [
  114. // 1 => 'yellow',
  115. // 2 => 'danger',
  116. // 3 => 'success',
  117. // ]);
  118. // $grid->column('close_time');
  119. // $grid->column('created_at');
  120. // $grid->column('updated_at')->sortable();
  121. // $grid->disableActions();
  122. // $grid->filter(function (Grid\Filter $filter) {
  123. // $filter->equal('id');
  124. //
  125. // });
  126. // });
  127. //}
  128. //
  129. ///**
  130. // * Make a show builder.
  131. // *
  132. // * @param mixed $id
  133. // *
  134. // * @return Show
  135. // */
  136. //protected function detail($id)
  137. //{
  138. // return Show::make($id, new Workorder(), function (Show $show) {
  139. // $show->field('id');
  140. // $show->field('title');
  141. // $show->field('content');
  142. // $show->field('publisher_type');
  143. // $show->field('publisher_id');
  144. // $show->field('point_type');
  145. // $show->field('point_id');
  146. // $show->field('status');
  147. // $show->field('close_time');
  148. // $show->field('created_at');
  149. // $show->field('updated_at');
  150. // });
  151. //}
  152. /**
  153. * Make a form builder.
  154. *
  155. * @return Form
  156. */
  157. protected function form()
  158. {
  159. return Form::make(new Workorder(), function (Form $form) {
  160. $form->display('id');
  161. $form->text('title')->required();
  162. $form->textarea('content')->required();
  163. $form->select('point_type')
  164. ->options([
  165. 0 => '代理商',
  166. ])
  167. ->default(1)
  168. ->required();
  169. $form->select('point_id', '代理商')->options(function () {
  170. $agentIds = AgentProductItem::query()->where('supplier_id',Admin::user()->id)->distinct()->pluck('agent_id');
  171. return Agent::query()->whereIn('id',$agentIds)->pluck('name','id');
  172. })->required();
  173. $form->hidden('publisher_type');
  174. $form->hidden('publisher_id');
  175. $form->saving(function (Form $form) {
  176. // 判断是否是新增操作
  177. if ($form->isCreating()) {
  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[1];
  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[1];
  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[1];
  233. $item->publisher_id = Admin::user()->id;
  234. $item->save();
  235. return $this->jsonSuccess($item);
  236. }
  237. }