12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
- namespace app\controller\store\appointment;
-
- use app\controller\store\AuthController;
- use app\model\store\appointment\AppointmentModel;
-
- class Kanban extends AuthController
- {
-
- public function show()
- {
- $day = $this->request->param('day');
- if (empty($day)) return $this->fail('参数错误');
- if (false === strtotime($day . ' 00:00:00')) return $this->fail('参数错误');
- $store_id = $this->request->param('store_id/d', 0);
- if (empty($store_id)) {
- $where = [
- ['day', '=', $day]
- ];
- } else {
- $where = [
- ['store_id', '=', $store_id],
- ['day', '=', $day]
- ];
- }
-
- $appointment_model = new AppointmentModel();
- $total = $appointment_model->where($where)->group('technician_id')->count();
- $appointment_model = $appointment_model->with(['technician']);
- $order = ['count' => 'desc'];
- $field = 'technician_id,count(*) as count';
- $list = $appointment_model
- ->where($where)
- ->field($field)
- ->group('technician_id')
- ->order($order)
- ->select()
- ->toArray();
-
- $technician_ids = array_column($list, 'technician_id');
- $appointment_data = AppointmentModel::with(['technician', 'member'])->where([
- ['store_id', '=', $store_id],
- ['day', '=', $day],
- ['technician_id', 'in', $technician_ids]
- ])->select()->append(['status_means', 'operate_type_means', 'arrival_time_format', 'cancel_time_format', 'add_time_format'])->toArray();
-
- $technician_data = [];
- foreach ($appointment_data as $k => $v) {
- $technician_data[$v['technician_id']][] = $v;
- }
-
- foreach ($list as $k => $v) {
- $list[$k]['orders'] = $technician_data[$v['technician_id']];
- }
-
- $return = [
- 'total' => $total,
- 'list' => $list
- ];
- return $this->success($return);
- }
-
- }
|