123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\admin\controller;
- use app\admin\controller\base\Permissions;
- use think\Db;
- class AppointmentTicket extends Permissions
- {
- private function getModel()
- {
- return new \app\common\model\AppointmentTicket();
- }
- public function index()
- {
- $pid = $this->request->param('pid', 0, 'intval');
- if ($this->request->isAjax()) {
- $post = $this->request->param();
- $where = [
- 'provider_id' => $pid
- ];
- if (isset($post['ids']) and !empty($post['ids'])) {
- $where['id'] = ['in', $post['ids']];
- }
- if (isset($post["appointment_id"]) and "" != $post["appointment_id"]) {
- $where["appointment_id"] = $post["appointment_id"];
- }
- if (isset($post["appointment_daytime"]) and !empty($post["appointment_daytime"])) {
- $timerang = explode(' - ', $post["appointment_daytime"]);
- $min_time = strtotime($timerang[0]);
- $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
- $where["appointment_daytime"] = [['>=', $min_time], ['<=', $max_time]];
- }
- if (isset($post["provider_id"]) and "" != $post["provider_id"]) {
- $where["provider_id"] = $post["provider_id"];
- }
- if (isset($post["address_id"]) and "" != $post["address_id"]) {
- $where["address_id"] = $post["address_id"];
- }
- if (isset($post["morning_use"]) and "" != $post["morning_use"]) {
- $where["morning_use"] = $post["morning_use"];
- }
- if (isset($post["afternoon_use"]) and "" != $post["afternoon_use"]) {
- $where["afternoon_use"] = $post["afternoon_use"];
- }
- if (isset($post["night_use"]) and "" != $post["night_use"]) {
- $where["night_use"] = $post["night_use"];
- }
- $model = $this->getModel();
- $count = $model->where($where)->count();
- $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('appointment_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();
- }
- }
- public function publish()
- {
- $id = $this->request->param('id', 0, 'intval');
- $model = $this->getModel();
- $post = $this->request->post();
- if ($this->request->isPost()) {
- if (isset($post['appointment_daytime']) && !empty($post['appointment_daytime'])) {
- $post['appointment_daytime'] = strtotime($post['appointment_daytime']);
- }
- //验证
- $validate = new \think\Validate([
- ['appointment_id|放号配置', 'require|number'],
- ['appointment_daytime|排号日期', 'require|number'],
- ['provider_id|服务人id', 'require|number'],
- ['address_id|地址id', 'number'],
- ['morning_use|上午报名个数', 'number'],
- ['afternoon_use|中午报名个数', 'number'],
- ['night_use|晚上报名个数', 'number'],
- ]);
- if (!$validate->check($post)) {
- $this->error('提交失败:' . $validate->getError());
- }
- }
- 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('修改成功');
- }
- } else {
- $this->assign('data', $data);
- return $this->fetch();
- }
- } else {
- }
- }
- 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('删除成功');
- }
- }
- }
- }
|