123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- *
- *User:Administrator
- *Date:2021/10/14
- */
- namespace app\api\model;
- use think\Db;
- use think\Model;
- class Cyd extends Model
- {
- function unitProduction()
- {
- return $this->belongsTo('unitProduction', 'product_unit','id');
- }
- function unitTest()
- {
- return $this->belongsTo('unitTest', 'units_id', 'id');
- }
- function unitSample()
- {
- return $this->belongsTo('unitSample', 'sample_unit', 'id');
- }
- function undertake()
- {
- return $this->belongsTo('underTake', 'undertake_id', 'id');
- }
- public function getCydListByUndertakeId($undertake_id,$pageNum,$pageSize)
- {
- $data = $this->with('undertake')
- ->where('undertake_id', '=', $undertake_id)
- ->page($pageNum,$pageSize)
- ->select();
- return $data;
- }
- public function countCydListByUndertakeId($undertake_id)
- {
- $data = $this->with('undertake')
- ->where('undertake_id', '=', $undertake_id)
- ->count();
- return $data;
- }
- public function getCydDetailBySampleID($sample_id)
- {
- $data = $this->with(['unitProduction', 'unitTest','unitSample'])
- ->where('sample_id','=',$sample_id)
- ->select();
- return $data;
- }
- public function selectCydInfoByTaskID($task_id)
- {
- return $this->where([
- 'task_id' => $task_id,
- 'status'=>1
- ])->select();
- }
- public function countCydInfoByTaskID($task_id)
- {
- return $this->where([
- 'task_id' => $task_id,
- 'status'=>1
- ])->count();
- }
- public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
- {
- //这里保留两个task_id是为了以后可能会删除一个
- $result = $this
- ->alias('cyd')
- ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
- ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
- //bear-抽样单位,report-报告单位,check-检测单位
- ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
- ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
- ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
- ->field('unit_test_name,unit_production_name,cyd.undertake_id')
- ->where($where)
- ->page($pageNum,$pageSize)
- ->select();
- return $result;
- }
- public function countSampleListByTaskIdAndUid($where)
- {
- $count = $this
- ->alias('cyd')
- ->field('sample_id,sample_name,cyd.task_id,place,sample_date,sample_status,test_status')
- ->leftjoin('t_undertake a','a.id=cyd.undertake_id')
- //bear-抽样单位,report-报告单位,check-检测单位
- ->field('bear_name,check_name,report_name,a.task_id as underTake_task_id')
- ->leftjoin('t_unit_test b','cyd.id=b.cyd_id')//受检单位
- ->leftjoin('t_unit_production d','cyd.id=d.cyd_id')//生产单位
- ->field('unit_test_name,unit_production_name')
- ->where($where)
- ->count();
- return $count;
- }
- public function createSample($cyd_data)
- {
- $result = $this->insertGetId($cyd_data);
- return $result;
- }
- public function updateCydDataByID($id, $data)
- {
- $result = $this->where('id','=',$id)->save($data);
- return $result;
- }
- //用于生成抽样单编号的
- public function countSampleCreateID()
- {
- return $this->whereDay('createtime','today')->count();
- }
- public function getCydInfoBySampleId($sample_id)
- {
- return $this->where('sample_id', '=', $sample_id)->find();
- }
- }
|