|
@@ -5,64 +5,73 @@ namespace app\api\controller;
|
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
use think\Db;
|
|
use think\Db;
|
|
|
use app\service\SalaryCalculationService;
|
|
use app\service\SalaryCalculationService;
|
|
|
-/**
|
|
|
|
|
- * 首页接口
|
|
|
|
|
- */
|
|
|
|
|
class Index extends Api
|
|
class Index extends Api
|
|
|
{
|
|
{
|
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedLogin = ['*'];
|
|
|
protected $noNeedRight = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 首页
|
|
|
|
|
- *
|
|
|
|
|
- */
|
|
|
|
|
public function index()
|
|
public function index()
|
|
|
{
|
|
{
|
|
|
$this->success('请求成功');
|
|
$this->success('请求成功');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第一屏
|
|
|
|
|
+ */
|
|
|
public function GetOrderNumber(){
|
|
public function GetOrderNumber(){
|
|
|
- if ($this->request->isGet() === false){
|
|
|
|
|
- $this->error('请求错误');
|
|
|
|
|
- }
|
|
|
|
|
$nowTime = date('Y-m-d H:i:s',time());
|
|
$nowTime = date('Y-m-d H:i:s',time());
|
|
|
$oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
|
|
$oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
|
|
|
- $where =[
|
|
|
|
|
- 'Mod_rq' => ['between',[$oldTime,$nowTime]],
|
|
|
|
|
- '行号' => '1'
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ $currentYear = date('Y');
|
|
|
|
|
+ $lastYear = $currentYear - 1;
|
|
|
|
|
|
|
|
- //按月份查询工单信息
|
|
|
|
|
|
|
+ //按月份查询工单信息(两年)
|
|
|
$monthData = \db('工单_基本资料')
|
|
$monthData = \db('工单_基本资料')
|
|
|
->where('Mod_rq', 'between', [$oldTime, $nowTime])
|
|
->where('Mod_rq', 'between', [$oldTime, $nowTime])
|
|
|
|
|
+ ->where('行号', '1')
|
|
|
->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
|
|
->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
|
|
|
->group('month')
|
|
->group('month')
|
|
|
->order('month')
|
|
->order('month')
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- // 转换为接口需要的格式
|
|
|
|
|
|
|
+ // 构建按月分组的索引
|
|
|
|
|
+ $currentData = array_fill(1, 12, 0);
|
|
|
|
|
+ $lastData = array_fill(1, 12, 0);
|
|
|
|
|
+ foreach ($monthData as $item) {
|
|
|
|
|
+ list($y, $m) = explode('-', $item['month']);
|
|
|
|
|
+ $m = (int)$m;
|
|
|
|
|
+ if ((int)$y == $currentYear) {
|
|
|
|
|
+ $currentData[$m] = (int)$item['count'];
|
|
|
|
|
+ } elseif ((int)$y == $lastYear) {
|
|
|
|
|
+ $lastData[$m] = (int)$item['count'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // X 轴:1-12 月
|
|
|
|
|
+ $categories = [];
|
|
|
|
|
+ for ($i = 1; $i <= 12; $i++) {
|
|
|
|
|
+ $categories[] = str_pad($i, 2, '0', STR_PAD_LEFT);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$result = [
|
|
$result = [
|
|
|
"status" => 0,
|
|
"status" => 0,
|
|
|
- "msg" => "",
|
|
|
|
|
- "data" => [
|
|
|
|
|
- "categories" => [],
|
|
|
|
|
- "series" => [
|
|
|
|
|
|
|
+ "msg" => "",
|
|
|
|
|
+ "data" => [
|
|
|
|
|
+ "categories" => $categories,
|
|
|
|
|
+ "series" => [
|
|
|
|
|
+ [
|
|
|
|
|
+ "name" => $lastYear . "年",
|
|
|
|
|
+ "data" => array_values($lastData),
|
|
|
|
|
+ "color" => "#7B3FF2"
|
|
|
|
|
+ ],
|
|
|
[
|
|
[
|
|
|
- "name" => "工单数量",
|
|
|
|
|
- "data" => []
|
|
|
|
|
|
|
+ "name" => $currentYear . "年",
|
|
|
|
|
+ "data" => array_values($currentData),
|
|
|
|
|
+ "color" => "#0ABEFA"
|
|
|
]
|
|
]
|
|
|
]
|
|
]
|
|
|
]
|
|
]
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- // 填充数据
|
|
|
|
|
- foreach ($monthData as $item) {
|
|
|
|
|
- $result['data']['categories'][] = $item['month'];
|
|
|
|
|
- $result['data']['series'][0]['data'][] = (int)$item['count'];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 返回JSON格式数据
|
|
|
|
|
return json($result);
|
|
return json($result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -112,7 +121,6 @@ class Index extends Api
|
|
|
if($bool===false) $this->error('订单数量存入redis失败','','000002');
|
|
if($bool===false) $this->error('订单数量存入redis失败','','000002');
|
|
|
$this->success('同步成功');
|
|
$this->success('同步成功');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//获取计划中工单数量
|
|
//获取计划中工单数量
|
|
|
public function getJhzByRedis()
|
|
public function getJhzByRedis()
|
|
|
{
|
|
{
|
|
@@ -139,7 +147,6 @@ class Index extends Api
|
|
|
return json($data);
|
|
return json($data);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//获取排程中工单数量
|
|
//获取排程中工单数量
|
|
|
public function getPczByRedis()
|
|
public function getPczByRedis()
|
|
|
{
|
|
{
|
|
@@ -166,7 +173,6 @@ class Index extends Api
|
|
|
return json($data);
|
|
return json($data);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//获取制程中工单数量
|
|
//获取制程中工单数量
|
|
|
public function getZczByRedis()
|
|
public function getZczByRedis()
|
|
|
{
|
|
{
|
|
@@ -233,7 +239,6 @@ class Index extends Api
|
|
|
if($bool===false) $this->error('存入redis失败','','000002');
|
|
if($bool===false) $this->error('存入redis失败','','000002');
|
|
|
$this->success('同步成功');
|
|
$this->success('同步成功');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//印后车间生产进度数据同步Redis
|
|
//印后车间生产进度数据同步Redis
|
|
|
public function yhcjDbToRedis()
|
|
public function yhcjDbToRedis()
|
|
|
{
|
|
{
|
|
@@ -314,7 +319,6 @@ class Index extends Api
|
|
|
'data' => $result
|
|
'data' => $result
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//获取印后车间生产进度数据
|
|
//获取印后车间生产进度数据
|
|
|
public function getYhcjByRedis()
|
|
public function getYhcjByRedis()
|
|
|
{
|
|
{
|
|
@@ -387,29 +391,77 @@ class Index extends Api
|
|
|
$this->success('同步成功');
|
|
$this->success('同步成功');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //获取机台产量数据
|
|
|
|
|
|
|
+ //机台月度走势对比图
|
|
|
public function getJtClDbByRedis()
|
|
public function getJtClDbByRedis()
|
|
|
{
|
|
{
|
|
|
$req = $this->request->param();
|
|
$req = $this->request->param();
|
|
|
|
|
+ $jtbh = isset($req['jtbh']) && !empty($req['jtbh']) ? $req['jtbh'] : null;
|
|
|
|
|
|
|
|
-// if (isset($req['jtbh']) && !empty($req['jtbh'])){
|
|
|
|
|
-// $jtbh = $req['jtbh'];
|
|
|
|
|
-// }else{
|
|
|
|
|
-// $this->error('参数错误');
|
|
|
|
|
-// }
|
|
|
|
|
- $row = cache('jtClDbToRedis');
|
|
|
|
|
-// $result['categories']=[];
|
|
|
|
|
-// $result['series'][0]['name']=$jtbh;
|
|
|
|
|
-// $result['series'][0]['data']=[];
|
|
|
|
|
-// if($row && array_key_exists($jtbh,$row)){
|
|
|
|
|
-// $result['categories'] = array_map('strval', array_keys($row[$jtbh]));
|
|
|
|
|
-// $result['series'][0]['data'] = array_values($row[$jtbh]);
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// $res['status']=0;
|
|
|
|
|
-// $res['msg']='';
|
|
|
|
|
-// $res['data']=$result;
|
|
|
|
|
- return json($row);
|
|
|
|
|
|
|
+ $row = cache('jtClDbToRedis') ?: [];
|
|
|
|
|
+
|
|
|
|
|
+ // 统一班次刻度 08~23
|
|
|
|
|
+ $categories = [];
|
|
|
|
|
+ for ($i = 8; $i < 24; $i++) {
|
|
|
|
|
+ $categories[] = sprintf('%02d', $i);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 从缓存获取机台列表
|
|
|
|
|
+ $machines = array_keys($row);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果缓存为空,从设备基本资料表获取所有机台
|
|
|
|
|
+ if (empty($machines)) {
|
|
|
|
|
+ $machines = \db('设备_基本资料')
|
|
|
|
|
+ ->where('使用状态', 1)
|
|
|
|
|
+ ->column('rtrim(设备编号)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 传了 jtbh 但缓存里没有该机台,也要加入
|
|
|
|
|
+ if ($jtbh !== null && !in_array($jtbh, $machines)) {
|
|
|
|
|
+ $machines[] = $jtbh;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($machines)) {
|
|
|
|
|
+ return json([
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
|
|
+ 'data' => [
|
|
|
|
|
+ 'categories' => $categories,
|
|
|
|
|
+ 'series' => [],
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 取各机台最新一条的当前状态
|
|
|
|
|
+ $statusList = \db('设备_产量采集')
|
|
|
|
|
+ ->whereIn('设备编号', $machines)
|
|
|
|
|
+ ->order('UniqId desc')
|
|
|
|
|
+ ->column('当前状态', '设备编号');
|
|
|
|
|
+
|
|
|
|
|
+ $series = [];
|
|
|
|
|
+ foreach ($machines as $key) {
|
|
|
|
|
+ if ($jtbh !== null && $key !== $jtbh) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $hours = $row[$key] ?? [];
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ foreach ($categories as $h) {
|
|
|
|
|
+ $data[] = isset($hours[$h]) ? (int)$hours[$h] : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $series[] = [
|
|
|
|
|
+ 'name' => $key,
|
|
|
|
|
+ 'status' => $statusList[$key] ?? '',
|
|
|
|
|
+ 'data' => $data,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return json([
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
|
|
+ 'data' => [
|
|
|
|
|
+ 'categories' => $categories,
|
|
|
|
|
+ 'series' => $series,
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -481,16 +533,16 @@ class Index extends Api
|
|
|
{
|
|
{
|
|
|
$row = cache('bzDbToRedis');
|
|
$row = cache('bzDbToRedis');
|
|
|
$result['columns']=[
|
|
$result['columns']=[
|
|
|
- ['name'=>'机台号','id'=>'jtbh','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
|
|
|
|
+ ['name'=>'机台号','id'=>'jtbh','width'=>'30','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
// ['name'=>'班组','id'=>'bzdh','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
// ['name'=>'班组','id'=>'bzdh','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
- ['name'=>'在产工单号','id'=>'gdbh','width'=>'16','textAlign'=>'left'],
|
|
|
|
|
|
|
+ ['name'=>'在产工单号','id'=>'gdbh','width'=>'40','textAlign'=>'left'],
|
|
|
// ['name'=>'工单名称','id'=>'gdmc','width'=>'20','autoWrap'=>"true",'textAlign'=>'left'],
|
|
// ['name'=>'工单名称','id'=>'gdmc','width'=>'20','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
// ['name'=>'印件号','id'=>'yjno','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
// ['name'=>'印件号','id'=>'yjno','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
// ['name'=>'工序','id'=>'gx','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
// ['name'=>'工序','id'=>'gx','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
// ['name'=>'计划产量','id'=>'jhcl','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
|
|
// ['name'=>'计划产量','id'=>'jhcl','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
// ['name'=>'已完成产量','id'=>'wccl','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
|
|
// ['name'=>'已完成产量','id'=>'wccl','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
// ['name'=>'小时产能','id'=>'xscn','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
|
|
// ['name'=>'小时产能','id'=>'xscn','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
- ['name'=>'机台状态','id'=>'status','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
|
|
|
|
+ ['name'=>'机台状态','id'=>'status','width'=>'30','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
];
|
|
];
|
|
|
if($row){
|
|
if($row){
|
|
|
foreach($row as $k=>$v){
|
|
foreach($row as $k=>$v){
|
|
@@ -524,7 +576,9 @@ class Index extends Api
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第二屏
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 决策支持月度设备运行数据统计->班组(接口)
|
|
* 决策支持月度设备运行数据统计->班组(接口)
|
|
@@ -1009,6 +1063,323 @@ class Index extends Api
|
|
|
return json($response);
|
|
return json($response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 工单超节损(接口)Excessive_Structural
|
|
|
|
|
+ * 大屏接口,默认近两个月数据
|
|
|
|
|
+ */
|
|
|
|
|
+ public function Excessive_Structural()
|
|
|
|
|
+ {
|
|
|
|
|
+ $where = [];
|
|
|
|
|
+
|
|
|
|
|
+ // 默认近两个月
|
|
|
|
|
+ $endDate = date('Y-m');
|
|
|
|
|
+ $startDate = date('Y-m', strtotime('-2 months'));
|
|
|
|
|
+ $where['a.jjcp_sj'] = ['between', [$startDate . '-01', $endDate . '-31']];
|
|
|
|
|
+
|
|
|
|
|
+ $field = '
|
|
|
|
|
+ b.sys_ny,
|
|
|
|
|
+ a.jjcp_gdbh AS Gd_gdbh,
|
|
|
|
|
+ a.jjcp_yjno AS jjcp_yjno,
|
|
|
|
|
+ c.yj_cpdh AS 成品编码,
|
|
|
|
|
+ c.yj_yjmc AS 成品名称,
|
|
|
|
|
+ b.`实际投料`,
|
|
|
|
|
+ b.`计量单位`,
|
|
|
|
|
+ DATE(a.jjcp_sj) AS warehousing_date,
|
|
|
|
|
+ total_sl.warehousing_num,
|
|
|
|
|
+ SUM(DISTINCT b.`计划损耗`) AS `工单计划损耗`,
|
|
|
|
|
+ b.`废品合计`,
|
|
|
|
|
+ SUM(b.`CjsJe`) AS reward_money,
|
|
|
|
|
+ b.`印件无形损` AS 工单无形损,
|
|
|
|
|
+ b.`材料废`,
|
|
|
|
|
+ b.`零头处理`,
|
|
|
|
|
+ b.`外发废`,
|
|
|
|
|
+ SUM(b.`班组制程废品`) AS zcfp,
|
|
|
|
|
+ `工单质检废` AS 工单质检废,
|
|
|
|
|
+ c.质量考核,
|
|
|
|
|
+ c.工单类型
|
|
|
|
|
+ ';
|
|
|
|
|
+
|
|
|
|
|
+ $subQuery = \db('成品入仓')
|
|
|
|
|
+ ->alias('a_sub')
|
|
|
|
|
+ ->field('a_sub.jjcp_gdbh AS Gd_gdbh_sub, a_sub.jjcp_yjno AS jjcp_yjno_sub, SUM(a_sub.jjcp_sl) AS warehousing_num')
|
|
|
|
|
+ ->group('a_sub.jjcp_gdbh, a_sub.jjcp_yjno')
|
|
|
|
|
+ ->buildSql();
|
|
|
|
|
+
|
|
|
|
|
+ $list = \db('成品入仓')
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join('工单_质量考核汇总 b', 'a.jjcp_gdbh = b.Gy0_gdbh AND a.jjcp_yjno = b.印件及工序', 'left')
|
|
|
|
|
+ ->join('工单_印件资料 c', 'a.jjcp_gdbh = c.Yj_Gdbh AND a.jjcp_yjno = c.yj_Yjno')
|
|
|
|
|
+ ->join([$subQuery => 'total_sl'], 'a.jjcp_gdbh = total_sl.Gd_gdbh_sub AND a.jjcp_yjno = total_sl.jjcp_yjno_sub', 'left')
|
|
|
|
|
+ ->field($field)
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->where('a.jjcp_smb', 'like', '末%')
|
|
|
|
|
+ ->group('Gd_gdbh,jjcp_yjno')
|
|
|
|
|
+ ->order('warehousing_date DESC')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ $result['columns'] = [
|
|
|
|
|
+ ['name' => '工单编号', 'id' => 'Gd_gdbh', 'width' => '15', 'textAlign' => 'left'],
|
|
|
|
|
+ // ['name' => '印件号', 'id' => 'jjcp_yjno', 'width' => '15', 'textAlign' => 'left'],
|
|
|
|
|
+ // ['name' => '成品编码', 'id' => '成品编码', 'width' => '12', 'textAlign' => 'left'],
|
|
|
|
|
+ ['name' => '成品名称', 'id' => '成品名称', 'width' => '35', 'autoWrap' => 'true', 'textAlign' => 'left'],
|
|
|
|
|
+ // ['name' => '实际投料', 'id' => '实际投料', 'width' => '10', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '计量单位', 'id' => '计量单位', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ ['name' => '入仓日期', 'id' => 'warehousing_date', 'width' => '15', 'textAlign' => 'center'],
|
|
|
|
|
+ ['name' => '入仓数量', 'id' => 'warehousing_num', 'width' => '15', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '计划损耗', 'id' => '工单计划损耗', 'width' => '10', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '废品合计', 'id' => '废品合计', 'width' => '10', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '奖惩金额', 'id' => 'reward_money', 'width' => '10', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '无形损', 'id' => '工单无形损', 'width' => '10', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '材料废', 'id' => '材料废', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '零头处理', 'id' => '零头处理', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '外发废', 'id' => '外发废', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '质检废', 'id' => '工单质检废', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ ['name' => '目标合格率', 'id' => 'target_rate', 'width' => '15', 'textAlign' => 'center'],
|
|
|
|
|
+ ['name' => '实际合格率', 'id' => 'real_rate', 'width' => '15', 'textAlign' => 'center'],
|
|
|
|
|
+ // ['name' => '质量考核', 'id' => '考核', 'width' => '8', 'textAlign' => 'center'],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
|
|
+ $status = \db('工单_印件资料')
|
|
|
|
|
+ ->where('Yj_Gdbh', $value['Gd_gdbh'])
|
|
|
|
|
+ ->where('yj_Yjno', $value['jjcp_yjno'])
|
|
|
|
|
+ ->value('质量考核');
|
|
|
|
|
+ $list[$key]['工单质检废'] = $value['废品合计'] - $value['zcfp'];
|
|
|
|
|
+ $list[$key]['质量考核'] = $status;
|
|
|
|
|
+ $list[$key]['考核'] = ($status == 1) ? '否' : '是';
|
|
|
|
|
+ if ($value['实际投料'] !== null) {
|
|
|
|
|
+ $actualMaterial = $value['实际投料'] * 10000;
|
|
|
|
|
+ $list[$key]['target_rate'] = $this->_calculateRate($actualMaterial, $value['工单计划损耗']);
|
|
|
|
|
+ $list[$key]['real_rate'] = $value['warehousing_num'] / ($value['实际投料'] * 10000) * 100;
|
|
|
|
|
+ $list[$key]['real_rate'] = number_format($list[$key]['real_rate'], 2) . '%';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $list[$key]['target_rate'] = null;
|
|
|
|
|
+ $list[$key]['real_rate'] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ $list[$key]['reward_rate'] = '1';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $result['rows'] = $list;
|
|
|
|
|
+
|
|
|
|
|
+ return json([
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
|
|
+ 'data' => $result
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算目标合格率
|
|
|
|
|
+ */
|
|
|
|
|
+ private function _calculateRate($actual, $loss)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($actual == 0) {
|
|
|
|
|
+ return '0.00%';
|
|
|
|
|
+ }
|
|
|
|
|
+ $rate = ($actual - $loss) / $actual * 100;
|
|
|
|
|
+ return number_format($rate, 2) . '%';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生产中心合格率统计(缓存)
|
|
|
|
|
+ * 同步数据到 Redis
|
|
|
|
|
+ */
|
|
|
|
|
+ public function ProcessOutputRateCache()
|
|
|
|
|
+ {
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ $year = isset($param['year']) && !empty($param['year']) ? $param['year'] : date('Y');
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 获取工序分组
|
|
|
|
|
+ $sist = ['胶印车间', '凹丝印车间', '印后车间', '检验车间'];
|
|
|
|
|
+ $processOrder = \db('设备_基本资料')
|
|
|
|
|
+ ->whereNotNull('设备编组')
|
|
|
|
|
+ ->whereIn('使用部门', $sist)
|
|
|
|
|
+ ->group('设备编组')
|
|
|
|
|
+ ->column('RTRIM(设备编组) as 设备编组');
|
|
|
|
|
+ if (empty($processOrder)) {
|
|
|
|
|
+ $this->success('成功', []);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 初始化结果数组(按工序)
|
|
|
|
|
+ $result = [];
|
|
|
|
|
+ foreach ($processOrder as $process) {
|
|
|
|
|
+ $key = substr($process, 5, 6);
|
|
|
|
|
+ $result[$key] = [];
|
|
|
|
|
+ for ($i = 1; $i <= 12; $i++) {
|
|
|
|
|
+ $result[$key][str_pad($i, 2, '0', STR_PAD_LEFT) . '月'] = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $result[$key]['平均值'] = '0.00%';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 汇总所有年份内数据,一次查出所有"工序-月份"数据
|
|
|
|
|
+ $dataList = \db('工单_质量考核汇总')
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
|
|
+ ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
|
|
+ ->join('成品入仓 d', 'a.Gy0_gdbh = d.jjcp_gdbh AND a.印件及工序 = d.jjcp_yjno')
|
|
|
|
|
+ ->join('设备_基本资料 e', 'a.sczl_jtbh = e.设备编号')
|
|
|
|
|
+ ->whereIn('e.设备编组', $processOrder)
|
|
|
|
|
+ ->where('d.jjcp_smb', 'like', '末%')
|
|
|
|
|
+ ->where('a.sys_ny', 'like', $year . '%')
|
|
|
|
|
+ ->field([
|
|
|
|
|
+ 'e.设备编组',
|
|
|
|
|
+ 'a.sys_ny',
|
|
|
|
|
+ 'SUM(a.班组制程废品/ a.联数) AS 制程废品',
|
|
|
|
|
+ 'SUM(a.班组质检废品/ a.联数) AS 质检废品',
|
|
|
|
|
+ 'SUM(a.班组产量/ a.联数) AS 产量'
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->group('e.设备编组, a.sys_ny')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 处理统计数据
|
|
|
|
|
+ $yearTotal = [];
|
|
|
|
|
+ foreach ($dataList as $item) {
|
|
|
|
|
+ $processKey = substr($item['设备编组'], 5, 6);
|
|
|
|
|
+ $monthKey = substr($item['sys_ny'], 4, 2) . '月';
|
|
|
|
|
+
|
|
|
|
|
+ $output = floatval($item['产量']);
|
|
|
|
|
+ $waste = floatval($item['制程废品']) + floatval($item['质检废品']);
|
|
|
|
|
+ $rate = $output > 0 ? (1 - $waste / $output) * 100 : 0;
|
|
|
|
|
+ $result[$processKey][$monthKey] = sprintf('%.2f%%', $rate);
|
|
|
|
|
+
|
|
|
|
|
+ if (!isset($yearTotal[$processKey])) {
|
|
|
|
|
+ $yearTotal[$processKey] = ['totalOutput' => 0, 'totalWaste' => 0];
|
|
|
|
|
+ }
|
|
|
|
|
+ $yearTotal[$processKey]['totalOutput'] += $output;
|
|
|
|
|
+ $yearTotal[$processKey]['totalWaste'] += $waste;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 计算年均合格率
|
|
|
|
|
+ foreach ($yearTotal as $processKey => $val) {
|
|
|
|
|
+ $totalOutput = $val['totalOutput'];
|
|
|
|
|
+ $totalWaste = $val['totalWaste'];
|
|
|
|
|
+ if ($totalOutput > 0) {
|
|
|
|
|
+ $avgRate = (1 - $totalWaste / $totalOutput) * 100;
|
|
|
|
|
+ $result[$processKey]['平均值'] = sprintf('%.2f%%', $avgRate);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $result[$processKey]['平均值'] = '0.00%';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 存入 Redis
|
|
|
|
|
+ $bool = cache('ProcessOutputRate_' . $year, $result);
|
|
|
|
|
+ if ($bool === false) {
|
|
|
|
|
+ $this->error('存入redis失败', '', '000002');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('同步成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 质检废品率统计(合格率图表)
|
|
|
|
|
+ * 从 Redis 读取数据返回 Sugar BI 图表格式(本月、有数据的前10工序)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function ProcessOutputRate()
|
|
|
|
|
+ {
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ $year = isset($param['year']) && !empty($param['year']) ? $param['year'] : date('Y');
|
|
|
|
|
+ $month = date('m'); // 本月
|
|
|
|
|
+
|
|
|
|
|
+ $data = cache('ProcessOutputRate_' . $year);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($data)) {
|
|
|
|
|
+ return json([
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
|
|
+ 'data' => [
|
|
|
|
|
+ 'categories' => [],
|
|
|
|
|
+ 'series' => []
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 过滤掉本月无数据的工序,只保留有数据的
|
|
|
|
|
+ $hasDataKeys = [];
|
|
|
|
|
+ foreach ($data as $process => $row) {
|
|
|
|
|
+ $val = $row[$month . '月'] ?? '';
|
|
|
|
|
+ if ($val !== '' && $val !== null && $val !== 0) {
|
|
|
|
|
+ $hasDataKeys[] = $process;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 只取前 10 道有数据的工序
|
|
|
|
|
+ $processKeys = array_slice($hasDataKeys, 0, 10);
|
|
|
|
|
+
|
|
|
|
|
+ // 本月刻度
|
|
|
|
|
+ $categories = [$month . '月'];
|
|
|
|
|
+
|
|
|
|
|
+ $series = [];
|
|
|
|
|
+ foreach ($processKeys as $process) {
|
|
|
|
|
+ $row = $data[$process] ?? [];
|
|
|
|
|
+ $val = $row[$month . '月'] ?? '';
|
|
|
|
|
+ if ($val !== '' && $val !== null) {
|
|
|
|
|
+ $value = floatval(str_replace('%', '', $val));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $value = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $series[] = [
|
|
|
|
|
+ 'name' => $process,
|
|
|
|
|
+ 'data' => [$value],
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return json([
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
|
|
+ 'data' => [
|
|
|
|
|
+ 'categories' => $categories,
|
|
|
|
|
+ 'series' => $series,
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 年度质检废品率统计(表格)
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function QualityInspectionList()
|
|
|
|
|
+ {
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ $year = isset($param['year']) && !empty($param['year']) ? $param['year'] : date('Y');
|
|
|
|
|
+ $where = ['年月' => ['like', $year . '%']];
|
|
|
|
|
+
|
|
|
|
|
+ // 按废品类别统计数量
|
|
|
|
|
+ $wasteList = \db('rec_月度废品汇总')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->field('废品类别, sum(废品数量) as 废品数量')
|
|
|
|
|
+ ->group('废品类别')
|
|
|
|
|
+ ->order('废品数量 desc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ // 总量
|
|
|
|
|
+ $total = 0;
|
|
|
|
|
+ foreach ($wasteList as $item) {
|
|
|
|
|
+ $total += $item['废品数量'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构建 Sugar BI 表格格式
|
|
|
|
|
+ $result = [
|
|
|
|
|
+ 'columns' => [
|
|
|
|
|
+ ['name' => '废品名称', 'id' => '废品名称类别', 'width' => '40', 'autoWrap' => "true", 'textAlign' => 'left'],
|
|
|
|
|
+ ['name' => '数量', 'id' => '数量', 'width' => '30', 'autoWrap' => "true", 'textAlign' => 'center'],
|
|
|
|
|
+ ['name' => '占比', 'id' => '占比', 'width' => '30', 'autoWrap' => "true", 'textAlign' => 'center'],
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'rows' => [],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($wasteList as $item) {
|
|
|
|
|
+ $ratio = $total > 0 ? round($item['废品数量'] / $total * 100, 2) . '%' : '0%';
|
|
|
|
|
+ $result['rows'][] = [
|
|
|
|
|
+ '废品名称类别' => $item['废品类别'],
|
|
|
|
|
+ '数量' => $item['废品数量'],
|
|
|
|
|
+ '占比' => $ratio,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $resOut['status'] = 0;
|
|
|
|
|
+ $resOut['msg'] = '';
|
|
|
|
|
+ $resOut['data'] = $result;
|
|
|
|
|
+ return json($resOut);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|