|
@@ -5,6 +5,7 @@ namespace app\api\controller;
|
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
use \think\Request;
|
|
use \think\Request;
|
|
|
use \think\Db;
|
|
use \think\Db;
|
|
|
|
|
+use \think\cache;
|
|
|
/**
|
|
/**
|
|
|
* 工单核验单维护接口
|
|
* 工单核验单维护接口
|
|
|
*/
|
|
*/
|
|
@@ -32,30 +33,37 @@ class WorkOrderVerification extends Api
|
|
|
if(!$this->request->isGet()){
|
|
if(!$this->request->isGet()){
|
|
|
$this->error('请求方式错误');
|
|
$this->error('请求方式错误');
|
|
|
}
|
|
}
|
|
|
- $rows = db()->table('db_qczl')
|
|
|
|
|
- ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
|
|
|
|
|
- ->group('date')
|
|
|
|
|
- ->order('UniqId desc')
|
|
|
|
|
- ->limit(30)
|
|
|
|
|
- ->select();
|
|
|
|
|
|
|
+ $is_have_cache = Cache::get('getTab');
|
|
|
|
|
+ if ($is_have_cache === false){
|
|
|
|
|
+ $rows = db()->table('db_qczl')
|
|
|
|
|
+ ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
|
|
|
|
|
+ ->group('date')
|
|
|
|
|
+ ->order('UniqId desc')
|
|
|
|
|
+ ->limit(30)
|
|
|
|
|
+ ->select();
|
|
|
|
|
|
|
|
- $arr = db()->table('db_qczl')
|
|
|
|
|
- ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
|
|
|
|
|
- ->where('sys_rq','>=',$rows[29]['date'])
|
|
|
|
|
- ->group('date, sys_id')
|
|
|
|
|
- ->select();
|
|
|
|
|
|
|
+ $arr = db()->table('db_qczl')
|
|
|
|
|
+ ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
|
|
|
|
|
+ ->where('sys_rq','>=',$rows[29]['date'])
|
|
|
|
|
+ ->group('date, sys_id')
|
|
|
|
|
+ ->select();
|
|
|
|
|
|
|
|
- foreach($rows as $key=>$value){
|
|
|
|
|
- $rows[$key]['sys'] = [];
|
|
|
|
|
- foreach($arr as $k=>$v){
|
|
|
|
|
- if($value['date'] == $v['date']){
|
|
|
|
|
- unset($v['date']);
|
|
|
|
|
- array_push($rows[$key]['sys'],$v);
|
|
|
|
|
- unset($arr[$k]);
|
|
|
|
|
|
|
+ foreach($rows as $key=>$value){
|
|
|
|
|
+ $rows[$key]['sys'] = [];
|
|
|
|
|
+ foreach($arr as $k=>$v){
|
|
|
|
|
+ if($value['date'] == $v['date']){
|
|
|
|
|
+ unset($v['date']);
|
|
|
|
|
+ array_push($rows[$key]['sys'],$v);
|
|
|
|
|
+ unset($arr[$k]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
|
|
|
}
|
|
}
|
|
|
- $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
|
|
|
|
|
|
|
+ Cache::set('getTab',$rows,86400);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $rows = Cache::get('getTab');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
$this->success('成功',$rows);
|
|
$this->success('成功',$rows);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -346,7 +354,7 @@ class WorkOrderVerification extends Api
|
|
|
$where['a.sczl_type'] = array('like','%'.$search.'%');
|
|
$where['a.sczl_type'] = array('like','%'.$search.'%');
|
|
|
$list = db('设备_产量计酬')->alias('a')
|
|
$list = db('设备_产量计酬')->alias('a')
|
|
|
->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
|
|
->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
|
|
|
- ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
|
|
|
|
|
|
|
+ ->where($where)->cache(true,86400)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
|
|
|
->select();
|
|
->select();
|
|
|
$count = count($list);
|
|
$count = count($list);
|
|
|
$list[$count]['sczl_gxmc'] = '99-外发加工';
|
|
$list[$count]['sczl_gxmc'] = '99-外发加工';
|
|
@@ -656,7 +664,7 @@ class WorkOrderVerification extends Api
|
|
|
if (!isset($params['end_date']) || empty($params['end_date'])) {
|
|
if (!isset($params['end_date']) || empty($params['end_date'])) {
|
|
|
$this->error('参数错误');
|
|
$this->error('参数错误');
|
|
|
}
|
|
}
|
|
|
- $where['qczl_rq'] = array('between time', [$params['start_date'], $params['start_date']]);
|
|
|
|
|
|
|
+ $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
|
|
|
$field = '
|
|
$field = '
|
|
|
rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
|
|
rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
|
|
|
rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
|
|
rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
|
|
@@ -666,69 +674,76 @@ class WorkOrderVerification extends Api
|
|
|
rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
|
|
rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
|
|
|
qczl_rq
|
|
qczl_rq
|
|
|
';
|
|
';
|
|
|
-
|
|
|
|
|
- $data = db('db_qczl')
|
|
|
|
|
- ->where($where)
|
|
|
|
|
- ->where(function ($query) {
|
|
|
|
|
|
|
+ $resultArray = array();
|
|
|
|
|
+ $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
|
|
|
|
|
+ $is_have_cache = Cache::has($key);
|
|
|
|
|
+ if ($is_have_cache === false){
|
|
|
|
|
+ $data = db('db_qczl')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->where(function ($query) {
|
|
|
|
|
+ for ($i = 1; $i <= 13; $i++) {
|
|
|
|
|
+ $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ->field($field)->select();
|
|
|
|
|
+ $list = [];
|
|
|
|
|
+ $j = 0;
|
|
|
|
|
+ foreach ($data as $entry) {
|
|
|
for ($i = 1; $i <= 13; $i++) {
|
|
for ($i = 1; $i <= 13; $i++) {
|
|
|
- $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- ->field($field)->select();
|
|
|
|
|
- $list = [];
|
|
|
|
|
- $j = 0;
|
|
|
|
|
- foreach ($data as $entry) {
|
|
|
|
|
- for ($i = 1; $i <= 13; $i++) {
|
|
|
|
|
- $labelKey = "fp_lb" . $i;
|
|
|
|
|
- $slKey = "fp_sl" . $i;
|
|
|
|
|
- $bhKey = "fp_bh" . $i;
|
|
|
|
|
- $bzKey = "fp_bz" . $i;
|
|
|
|
|
- if (!empty($entry[$labelKey])) {
|
|
|
|
|
- if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
|
|
|
|
|
- $list[$j]['fp_lb'] = $entry[$labelKey];
|
|
|
|
|
- $list[$j]['fp_sl'] = $entry[$slKey];
|
|
|
|
|
- $list[$j]['fp_bh'] = $entry[$bhKey];
|
|
|
|
|
- $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
|
|
|
|
|
- $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
|
|
|
|
|
- $list[$j]['fp_bz'] = $entry[$bzKey];
|
|
|
|
|
- $list[$j]['qczl_rq'] = $entry['qczl_rq'];
|
|
|
|
|
- $j++;
|
|
|
|
|
|
|
+ $labelKey = "fp_lb" . $i;
|
|
|
|
|
+ $slKey = "fp_sl" . $i;
|
|
|
|
|
+ $bhKey = "fp_bh" . $i;
|
|
|
|
|
+ $bzKey = "fp_bz" . $i;
|
|
|
|
|
+ if (!empty($entry[$labelKey])) {
|
|
|
|
|
+ if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
|
|
|
|
|
+ $list[$j]['fp_lb'] = $entry[$labelKey];
|
|
|
|
|
+ $list[$j]['fp_sl'] = $entry[$slKey];
|
|
|
|
|
+ $list[$j]['fp_bh'] = $entry[$bhKey];
|
|
|
|
|
+ $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
|
|
|
|
|
+ $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
|
|
|
|
|
+ $list[$j]['fp_bz'] = $entry[$bzKey];
|
|
|
|
|
+ $list[$j]['qczl_rq'] = $entry['qczl_rq'];
|
|
|
|
|
+ $j++;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- $resultArray = array();
|
|
|
|
|
- foreach ($list as $item) {
|
|
|
|
|
- $found = false;
|
|
|
|
|
- foreach ($resultArray as &$resultItem) {
|
|
|
|
|
- if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
|
|
|
|
|
- $resultItem["fp_sl"] += (int)$item["fp_sl"];
|
|
|
|
|
- $found = true;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ foreach ($list as $item) {
|
|
|
|
|
+ $found = false;
|
|
|
|
|
+ foreach ($resultArray as &$resultItem) {
|
|
|
|
|
+ if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
|
|
|
|
|
+ $resultItem["fp_sl"] += (int)$item["fp_sl"];
|
|
|
|
|
+ $found = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!$found) {
|
|
|
|
|
+ $resultArray[] = $item;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (!$found) {
|
|
|
|
|
- $resultArray[] = $item;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 使用usort进行排序
|
|
|
|
|
- usort($resultArray, function($a, $b) {
|
|
|
|
|
- // First, sort by fp_lb (K01/K02)
|
|
|
|
|
- $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
|
|
|
|
|
- if ($compareLb !== 0) {
|
|
|
|
|
- return $compareLb;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 使用usort进行排序
|
|
|
|
|
+ usort($resultArray, function($a, $b) {
|
|
|
|
|
+ // First, sort by fp_lb (K01/K02)
|
|
|
|
|
+ $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
|
|
|
|
|
+ if ($compareLb !== 0) {
|
|
|
|
|
+ return $compareLb;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // If fp_lb is the same, prioritize B班 over A班
|
|
|
|
|
- $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
|
|
|
|
|
- if ($compareBz !== 0) {
|
|
|
|
|
- return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // If fp_lb is the same, prioritize B班 over A班
|
|
|
|
|
+ $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
|
|
|
|
|
+ if ($compareBz !== 0) {
|
|
|
|
|
+ return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // If fp_bz is the same, sort by fp_bh
|
|
|
|
|
+ $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
|
|
|
|
|
+ return $compareBh;
|
|
|
|
|
+ });
|
|
|
|
|
+ Cache::set($key,$resultArray,86400);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $resultArray = Cache::get($key);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // If fp_bz is the same, sort by fp_bh
|
|
|
|
|
- $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
|
|
|
|
|
- return $compareBh;
|
|
|
|
|
- });
|
|
|
|
|
$this->success('请求成功',$resultArray);
|
|
$this->success('请求成功',$resultArray);
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|