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.

Kanban.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\controller\store\appointment;
  3. use app\controller\store\AuthController;
  4. use app\model\store\appointment\AppointmentModel;
  5. class Kanban extends AuthController
  6. {
  7. public function show()
  8. {
  9. $day = $this->request->param('day');
  10. if (empty($day)) return $this->fail('参数错误');
  11. if (false === strtotime($day . ' 00:00:00')) return $this->fail('参数错误');
  12. $store_id = $this->request->param('store_id/d', 0);
  13. if (empty($store_id)) {
  14. $where = [
  15. ['day', '=', $day]
  16. ];
  17. } else {
  18. $where = [
  19. ['store_id', '=', $store_id],
  20. ['day', '=', $day]
  21. ];
  22. }
  23. $appointment_model = new AppointmentModel();
  24. $total = $appointment_model->where($where)->group('technician_id')->count();
  25. $appointment_model = $appointment_model->with(['technician']);
  26. $order = ['count' => 'desc'];
  27. $field = 'technician_id,count(*) as count';
  28. $list = $appointment_model
  29. ->where($where)
  30. ->field($field)
  31. ->group('technician_id')
  32. ->order($order)
  33. ->select()
  34. ->toArray();
  35. $technician_ids = array_column($list, 'technician_id');
  36. $appointment_data = AppointmentModel::with(['technician', 'member'])->where([
  37. ['store_id', '=', $store_id],
  38. ['day', '=', $day],
  39. ['technician_id', 'in', $technician_ids]
  40. ])->select()->append(['status_means', 'operate_type_means', 'arrival_time_format', 'cancel_time_format', 'add_time_format'])->toArray();
  41. $technician_data = [];
  42. foreach ($appointment_data as $k => $v) {
  43. $technician_data[$v['technician_id']][] = $v;
  44. }
  45. foreach ($list as $k => $v) {
  46. $list[$k]['orders'] = $technician_data[$v['technician_id']];
  47. }
  48. $return = [
  49. 'total' => $total,
  50. 'list' => $list
  51. ];
  52. return $this->success($return);
  53. }
  54. }