Cyd.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. *
  4. *User:Administrator
  5. *Date:2021/10/14
  6. */
  7. namespace app\api\model;
  8. use think\Db;
  9. use think\Model;
  10. class Cyd extends Model
  11. {
  12. function unitProduction()
  13. {
  14. return $this->belongsTo('unitProduction', 'product_unit','id');
  15. }
  16. function unitTest()//受检单位
  17. {
  18. return $this->belongsTo('unitTest', 'units_id', 'id');
  19. }
  20. function unitSample()
  21. {
  22. return $this->belongsTo('unitSample', 'sample_unit', 'id');
  23. }
  24. function undertake()
  25. {
  26. return $this->belongsTo('underTake', 'undertake_id', 'id');
  27. }
  28. //监管端获取抽样单
  29. public function getCydListDetail($where,$pageNum=1,$pageSize=null)
  30. {
  31. $result = $this
  32. ->alias('cyd')
  33. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status,brand,level,sample_base,sample_ground,unit_id as lead_id')
  34. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  35. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id') //bear-抽样单位,report-报告单位,check-检测单位
  36. ->leftjoin('t_jcdw e','e.id=a.unit_id')
  37. ->field('e.name lead_name')//lead_name牵头单位名称
  38. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  39. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  40. ->field('unit_test_name,unit_production_name,cyd.undertake_id')
  41. ->where($where)
  42. ->page($pageNum,$pageSize)
  43. ->select();
  44. return $result;
  45. }
  46. public function getCydListByUndertakeId($undertake_id,$pageNum,$pageSize)
  47. {
  48. $data = $this->with(['undertake','unitTest'])
  49. ->where('undertake_id', '=', $undertake_id)
  50. ->page($pageNum,$pageSize)
  51. ->select();
  52. return $data;
  53. }
  54. public function countCydListByUndertakeId($undertake_id)
  55. {
  56. $data = $this->with(['undertake','unitTest'])
  57. ->where('undertake_id', '=', $undertake_id)
  58. ->count();
  59. return $data;
  60. }
  61. public function getCydDetailBySampleID($sample_id)
  62. {
  63. $data = $this->with(['unitProduction', 'unitTest','unitSample'])
  64. ->where('sample_id','=',$sample_id)
  65. ->find();
  66. return $data;
  67. }
  68. public function selectCydInfoByTaskID($task_id)
  69. {
  70. return $this->where([
  71. 'task_id' => $task_id,
  72. 'status'=>1
  73. ])->select();
  74. }
  75. public function countCydInfoByTaskID($task_id)
  76. {
  77. return $this->where([
  78. 'task_id' => $task_id,
  79. 'status'=>1
  80. ])->count();
  81. }
  82. public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
  83. {
  84. //这里保留两个task_id是为了以后可能会删除一个
  85. $result = $this
  86. ->alias('cyd')
  87. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status,brand,level,sample_base,sample_ground')
  88. ->field('unit_test_name,unit_production_name,cyd.undertake_id')
  89. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  90. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  91. //bear-抽样单位,report-报告单位,check-检测单位
  92. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  93. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  94. ->where($where)
  95. ->page($pageNum,$pageSize)
  96. ->select();
  97. return $result;
  98. }
  99. public function countSampleListByTaskIdAndUid($where)
  100. {
  101. $count = $this
  102. ->alias('cyd')
  103. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
  104. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  105. //bear-抽样单位,report-报告单位,check-检测单位
  106. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  107. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  108. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  109. ->field('unit_test_name,unit_production_name')
  110. ->where($where)
  111. ->count();
  112. return $count;
  113. }
  114. public function createSample($cyd_data)
  115. {
  116. $result = $this->insertGetId($cyd_data);
  117. return $result;
  118. }
  119. public function updateCydDataByID($id, $data)
  120. {
  121. $result = $this->where('id','=',$id)->save($data);
  122. return $result;
  123. }
  124. //用于生成抽样单编号的
  125. public function countSampleCreateID()
  126. {
  127. return $this->whereDay('createtime','today')->count();
  128. }
  129. public function getCydInfoBySampleId($sample_id)
  130. {
  131. return $this->where('sample_id', '=', $sample_id)->find();
  132. }
  133. public function updateCydDataBySampleID($sample_id, $data)
  134. {
  135. return $this->where('sample_id', '=', $sample_id)->save($data);
  136. }
  137. }