口腔客户管理系统
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.

Appoint.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. class Appoint extends BaseController
  5. {
  6. protected $noNeedLogin = [''];
  7. protected $noSize = ['*'];
  8. protected $noSecure = [//格式:'请求方式' => ['请求方法' => ['字段1','字段2'],],
  9. // 'post' => ['add' => ['data']]
  10. ];
  11. // public function read()
  12. // {
  13. // try {
  14. // $Appoint_model = new \app\admin\model\Appoint();
  15. // $result = $Appoint_model->read($_GET);
  16. // tojson(200, '请求成功', $result);
  17. // } catch (\Exception $e) {
  18. // tojson(10000, $e->getMessage());
  19. // }
  20. // }
  21. public function getStatusSelect()
  22. {
  23. try {
  24. $Appoint_model = new \app\admin\model\Appoint();
  25. $result = $Appoint_model->getStatusSelect();
  26. tojson(200, '请求成功', $result);
  27. } catch (\Exception $e) {
  28. tojson(10000, $e->getMessage());
  29. } catch (\Throwable $e) {
  30. tojson(10000, $e->getMessage());
  31. }
  32. }
  33. public function getScheduling()
  34. {
  35. try {
  36. $Appoint_model = new \app\admin\model\Appoint();
  37. $result = $Appoint_model->getScheduling($_GET);
  38. tojson(200, '请求成功', $result);
  39. } catch (\Exception $e) {
  40. tojson(10000, $e->getMessage());
  41. } catch (\Throwable $e) {
  42. tojson(10000, $e->getMessage());
  43. }
  44. }
  45. public function getAll()
  46. {
  47. try {
  48. $Appoint_model = new \app\admin\model\Appoint();
  49. $result = $Appoint_model->getAll($_GET, $this->request->page, $this->request->pageSize);
  50. tojson(200, '请求成功', $result);
  51. } catch (\Exception $e) {
  52. tojson(10000, $e->getMessage());
  53. } catch (\Throwable $e) {
  54. tojson(10000, $e->getMessage());
  55. }
  56. }
  57. public function save()
  58. {
  59. try {
  60. $Customer_model = new \app\admin\model\Customer();
  61. $check = $Customer_model->where('id', $_POST['customer_id'])->field('status')->find();
  62. if (empty($check)) {
  63. tojson(10000, '客户不存在');
  64. }
  65. if (in_array($check['status'], [6, 7, -1])) {
  66. tojson(10000, '此客户状态是无效或流失或已加入公海');
  67. }
  68. $District_model = new \app\admin\model\District();
  69. $check = $District_model->where('adcode', $_POST['city_id'])->value('adcode');
  70. if (empty($check)) {
  71. tojson(10000, '城市不存在');
  72. }
  73. $Hospital_model = new \app\admin\model\Hospital();
  74. $check = $Hospital_model->where('id', $_POST['hospital_id'])->field('is_appoint')->find();
  75. if (empty($check)) {
  76. tojson(10000, '医院不存在');
  77. }
  78. if ($check['is_appoint'] == 0) {
  79. tojson(10000, '此医院不支持预约');
  80. }
  81. $Appoint_model = new \app\admin\model\Appoint();
  82. $_POST['create_time'] = $_SERVER['REQUEST_TIME'];
  83. $Appoint_model->startTrans();
  84. $_POST['status'] = 1;
  85. $Appoint_model->save($_POST);
  86. //修改客户的status
  87. $Customer_model->where('id', $_POST['customer_id'])->update(['status' => 3]);
  88. $Appoint_model->commit();
  89. tojson(200, '添加成功');
  90. } catch (\Exception $e) {
  91. if (isset($Appoint_model)) {
  92. $Appoint_model->rollback();
  93. }
  94. tojson(10000, $e->getMessage());
  95. } catch (\Throwable $e) {
  96. if (isset($Appoint_model)) {
  97. $Appoint_model->rollback();
  98. }
  99. tojson(10000, $e->getMessage());
  100. }
  101. }
  102. public function update()
  103. {
  104. try {
  105. $Appoint_model = new \app\admin\model\Appoint();
  106. $check2 = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->field('status,is_returnvisit,customer_id')->find();
  107. if (!$check2) {
  108. tojson(10000, '记录不存在');
  109. }
  110. $Customer_model = new \app\admin\model\Customer();
  111. if (isset($this->param['customer_id']) && !empty($this->param['customer_id'])) {
  112. $check = $Customer_model->where('id', $this->param['customer_id'])->value('id');
  113. if (empty($check)) {
  114. tojson(10000, '客户不存在');
  115. }
  116. }
  117. if (isset($this->param['city_id']) && !empty($this->param['city_id'])) {
  118. $District_model = new \app\admin\model\District();
  119. $check = $District_model->where('adcode', $this->param['city_id'])->value('adcode');
  120. if (empty($check)) {
  121. tojson(10000, '城市不存在');
  122. }
  123. }
  124. if (isset($this->param['hospital_id']) && !empty($this->param['hospital_id'])) {
  125. $Hospital_model = new \app\admin\model\Hospital();
  126. $check = $Hospital_model->where('id', $this->param['hospital_id'])->value('id');
  127. if (empty($check)) {
  128. tojson(10000, '医院不存在');
  129. }
  130. }
  131. if (isset($this->param['status']) && $this->param['status'] == 3) {
  132. if ($check2['status'] == 4) {
  133. tojson(10000, '已成交不能取消');
  134. }
  135. if ($check2['status'] == 5) {
  136. tojson(10000, '未成交不能取消');
  137. }
  138. if (!isset($this->param['reason']) || empty($this->param['reason'])) {
  139. tojson(10000, '取消原因必填');
  140. }
  141. }
  142. if (isset($this->param['status']) && $this->param['status'] == 6) {//已改约
  143. if ($check2['status'] == 4) {
  144. tojson(10000, '已成交不能取消');
  145. }
  146. if ($check2['status'] == 5) {
  147. tojson(10000, '未成交不能取消');
  148. }
  149. }
  150. if (isset($this->param['status']) && $this->param['status'] == 4) {
  151. $validate = \think\Validate::make([
  152. 'is_deal' => ['require', 'number', 'in:1,2'],
  153. 'feedback' => ['require'],
  154. 'scene_zixun' => ['require'],
  155. 'visiting_doctor' => ['require'],
  156. ]);
  157. if (!$validate->check($this->param)) {
  158. tojson(10000, $validate->getError());
  159. }
  160. if (!in_array($check2['status'], [1, 6])) {
  161. tojson(10000, '预约状态不对');
  162. }
  163. if ($this->param['is_deal'] == 2) {//未成交
  164. $validate = \think\Validate::make([
  165. 'reason' => ['require'],
  166. ]);
  167. if (!$validate->check($this->param)) {
  168. tojson(10000, $validate->getError());
  169. }
  170. } else {
  171. $validate = \think\Validate::make([
  172. 'demand' => ['require'],
  173. 'collection' => ['require', 'number', 'in:1,2'],
  174. 'deal_money' => ['require', 'number'],
  175. 'collection_money' => ['require', 'number'],
  176. 'collection_time' => ['require', 'number'],
  177. ]);
  178. if (!$validate->check($this->param)) {
  179. tojson(10000, $validate->getError());
  180. }
  181. if ($this->param['collection_money'] > $this->param['deal_money']) {
  182. tojson(10000, '收款金额不能大于成交金额');
  183. }
  184. }
  185. }
  186. if (isset($this->param['satisfaction']) && !empty($this->param['satisfaction'])) {
  187. $validate = \think\Validate::make([
  188. 'satisfaction' => ['require'],
  189. 'equity' => ['require'],
  190. 'price' => ['require'],
  191. 'programme' => ['require'],
  192. 'concerns' => ['require'],
  193. 'is_complaint' => ['require', 'number', 'in:0,1'],
  194. ]);
  195. if (!$validate->check($this->param)) {
  196. tojson(10000, $validate->getError());
  197. }
  198. if (!in_array($check2['status'], [4, 5])) {
  199. tojson(10000, '预约状态不对,不能回访');
  200. }
  201. if ($check2['is_returnvisit'] != 1) {
  202. tojson(10000, '此数据已设置不回访');
  203. }
  204. if ($this->param['is_complaint'] == 1) {
  205. if (!isset($this->param['complaint']) || empty($this->param['complaint'])) {
  206. tojson(10000, '投诉内容不能为空');
  207. }
  208. }
  209. $this->param['return_visit'] = 1;
  210. unset($this->param['appoint_time']);
  211. }
  212. $this->param['update_time'] = $_SERVER['REQUEST_TIME'];
  213. $Appoint_model->startTrans();
  214. if (isset($this->param['status']) && $this->param['status'] == 4) {
  215. //修改客户的status
  216. if ($this->param['is_deal'] == 2) {//未成交
  217. $Customer_status = 5;
  218. $Appoint_data = ['status' => $Customer_status, 'is_deal' => $this->param['is_deal'], 'reason' => $this->param['reason'], 'update_time' => $_SERVER['REQUEST_TIME']];
  219. } else {
  220. $Customer_status = 4;
  221. $Appoint_data = ['status' => $Customer_status, 'is_deal' => $this->param['is_deal'], 'collection' => $this->param['collection'], 'update_time' => $_SERVER['REQUEST_TIME']];
  222. //添加收款明细记录
  223. $Collection_data = $this->param;
  224. $Collection_data['appoint_id'] = $this->param['id'];
  225. $Collection_data['customer_id'] = $check2['customer_id'];
  226. unset($Collection_data['id']);
  227. $Collection_model = new \app\admin\model\Collection();
  228. $Collection_model->save($Collection_data);
  229. }
  230. $Customer_model->save(['status' => $Customer_status, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
  231. $Appoint_model->save($Appoint_data, [$Appoint_model->getPk() => $this->param[$Appoint_model->getPk()]]);
  232. } else {
  233. if (isset($this->param['status']) && $this->param['status'] == 3) {
  234. $Customer_model->save(['status' => 2, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
  235. }
  236. if (isset($this->param['status']) && $this->param['status'] == 6) {
  237. $Customer_model->save(['status' => 3, 'update_time' => $_SERVER['REQUEST_TIME']], [$Customer_model->getPk() => $check2['customer_id']]);
  238. }
  239. $Appoint_model->save($this->param, [$Appoint_model->getPk() => $this->param[$Appoint_model->getPk()]]);
  240. }
  241. $Appoint_model->commit();
  242. tojson(200, '修改成功');
  243. } catch (\Exception $e) {
  244. if (isset($Appoint_model)) {
  245. $Appoint_model->rollback();
  246. }
  247. tojson(10000, $e->getMessage());
  248. } catch (\Throwable $e) {
  249. if (isset($Appoint_model)) {
  250. $Appoint_model->rollback();
  251. }
  252. tojson(10000, $e->getMessage());
  253. }
  254. }
  255. // public function delete()
  256. // {
  257. // try {
  258. // $Appoint_model = new \app\admin\model\Appoint();
  259. // $check = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->value($Appoint_model->getPk());
  260. // if (!$check) {
  261. // tojson(10000, '记录不存在');
  262. // }
  263. // $result = $Appoint_model->where($Appoint_model->getPk(), $this->param[$Appoint_model->getPk()])->delete();
  264. // if ($result) {
  265. // tojson(200, '删除成功');
  266. // } else {
  267. // tojson(10000, '删除失败');
  268. // }
  269. // } catch (\Exception $e) {
  270. // tojson(10000, $e->getMessage());
  271. // }
  272. // }
  273. }