appointmentlogic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\app\logic;
  3. use app\common\model\appointmentmodel;
  4. use app\common\model\tubemodel;
  5. use think\Db;
  6. /**
  7. * 登记记录表
  8. *
  9. * @author wj
  10. * @date 2022-07-22
  11. */
  12. class appointmentlogic extends baselogic
  13. {
  14. /**
  15. * 设置请求数据规则
  16. * 20220107
  17. * wj
  18. */
  19. protected function setrules()
  20. {
  21. $list = [
  22. 'getinfobyid' => [
  23. ['name' => 'id', 'title' => '申请id', 'require' => true, 'type' => 'numeric'],
  24. ],
  25. 'finishedbyaid' => [
  26. ['name' => 'appointment_id', 'title' => '申请id', 'require' => true, 'type' => 'numeric'],
  27. ['name' => 'testtubeno', 'title' => '测试管号', 'require' => true, 'type' => 'numeric'],
  28. ['name' => 'testtype', 'title' => '测试类型', 'require' => true, 'type' => 'numeric'],
  29. ],
  30. ];
  31. return $list;
  32. }
  33. /**
  34. * 获取用户当日申请最后一条数据
  35. *
  36. * @param [type] $arr
  37. * @return void
  38. * @author wj
  39. * @date 2022-07-22
  40. */
  41. public function getinfobyid($arr)
  42. {
  43. $result = $this->checkparam(__FUNCTION__, $arr);
  44. if (1 != $result['status']) {
  45. return $result;
  46. }
  47. $m_a = new appointmentmodel();
  48. $where = ['id' => $arr['id']];
  49. $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno', 'id'];
  50. $info = $m_a->getInfo($where, $field);
  51. if (empty($info)) {
  52. return backarr(0, "无申请数据");
  53. }
  54. if (!$info['ispay']) {
  55. return backarr(0, "未支付");
  56. }
  57. if ($info['isuse']) {
  58. $aid = $info['id'];
  59. $m_t = new tubemodel();
  60. $tinfo = $m_t->getInfo(['appointment_id' => $aid], ['oprtime']);
  61. return backarr(0, "已使用", ['id' => $aid, 'oprtime' => $tinfo['oprtime']]);
  62. }
  63. return backarr(1, "查询成功", $info);
  64. }
  65. /**
  66. * 请求数据完成
  67. * 根据appointment_id和testtubeno
  68. *
  69. * @return void
  70. * @author wj
  71. * @date 2022-07-25
  72. */
  73. public function finishedbyaid($arr)
  74. {
  75. $result = $this->checkparam(__FUNCTION__, $arr);
  76. if (1 != $result['status']) {
  77. return $result;
  78. }
  79. $data = $result['data'];
  80. $aid = $data['appointment_id'];
  81. $testtubeno = $data['testtubeno'];
  82. $testtype = $data['testtype'];
  83. $m_t = new tubemodel();
  84. $m_a = new appointmentmodel();
  85. $testtypelist = $m_t->gettesttypelist();
  86. if (!isset($testtypelist[$testtype])) {
  87. return backarr(0, "测试类型错误");
  88. }
  89. $where = ['id' => $aid];
  90. $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno', 'openid', 'code', 'id'];
  91. $ainfo = $m_a->getInfo($where, $field);
  92. if (empty($ainfo)) {
  93. return backarr(0, "无申请数据");
  94. }
  95. if (!$ainfo['ispay']) {
  96. return backarr(0, "未支付");
  97. }
  98. if ($ainfo['isuse']) {
  99. return backarr(0, "已使用");
  100. }
  101. $where = ['appointment_id' => $aid, 'testtubeno' => $testtubeno];
  102. $tinfo = $m_t->getInfo($where);
  103. if (!empty($tinfo)) {
  104. return backarr(0, "数据已存在");
  105. }
  106. Db::startTrans();
  107. try {
  108. $tinsertData = [
  109. 'openid' => $ainfo['openid'],
  110. 'name' => $ainfo['name'],
  111. 'telno' => $ainfo['telno'],
  112. 'sfzid' => $ainfo['sfzid'],
  113. 'testtubeno' => $testtubeno,
  114. 'code' => $ainfo['code'],
  115. 'appointment_id' => $ainfo['id'],
  116. 'test_type' => $testtype,
  117. ];
  118. $tid = $m_t->insertData($tinsertData);
  119. if (empty($tid)) {
  120. throw new \Exception("试管信息添加失败");
  121. }
  122. $aupdateData = ['isuse' => 1];
  123. $awhere = ['id' => $aid];
  124. $row = $m_a->updateinfo($awhere, $aupdateData);
  125. if (empty($row)) {
  126. throw new \Exception("申请单修改失败");
  127. }
  128. Db::commit();
  129. return backarr(1, "操作成功", ['tid' => $tid]);
  130. } catch (\Exception $e) {
  131. Db::rollback();
  132. return backarr(0, $e->getMessage());
  133. }
  134. }
  135. /**
  136. * 获取测试类型
  137. *
  138. * @return void
  139. * @author wj
  140. * @date 2022-07-26
  141. */
  142. public function gettesttypelist()
  143. {
  144. $t_m = new tubemodel();
  145. $list = $t_m->gettesttypelist();
  146. return $list;
  147. }
  148. }