Cyd.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 selectCydInfoByTaskID($task_id)
  24. {
  25. return $this->where([
  26. 'task_id' => $task_id,
  27. 'status'=>1
  28. ])->select();
  29. }
  30. public function countCydInfoByTaskID($task_id)
  31. {
  32. return $this->where([
  33. 'task_id' => $task_id,
  34. 'status'=>1
  35. ])->count();
  36. }
  37. public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
  38. {
  39. $cyd = (new Cyd());
  40. $data = $cyd->with(['unitProduction', 'unitTest','unitSample'])->where($where)->page($pageNum,$pageSize)->select();
  41. return $data;
  42. }
  43. public function countSampleListByTaskIdAndUid($where)
  44. {
  45. $cyd = (new Cyd());
  46. $count = $cyd->with(['unitProduction', 'unitTest','unitSample'])->where($where)->count();
  47. return $count;
  48. }
  49. public function createSample($cyd_data)
  50. {
  51. $result = $this->insertGetId($cyd_data);
  52. return $result;
  53. }
  54. public function updateCydDataByID($id, $data)
  55. {
  56. $result = $this->where('id','=',$id)->save($data);
  57. return $result;
  58. }
  59. //用于生成抽样单编号的
  60. public function countSampleCreateID()
  61. {
  62. return $this->whereDay('createtime','today')->count();
  63. }
  64. }