appointmentlogic.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\app\logic;
  3. use app\app\model\appointmentmodel;
  4. use app\app\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. ],
  29. ];
  30. return $list;
  31. }
  32. /**
  33. * 获取用户当日申请最后一条数据
  34. *
  35. * @param [type] $arr
  36. * @return void
  37. * @author wj
  38. * @date 2022-07-22
  39. */
  40. public function getinfobyid($arr)
  41. {
  42. $result = $this->checkparam(__FUNCTION__, $arr);
  43. if (1 != $result['status']) {
  44. return $result;
  45. }
  46. $m_a = new appointmentmodel();
  47. $where = ['id' => $arr['id']];
  48. $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno'];
  49. $info = $m_a->getInfo($where, $field);
  50. if (empty($info)) {
  51. return backarr(0, "无申请数据");
  52. }
  53. if (!$info['ispay']) {
  54. return backarr(0, "未支付");
  55. }
  56. if ($info['isuse']) {
  57. return backarr(0, "已使用");
  58. }
  59. return backarr(1, "查询成功", $info);
  60. }
  61. /**
  62. * 请求数据完成
  63. * 根据appointment_id和testtubeno
  64. *
  65. * @return void
  66. * @author wj
  67. * @date 2022-07-25
  68. */
  69. public function finishedbyaid($arr)
  70. {
  71. $result = $this->checkparam(__FUNCTION__, $arr);
  72. if (1 != $result['status']) {
  73. return $result;
  74. }
  75. $data = $result['data'];
  76. $aid = $data['appointment_id'];
  77. $testtubeno = $data['testtubeno'];
  78. $m_t = new tubemodel();
  79. $m_a = new appointmentmodel();
  80. $where = ['id' => $aid];
  81. $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno', 'openid', 'code', 'id'];
  82. $ainfo = $m_a->getInfo($where, $field);
  83. if (empty($ainfo)) {
  84. return backarr(0, "无申请数据");
  85. }
  86. if (!$ainfo['ispay']) {
  87. return backarr(0, "未支付");
  88. }
  89. if ($ainfo['isuse']) {
  90. return backarr(0, "已使用");
  91. }
  92. $where = ['appointment_id' => $aid, 'testtubeno' => $testtubeno];
  93. $tinfo = $m_t->getInfo($where);
  94. if (!empty($tinfo)) {
  95. return backarr(0, "数据已存在");
  96. }
  97. Db::startTrans();
  98. try {
  99. $tinsertData = [
  100. 'openid' => $ainfo['openid'],
  101. 'name' => $ainfo['openid'],
  102. 'telno' => $ainfo['openid'],
  103. 'sfzid' => $ainfo['openid'],
  104. 'testtubeno' => $testtubeno,
  105. 'code' => $ainfo['code'],
  106. 'appointment_id' => $ainfo['id'],
  107. ];
  108. $tid = $m_t->insertData($tinsertData);
  109. if (empty($tid)) {
  110. throw new \Exception("试管信息添加失败");
  111. }
  112. $aupdateData = ['isuse' => 1];
  113. $awhere = ['id' => $aid];
  114. $row = $m_a->updateinfo($awhere, $aupdateData);
  115. if (empty($row)) {
  116. throw new \Exception("申请单修改失败");
  117. }
  118. Db::commit();
  119. return backarr(1, "操作成功", ['tid' => $tid]);
  120. } catch (\Exception $e) {
  121. Db::rollback();
  122. return backarr(0, $e->getMessage());
  123. }
  124. }
  125. }