Cyd.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. public function getCydListByUndertakeId($undertake_id,$pageNum,$pageSize)
  29. {
  30. $data = $this->with(['undertake','unitTest'])
  31. ->where('undertake_id', '=', $undertake_id)
  32. ->page($pageNum,$pageSize)
  33. ->select();
  34. return $data;
  35. }
  36. public function countCydListByUndertakeId($undertake_id)
  37. {
  38. $data = $this->with(['undertake','unitTest'])
  39. ->where('undertake_id', '=', $undertake_id)
  40. ->count();
  41. return $data;
  42. }
  43. public function getCydDetailBySampleID($sample_id)
  44. {
  45. $data = $this->with(['unitProduction', 'unitTest','unitSample'])
  46. ->where('sample_id','=',$sample_id)
  47. ->find();
  48. return $data;
  49. }
  50. public function selectCydInfoByTaskID($task_id)
  51. {
  52. return $this->where([
  53. 'task_id' => $task_id,
  54. 'status'=>1
  55. ])->select();
  56. }
  57. public function countCydInfoByTaskID($task_id)
  58. {
  59. return $this->where([
  60. 'task_id' => $task_id,
  61. 'status'=>1
  62. ])->count();
  63. }
  64. public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
  65. {
  66. //这里保留两个task_id是为了以后可能会删除一个
  67. $result = $this
  68. ->alias('cyd')
  69. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
  70. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  71. //bear-抽样单位,report-报告单位,check-检测单位
  72. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  73. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  74. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  75. ->field('unit_test_name,unit_production_name,cyd.undertake_id')
  76. ->where($where)
  77. ->page($pageNum,$pageSize)
  78. ->select();
  79. return $result;
  80. }
  81. public function countSampleListByTaskIdAndUid($where)
  82. {
  83. $count = $this
  84. ->alias('cyd')
  85. ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
  86. ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
  87. //bear-抽样单位,report-报告单位,check-检测单位
  88. ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
  89. ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
  90. ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
  91. ->field('unit_test_name,unit_production_name')
  92. ->where($where)
  93. ->count();
  94. return $count;
  95. }
  96. public function createSample($cyd_data)
  97. {
  98. $result = $this->insertGetId($cyd_data);
  99. return $result;
  100. }
  101. public function updateCydDataByID($id, $data)
  102. {
  103. $result = $this->where('id','=',$id)->save($data);
  104. return $result;
  105. }
  106. //用于生成抽样单编号的
  107. public function countSampleCreateID()
  108. {
  109. return $this->whereDay('createtime','today')->count();
  110. }
  111. public function getCydInfoBySampleId($sample_id)
  112. {
  113. return $this->where('sample_id', '=', $sample_id)->find();
  114. }
  115. public function updateCydDataBySampleID($sample_id, $data)
  116. {
  117. return $this->where('sample_id', '=', $sample_id)->save($data);
  118. }
  119. }