Cyd.php 3.2 KB

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