Cyd.php 1.6 KB

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