Cyd.php 3.4 KB

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