|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
-
- namespace app\admin\controller;
-
- use app\BaseController;
-
- class Appoint extends BaseController
- {
-
- protected $noNeedLogin = [''];
- protected $noSize = ['*'];
- protected $noSecure = [//格式:'请求方式' => ['请求方法' => ['字段1','字段2'],],
- // 'post' => ['add' => ['data']]
- ];
-
- // public function read()
- // {
- // try {
- // $Appoint_model = new \app\admin\model\Appoint();
- // $result = $Appoint_model->read($_GET);
- // tojson(200, '请求成功', $result);
- // } catch (\Exception $e) {
- // tojson(10000, $e->getMessage());
- // }
- // }
-
- public function getStatusSelect()
- {
- try {
- $Appoint_model = new \app\admin\model\Appoint();
- $result = $Appoint_model->getStatusSelect();
- tojson(200, '请求成功', $result);
- } catch (\Exception $e) {
- tojson(10000, $e->getMessage());
- } catch (\Throwable $e) {
- tojson(10000, $e->getMessage());
- }
- }
-
- public function getScheduling()
- {
- try {
- $Appoint_model = new \app\admin\model\Appoint();
- $result = $Appoint_model->getScheduling($_GET);
- tojson(200, '请求成功', $result);
- } catch (\Exception $e) {
- tojson(10000, $e->getMessage());
- } catch (\Throwable $e) {
- tojson(10000, $e->getMessage());
- }
- }
-
- public function getAll()
- {
- try {
- $Appoint_model = new \app\admin\model\Appoint();
- $result = $Appoint_model->getAll($_GET, $this->request->page, $this->request->pageSize);
- tojson(200, '请求成功', $result);
- } catch (\Exception $e) {
- tojson(10000, $e->getMessage());
- } catch (\Throwable $e) {
- tojson(10000, $e->getMessage());
- }
- }
-
- public function save()
- {
- try {
- $Customer_model = new \app\admin\model\Customer();
- $check = $Customer_model->where('id', $_POST['customer_id'])->field('status')->find();
- if (empty($check)) {
- tojson(10000, '客户不存在');
- }
- if (in_array($check['status'], [6, 7, -1])) {
- tojson(10000, '此客户状态是无效或流失或已加入公海');
- }
- $District_model = new \app\admin\model\District();
- $check = $District_model->where('adcode', $_POST['city_id'])->value('adcode');
- if (empty($check)) {
- tojson(10000, '城市不存在');
- }
- $Hospital_model = new \app\admin\model\Hospital();
- $check = $Hospital_model->where('id', $_POST['hospital_id'])->field('is_appoint')->find();
- if (empty($check)) {
- tojson(10000, '医院不存在');
- }
- if ($check['is_appoint'] == 0) {
- tojson(10000, '此医院不支持预约');
- }
- $Appoint_model = new \app\admin\model\Appoint();
- $_POST['create_time'] = $_SERVER['REQUEST_TIME'];
- $Appoint_model->startTrans();
- $_POST['status'] = 1;
- $Appoint_model->save($_POST);
- //修改客户的status
- $Customer_model->where('id', $_POST['customer_id'])->update(['status' => 3]);
- $Appoint_model->commit();
- tojson(200, '添加成功');
- } catch (\Exception $e) {
- if (isset($Appoint_model)) {
- $Appoint_model->rollback();
- }
- tojson(10000, $e->getMessage());
- } catch (\Throwable $e) {
- if (isset($Appoint_model)) {
- $Appoint_model->rollback();
- }
- tojson(10000, $e->getMessage());
- }
- }
-
- public function update()
- {
- try {
- $Appoint_model = new \app\admin\model\Appoint();
- $check2 = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->field('status,is_returnvisit,customer_id')->find();
- if (!$check2) {
- tojson(10000, '记录不存在');
- }
- $Customer_model = new \app\admin\model\Customer();
- if (isset($this->param['customer_id']) && !empty($this->param['customer_id'])) {
- $check = $Customer_model->where('id', $this->param['customer_id'])->value('id');
- if (empty($check)) {
- tojson(10000, '客户不存在');
- }
- }
- if (isset($this->param['city_id']) && !empty($this->param['city_id'])) {
- $District_model = new \app\admin\model\District();
- $check = $District_model->where('adcode', $this->param['city_id'])->value('adcode');
- if (empty($check)) {
- tojson(10000, '城市不存在');
- }
- }
- if (isset($this->param['hospital_id']) && !empty($this->param['hospital_id'])) {
- $Hospital_model = new \app\admin\model\Hospital();
- $check = $Hospital_model->where('id', $this->param['hospital_id'])->value('id');
- if (empty($check)) {
- tojson(10000, '医院不存在');
- }
- }
- if (isset($this->param['status']) && $this->param['status'] == 3) {
- if ($check2['status'] == 4) {
- tojson(10000, '已成交不能取消');
- }
- if ($check2['status'] == 5) {
- tojson(10000, '未成交不能取消');
- }
- if (!isset($this->param['reason']) || empty($this->param['reason'])) {
- tojson(10000, '取消原因必填');
- }
- }
- if (isset($this->param['status']) && $this->param['status'] == 6) {//已改约
- if ($check2['status'] == 4) {
- tojson(10000, '已成交不能取消');
- }
- if ($check2['status'] == 5) {
- tojson(10000, '未成交不能取消');
- }
- }
- if (isset($this->param['status']) && $this->param['status'] == 4) {
- $validate = \think\Validate::make([
- 'is_deal' => ['require', 'number', 'in:1,2'],
- 'feedback' => ['require'],
- 'scene_zixun' => ['require'],
- 'visiting_doctor' => ['require'],
- ]);
- if (!$validate->check($this->param)) {
- tojson(10000, $validate->getError());
- }
- if (!in_array($check2['status'], [1, 6])) {
- tojson(10000, '预约状态不对');
- }
- if ($this->param['is_deal'] == 2) {//未成交
- $validate = \think\Validate::make([
- 'reason' => ['require'],
- ]);
- if (!$validate->check($this->param)) {
- tojson(10000, $validate->getError());
- }
- } else {
- $validate = \think\Validate::make([
- 'demand' => ['require'],
- 'collection' => ['require', 'number', 'in:1,2'],
- 'deal_money' => ['require', 'number'],
- 'collection_money' => ['require', 'number'],
- 'collection_time' => ['require', 'number'],
- ]);
- if (!$validate->check($this->param)) {
- tojson(10000, $validate->getError());
- }
- if ($this->param['collection_money'] > $this->param['deal_money']) {
- tojson(10000, '收款金额不能大于成交金额');
- }
- }
- }
- if (isset($this->param['satisfaction']) && !empty($this->param['satisfaction'])) {
- $validate = \think\Validate::make([
- 'satisfaction' => ['require'],
- 'equity' => ['require'],
- 'price' => ['require'],
- 'programme' => ['require'],
- 'concerns' => ['require'],
- 'is_complaint' => ['require', 'number', 'in:0,1'],
- ]);
- if (!$validate->check($this->param)) {
- tojson(10000, $validate->getError());
- }
- if (!in_array($check2['status'], [4, 5])) {
- tojson(10000, '预约状态不对,不能回访');
- }
- if ($check2['is_returnvisit'] != 1) {
- tojson(10000, '此数据已设置不回访');
- }
- if ($this->param['is_complaint'] == 1) {
- if (!isset($this->param['complaint']) || empty($this->param['complaint'])) {
- tojson(10000, '投诉内容不能为空');
- }
- }
- $this->param['return_visit'] = 1;
- unset($this->param['appoint_time']);
- }
- $this->param['update_time'] = $_SERVER['REQUEST_TIME'];
- $Appoint_model->startTrans();
- if (isset($this->param['status']) && $this->param['status'] == 4) {
- //修改客户的status
- if ($this->param['is_deal'] == 2) {//未成交
- $Customer_status = 5;
- $Appoint_data = ['status' => $Customer_status, 'is_deal' => $this->param['is_deal'], 'reason' => $this->param['reason'], 'update_time' => $_SERVER['REQUEST_TIME']];
- } else {
- $Customer_status = 4;
- $Appoint_data = ['status' => $Customer_status, 'is_deal' => $this->param['is_deal'], 'collection' => $this->param['collection'], 'update_time' => $_SERVER['REQUEST_TIME']];
- //添加收款明细记录
- $Collection_data = $this->param;
- $Collection_data['appoint_id'] = $this->param['id'];
- $Collection_data['customer_id'] = $check2['customer_id'];
- unset($Collection_data['id']);
- $Collection_model = new \app\admin\model\Collection();
- $Collection_model->save($Collection_data);
- }
- $Customer_model->save(['status' => $Customer_status, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
- $Appoint_model->save($Appoint_data, [$Appoint_model->getPk() => $this->param[$Appoint_model->getPk()]]);
- } else {
- if (isset($this->param['status']) && $this->param['status'] == 3) {
- $Customer_model->save(['status' => 2, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
- }
- if (isset($this->param['status']) && $this->param['status'] == 6) {
- $Customer_model->save(['status' => 3, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
- }
- $Appoint_model->save($this->param, [$Appoint_model->getPk() => $this->param[$Appoint_model->getPk()]]);
- }
- $Appoint_model->commit();
- tojson(200, '修改成功');
- } catch (\Exception $e) {
- if (isset($Appoint_model)) {
- $Appoint_model->rollback();
- }
- tojson(10000, $e->getMessage());
- } catch (\Throwable $e) {
- if (isset($Appoint_model)) {
- $Appoint_model->rollback();
- }
- tojson(10000, $e->getMessage());
- }
- }
-
- // public function delete()
- // {
- // try {
- // $Appoint_model = new \app\admin\model\Appoint();
- // $check = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->value($Appoint_model->getPk());
- // if (!$check) {
- // tojson(10000, '记录不存在');
- // }
- // $result = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->delete();
- // if ($result) {
- // tojson(200, '删除成功');
- // } else {
- // tojson(10000, '删除失败');
- // }
- // } catch (\Exception $e) {
- // tojson(10000, $e->getMessage());
- // }
- // }
-
- }
|