|
@@ -4,12 +4,13 @@ namespace app\admin\controller;
|
|
|
|
|
|
use app\admin\controller\base\Permissions;
|
|
|
use app\common\model\Appointment as appointmentModel;
|
|
|
+use time\DateHelper;
|
|
|
|
|
|
class Appointment extends Permissions
|
|
|
{
|
|
|
private function getModel()
|
|
|
{
|
|
|
- return new \app\common\model\Appointment();
|
|
|
+ return new appointmentModel();
|
|
|
}
|
|
|
|
|
|
public function index()
|
|
@@ -20,14 +21,14 @@ class Appointment extends Permissions
|
|
|
$where = [
|
|
|
'provider_id' => $pid
|
|
|
];
|
|
|
- if (!empty($post["title"])) {
|
|
|
- $where["title"] = ['like', '%' . $post["title"] . '%'];
|
|
|
+ if (isset($post['ids']) and !empty($post['ids'])) {
|
|
|
+ $where['id'] = ['in', $post['ids']];
|
|
|
}
|
|
|
- if (isset($post["start_time"]) and !empty($post["start_time"])) {
|
|
|
- $timerang = explode(' - ', $post["start_time"]);
|
|
|
+ if (isset($post["daytime"]) and !empty($post["daytime"])) {
|
|
|
+ $timerang = explode(' - ', $post["daytime"]);
|
|
|
$min_time = strtotime($timerang[0]);
|
|
|
$max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
|
|
|
- $where["start_time"] = [['>=', $min_time], ['<=', $max_time]];
|
|
|
+ $where["daytime"] = [['>=', $min_time], ['<=', $max_time]];
|
|
|
}
|
|
|
if (isset($post["create_time"]) and !empty($post["create_time"])) {
|
|
|
$timerang = explode(' - ', $post["create_time"]);
|
|
@@ -38,8 +39,11 @@ class Appointment extends Permissions
|
|
|
|
|
|
$model = $this->getModel();
|
|
|
$count = $model->where($where)->count();
|
|
|
- $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
|
|
|
-
|
|
|
+ $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('daytime desc')->select();
|
|
|
+ foreach ($data as $key => $value) {
|
|
|
+ $value['specialist_name'] = $value->specialist->name;
|
|
|
+ $data[$key] = $value;
|
|
|
+ }
|
|
|
return array('code' => 0, 'count' => $count, 'data' => $data);
|
|
|
} else {
|
|
|
return $this->fetch();
|
|
@@ -53,7 +57,6 @@ class Appointment extends Permissions
|
|
|
$pid = $this->request->param('pid', 0, 'intval');
|
|
|
$this->assign('pid', $pid);
|
|
|
|
|
|
- $model = $this->getModel();
|
|
|
$post = $this->request->post();
|
|
|
$post['provider_id'] = $pid;
|
|
|
|
|
@@ -86,7 +89,7 @@ class Appointment extends Permissions
|
|
|
$validate = new \think\Validate([
|
|
|
['title|服务名称', 'max:50'],
|
|
|
['provider_id', 'require|number'],
|
|
|
-// ['phone|咨询电话', 'max:50'],
|
|
|
+ ['phone|咨询电话', 'max:50'],
|
|
|
['start_time', 'number', '排号日期格式不对'],
|
|
|
['end_time', 'number', '排号日期格式不对'],
|
|
|
['morning_num|上午放号个数', 'number'],
|
|
@@ -108,64 +111,55 @@ class Appointment extends Permissions
|
|
|
|
|
|
if ($id > 0) {
|
|
|
//修改
|
|
|
-// $data = $model->where('id', $id)->find();
|
|
|
-// if (empty($data)) {
|
|
|
-// $this->error('id不正确');
|
|
|
-// }
|
|
|
-// if ($this->request->isPost()) {
|
|
|
-// if (false == $model->allowField(true)->save($post, ['id' => $id])) {
|
|
|
- $this->error('修改失败');
|
|
|
-// } else {
|
|
|
-// $this->success('修改成功', 'index', ['pid' => $pid]);
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// $this->assign('data', $data);
|
|
|
-// return $this->fetch();
|
|
|
-// }
|
|
|
} else {
|
|
|
//新增
|
|
|
if ($this->request->isPost()) {
|
|
|
-
|
|
|
- //判断是否存在排号
|
|
|
- $exits = (new \app\common\model\AppointmentTicket())->where(['provider_id' => $pid, 'appointment_daytime' => [['>=', $post['start_time']], ['<=', $post['end_time']]]])->count();
|
|
|
+ //判断是否时间跨度重叠
|
|
|
+ $exits = $this->getModel()->where(['provider_id' => $pid, 'daytime' => [['>=', $post['start_time']], ['<=', $post['end_time']]]])->count();
|
|
|
if ($exits > 0) {
|
|
|
$this->error('该时间跨度内,已存在排号,请重新选择时间');
|
|
|
}
|
|
|
-
|
|
|
- if (false == $model->allowField(true)->save($post)) {
|
|
|
- $this->error('添加失败');
|
|
|
- } else {
|
|
|
- //生成号源
|
|
|
- appointmentModel::createTicketFromAllAppointment();
|
|
|
- $this->success('添加成功', 'index', ['pid' => $pid]);
|
|
|
+ //生成号源
|
|
|
+ $daylist = DateHelper::dateTimeList(date('Y-m-d', $post['start_time']), date('Y-m-d', $post['end_time']), true);
|
|
|
+ if (count($daylist) == 2 && end($daylist) == current($daylist)) {
|
|
|
+ array_pop($daylist);
|
|
|
}
|
|
|
+ $addressId = (new \app\common\model\Specialist())->where('id', $post['provider_id'])->value('address_id');
|
|
|
+ foreach ($daylist as $datetime) {
|
|
|
+ $post['daytime'] = strtotime($datetime);
|
|
|
+ $post['address_id'] = $addressId;
|
|
|
+ if (false == $this->getModel()->allowField(true)->save($post)) {
|
|
|
+ $this->error('添加失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->success('添加成功', 'index', ['pid' => $pid]);
|
|
|
} else {
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// public function delete()
|
|
|
-// {
|
|
|
-// if ($this->request->isAjax()) {
|
|
|
-// $id = $this->request->param('id', 0, 'intval');
|
|
|
-// if (false == $this->getModel()->where('id', $id)->delete()) {
|
|
|
-// $this->error('删除失败');
|
|
|
-// } else {
|
|
|
-// $this->success('删除成功', 'index');
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// public function deletes()
|
|
|
-// {
|
|
|
-// if ($this->request->isAjax()) {
|
|
|
-// $post = $this->request->param();
|
|
|
-// $ids = $post['ids'];
|
|
|
-// if ($this->getModel()->where('id', 'in', $ids)->delete()) {
|
|
|
-// $this->success('删除成功');
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ public function delete()
|
|
|
+ {
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ $id = $this->request->param('id', 0, 'intval');
|
|
|
+ if (false == $this->getModel()->where('id', $id)->delete()) {
|
|
|
+ $this->error('删除失败');
|
|
|
+ } else {
|
|
|
+ $this->success('删除成功', 'index');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deletes()
|
|
|
+ {
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ $post = $this->request->param();
|
|
|
+ $ids = $post['ids'];
|
|
|
+ if ($this->getModel()->where('id', 'in', $ids)->delete()) {
|
|
|
+ $this->success('删除成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|