62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use CodeIgniter\Model;
|
||
|
|
|
||
|
|
class DailyResultModel extends Model
|
||
|
|
{
|
||
|
|
protected $table = 'daily_result';
|
||
|
|
protected $primaryKey = 'id';
|
||
|
|
protected $useAutoIncrement = true;
|
||
|
|
protected $returnType = 'array';
|
||
|
|
protected $useSoftDeletes = false;
|
||
|
|
protected $allowedFields = ['controlid', 'testid', 'resdate', 'resvalue', 'rescomment'];
|
||
|
|
protected $useTimestamps = false;
|
||
|
|
|
||
|
|
public function getByMonth($controlid, $testid, $yearMonth)
|
||
|
|
{
|
||
|
|
$startDate = $yearMonth . '-01';
|
||
|
|
$endDate = $yearMonth . '-31';
|
||
|
|
|
||
|
|
$builder = $this->db->table('daily_result');
|
||
|
|
$builder->select('*');
|
||
|
|
$builder->where('controlid', $controlid);
|
||
|
|
$builder->where('testid', $testid);
|
||
|
|
$builder->where('resdate >=', $startDate);
|
||
|
|
$builder->where('resdate <=', $endDate);
|
||
|
|
$builder->orderBy('resdate', 'ASC');
|
||
|
|
return $builder->get()->getResultArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getByControlMonth($controlid, $yearMonth)
|
||
|
|
{
|
||
|
|
$startDate = $yearMonth . '-01';
|
||
|
|
$endDate = $yearMonth . '-31';
|
||
|
|
|
||
|
|
$builder = $this->db->table('daily_result');
|
||
|
|
$builder->select('*');
|
||
|
|
$builder->where('controlid', $controlid);
|
||
|
|
$builder->where('resdate >=', $startDate);
|
||
|
|
$builder->where('resdate <=', $endDate);
|
||
|
|
return $builder->get()->getResultArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function saveResult($data)
|
||
|
|
{
|
||
|
|
$builder = $this->db->table('daily_result');
|
||
|
|
$existing = $builder->select('*')
|
||
|
|
->where('controlid', $data['controlid'])
|
||
|
|
->where('testid', $data['testid'])
|
||
|
|
->where('resdate', $data['resdate'])
|
||
|
|
->get()
|
||
|
|
->getRowArray();
|
||
|
|
|
||
|
|
if ($existing) {
|
||
|
|
return $builder->where('id', $existing['id'])->update($data);
|
||
|
|
} else {
|
||
|
|
return $builder->insert($data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|