Cyd.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 countCydListDetail($where,$pageNum=1,$pageSize=null)
  47. {
  48. $result = $this
  49. ->alias('cyd')
  50. ->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')
  51. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  52. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id') //bear-抽样单位,report-报告单位,check-检测单位
  53. ->leftjoin('t_jcdw e','e.id=a.unit_id')
  54. ->field('e.name lead_name')//lead_name牵头单位名称
  55. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  56. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  57. ->field('unit_test_name,unit_production_name,cyd.undertake_id')
  58. ->where($where)
  59. ->count();
  60. return $result;
  61. }
  62. public function getCydListByUndertakeId($undertake_id,$pageNum,$pageSize)
  63. {
  64. $data = $this->with(['undertake','unitTest'])
  65. ->where('undertake_id', '=', $undertake_id)
  66. ->page($pageNum,$pageSize)
  67. ->select();
  68. return $data;
  69. }
  70. public function countCydListByUndertakeId($undertake_id)
  71. {
  72. $data = $this->with(['undertake','unitTest'])
  73. ->where('undertake_id', '=', $undertake_id)
  74. ->count();
  75. return $data;
  76. }
  77. public function getCydDetailBySampleID($sample_id)
  78. {
  79. $data = $this->with(['unitProduction', 'unitTest','unitSample'])
  80. ->where('sample_id','=',$sample_id)
  81. ->find();
  82. return $data;
  83. }
  84. public function selectCydInfoByTaskID($task_id)
  85. {
  86. return $this->where([
  87. 'task_id' => $task_id,
  88. 'status'=>1
  89. ])->select();
  90. }
  91. public function countCydInfoByTaskID($task_id)
  92. {
  93. return $this->where([
  94. 'task_id' => $task_id,
  95. 'status'=>1
  96. ])->count();
  97. }
  98. public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
  99. {
  100. //这里保留两个task_id是为了以后可能会删除一个
  101. $result = $this
  102. ->alias('cyd')
  103. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status,brand,level,sample_base,sample_ground')
  104. ->field('unit_test_name,unit_production_name,cyd.undertake_id')
  105. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  106. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  107. //bear-抽样单位,report-报告单位,check-检测单位
  108. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  109. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  110. ->where($where)
  111. ->page($pageNum,$pageSize)
  112. ->select();
  113. return $result;
  114. }
  115. public function countSampleListByTaskIdAndUid($where)
  116. {
  117. $count = $this
  118. ->alias('cyd')
  119. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
  120. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  121. //bear-抽样单位,report-报告单位,check-检测单位
  122. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  123. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  124. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  125. ->field('unit_test_name,unit_production_name')
  126. ->where($where)
  127. ->count();
  128. return $count;
  129. }
  130. public function createSample($cyd_data)
  131. {
  132. $result = $this->insertGetId($cyd_data);
  133. return $result;
  134. }
  135. public function updateCydDataByID($id, $data)
  136. {
  137. $result = $this->where('id','=',$id)->save($data);
  138. return $result;
  139. }
  140. //用于生成抽样单编号的
  141. public function countSampleCreateID()
  142. {
  143. return $this->whereDay('createtime','today')->count();
  144. }
  145. public function getCydInfoBySampleId($sample_id)
  146. {
  147. return $this->where('sample_id', '=', $sample_id)->find();
  148. }
  149. public function updateCydDataBySampleID($sample_id, $data)
  150. {
  151. return $this->where('sample_id', '=', $sample_id)->save($data);
  152. }
  153. }