Cyd.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. *
  4. *User:Administrator
  5. *Date:2021/10/14
  6. */
  7. namespace app\api\model;
  8. use think\Model;
  9. class Cyd extends Model
  10. {
  11. function unitProduction()
  12. {
  13. return $this->belongsTo('unitProduction', 'product_unit','id');
  14. }
  15. function unitTest()
  16. {
  17. return $this->belongsTo('unitTest', 'units_id', 'id');
  18. }
  19. function unitSample()
  20. {
  21. return $this->belongsTo('unitSample', 'sample_unit', 'id');
  22. }
  23. public function getCydDetailBySampleID($sample_id)
  24. {
  25. $cyd = (new Cyd());
  26. $data = $cyd->with(['unitProduction', 'unitTest','unitSample'])
  27. ->where('sample_id','=',$sample_id)
  28. ->select();
  29. return $data;
  30. }
  31. public function selectCydInfoByTaskID($task_id)
  32. {
  33. return $this->where([
  34. 'task_id' => $task_id,
  35. 'status'=>1
  36. ])->select();
  37. }
  38. public function countCydInfoByTaskID($task_id)
  39. {
  40. return $this->where([
  41. 'task_id' => $task_id,
  42. 'status'=>1
  43. ])->count();
  44. }
  45. public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
  46. {
  47. $cyd = (new Cyd());
  48. $data = $cyd->with(['unitProduction', 'unitTest','unitSample'])->where($where)->page($pageNum,$pageSize)->select();
  49. return $data;
  50. }
  51. public function countSampleListByTaskIdAndUid($where)
  52. {
  53. $cyd = (new Cyd());
  54. $count = $cyd->with(['unitProduction', 'unitTest','unitSample'])->where($where)->count();
  55. return $count;
  56. }
  57. public function createSample($cyd_data)
  58. {
  59. $result = $this->insertGetId($cyd_data);
  60. return $result;
  61. }
  62. public function updateCydDataByID($id, $data)
  63. {
  64. $result = $this->where('id','=',$id)->save($data);
  65. return $result;
  66. }
  67. //用于生成抽样单编号的
  68. public function countSampleCreateID()
  69. {
  70. return $this->whereDay('createtime','today')->count();
  71. }
  72. }