PersonalTalentsLogController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Admin\Controllers\PersonalTalents;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\PersonalTalents;
  5. use App\Models\PersonalTalentsLog;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. class PersonalTalentsLogController extends Controller
  12. {
  13. protected $role_id_1 = 30;
  14. use HasResourceActions;
  15. /**
  16. * Index interface.
  17. *
  18. * @param Content $content
  19. * @return Content
  20. */
  21. public function index(Content $content)
  22. {
  23. return $content
  24. ->header('进度列表')
  25. ->description('')
  26. ->body($this->grid());
  27. }
  28. /**
  29. * Show interface.
  30. *
  31. * @param mixed $id
  32. * @param Content $content
  33. * @return Content
  34. */
  35. public function show($id, Content $content)
  36. {
  37. }
  38. /**
  39. * Edit interface.
  40. *
  41. * @param mixed $id
  42. * @param Content $content
  43. * @return Content
  44. */
  45. public function edit($id, Content $content)
  46. {
  47. return $content
  48. ->header('进度列表')
  49. ->description('编辑')
  50. ->body($this->form()->edit($id));
  51. }
  52. /**
  53. * Create interface.
  54. *
  55. * @param Content $content
  56. * @return Content
  57. */
  58. public function create(Content $content)
  59. {
  60. return $content
  61. ->header('进度列表')
  62. ->description('创建')
  63. ->body($this->form());
  64. }
  65. /**
  66. * Make a grid builder.
  67. *
  68. * @return Grid
  69. */
  70. protected function grid()
  71. {
  72. $id = request()->id;
  73. if(empty($id)){
  74. admin_toastr('请选择人才!', 'error');
  75. return back();
  76. }
  77. $grid = new Grid(new PersonalTalentsLog());
  78. $grid->model()->where('talents_id', $id)->where('log_class', 5)->orderBy('id', 'desc');
  79. $grid->id('ID');
  80. $grid->log_time('操作时间')->display(function ($log_time) {
  81. return date('Y-m-d',$log_time) ;
  82. });
  83. $grid->content('日志内容');
  84. $grid->auth_man('操作人员');
  85. $grid->actions(function ($actions) use ($grid) {
  86. $actions->disableView();
  87. });
  88. $grid->filter(function ($filter) {
  89. $filter->like('content', '内容');
  90. });
  91. return $grid;
  92. }
  93. /**
  94. * Make a form builder.
  95. *
  96. * @return Form
  97. */
  98. protected function form()
  99. {
  100. $id = request()->id;
  101. $form = new Form(new PersonalTalentsLog);
  102. $form->date('log_time',
  103. '处理时间')->format('YYYY-MM-DD')->default(date('Y-m-s', time()))->setMustMark();
  104. $form->textarea('inplan_content', '进度内容')->attribute(['maxlength'=>1000])->rules(['required'], ['required'=>"请填写进度内容"])->setMustMark();
  105. $form->hidden('ids')->default($id);
  106. return $form;
  107. }
  108. public function personalTalentsLogList(Content $content)
  109. {
  110. return $content
  111. ->header('进度列表')
  112. ->description('进度列表')
  113. ->body($this->grid());
  114. }
  115. public function store()
  116. {
  117. $id = request()->ids;
  118. $log_time = request()->log_time;
  119. if (empty($log_time)) {
  120. admin_toastr('请选择日期', 'error');
  121. return back();
  122. }
  123. $inplan_content = request()->inplan_content;
  124. if (empty($inplan_content)) {
  125. admin_toastr('请填入进度内容', 'error');
  126. return back();
  127. }
  128. $role_arr = [];
  129. if (!empty(Admin::user()->roles)) {
  130. foreach (Admin::user()->roles as $key => $val) {
  131. $role_arr[] = $val->id;
  132. }
  133. }
  134. if (!in_array($this->role_id_1, $role_arr)) {
  135. admin_toastr('人才客服才可以操作', 'error');
  136. return back();
  137. }
  138. //判断是否为此人才的所属客服在操作
  139. $adminid = PersonalTalents::where(array('id' => $id))->value('admin_id');
  140. if ($adminid != Admin::user()->id) {
  141. admin_toastr('此人才的客服才可以操作', 'error');
  142. return back();
  143. }
  144. try {
  145. $log['talents_id'] = $id;
  146. $log['content'] = $inplan_content;
  147. $log['log_time'] = strtotime($log_time);
  148. $log['log_class'] = 5;//日志类型
  149. $log['auth_man'] = Admin::user()->username;
  150. PersonalTalentsLog::create($log);
  151. admin_toastr('操作成功', 'success');
  152. } catch (\Exception $e) {
  153. admin_toastr('操作失败', 'error');
  154. }
  155. return redirect(admin_base_path("personalTalents/personalTalentsLog/list/".request()->ids));
  156. }
  157. }