appointmentlogic.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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'];
  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. return backarr(0, "已使用");
  59. }
  60. return backarr(1, "查询成功", $info);
  61. }
  62. /**
  63. * 请求数据完成
  64. * 根据appointment_id和testtubeno
  65. *
  66. * @return void
  67. * @author wj
  68. * @date 2022-07-25
  69. */
  70. public function finishedbyaid($arr)
  71. {
  72. $result = $this->checkparam(__FUNCTION__, $arr);
  73. if (1 != $result['status']) {
  74. return $result;
  75. }
  76. $data = $result['data'];
  77. $aid = $data['appointment_id'];
  78. $testtubeno = $data['testtubeno'];
  79. $testtype = $data['testtype'];
  80. $m_t = new tubemodel();
  81. $m_a = new appointmentmodel();
  82. $testtypelist = $m_t->gettesttypelist();
  83. if (!isset($testtypelist[$testtype])) {
  84. return backarr(0, "测试类型错误");
  85. }
  86. $where = ['id' => $aid];
  87. $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno', 'openid', 'code', 'id'];
  88. $ainfo = $m_a->getInfo($where, $field);
  89. if (empty($ainfo)) {
  90. return backarr(0, "无申请数据");
  91. }
  92. if (!$ainfo['ispay']) {
  93. return backarr(0, "未支付");
  94. }
  95. if ($ainfo['isuse']) {
  96. return backarr(0, "已使用");
  97. }
  98. $where = ['appointment_id' => $aid, 'testtubeno' => $testtubeno];
  99. $tinfo = $m_t->getInfo($where);
  100. if (!empty($tinfo)) {
  101. return backarr(0, "数据已存在");
  102. }
  103. Db::startTrans();
  104. try {
  105. $tinsertData = [
  106. 'openid' => $ainfo['openid'],
  107. 'name' => $ainfo['openid'],
  108. 'telno' => $ainfo['openid'],
  109. 'sfzid' => $ainfo['openid'],
  110. 'testtubeno' => $testtubeno,
  111. 'code' => $ainfo['code'],
  112. 'appointment_id' => $ainfo['id'],
  113. ];
  114. $tid = $m_t->insertData($tinsertData);
  115. if (empty($tid)) {
  116. throw new \Exception("试管信息添加失败");
  117. }
  118. $aupdateData = ['isuse' => 1];
  119. $awhere = ['id' => $aid];
  120. $row = $m_a->updateinfo($awhere, $aupdateData);
  121. if (empty($row)) {
  122. throw new \Exception("申请单修改失败");
  123. }
  124. Db::commit();
  125. return backarr(1, "操作成功", ['tid' => $tid]);
  126. } catch (\Exception $e) {
  127. Db::rollback();
  128. return backarr(0, $e->getMessage());
  129. }
  130. }
  131. /**
  132. * 获取测试类型
  133. *
  134. * @return void
  135. * @author wj
  136. * @date 2022-07-26
  137. */
  138. public function gettesttypelist()
  139. {
  140. $t_m = new tubemodel();
  141. $list = $t_m->gettesttypelist();
  142. return $list;
  143. }
  144. }