appointmentlogic.php 5.1 KB

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