|
@@ -6,13 +6,18 @@ use App\Model\ApplyOrder;
|
|
|
use App\Model\ApplyOrderDetail;
|
|
|
use App\Model\Box;
|
|
|
use App\Model\BoxDetail;
|
|
|
+use App\Model\DispatchEmpSub;
|
|
|
use App\Model\DispatchSub;
|
|
|
+use App\Model\EmployeeTeamPermission;
|
|
|
+use App\Model\Equipment;
|
|
|
+use App\Model\OrdersProduct;
|
|
|
use App\Model\OrdersProductProcess;
|
|
|
use App\Model\Process;
|
|
|
use App\Model\SaleOrdersProduct;
|
|
|
use App\Model\SalesFrom;
|
|
|
use App\Model\ScrappCount;
|
|
|
use App\Model\SystemL;
|
|
|
+use App\Model\Team;
|
|
|
use App\Service\FyySqlServerService;
|
|
|
use App\Service\ReportFormsService;
|
|
|
use Carbon\Carbon;
|
|
@@ -282,7 +287,7 @@ class ScreenController extends BaseController
|
|
|
|
|
|
//产量趋势图
|
|
|
public function output_value_efficiency(Request $request){
|
|
|
- $time = strtotime(date("Y-06-01 00:00:00"));
|
|
|
+ $time = strtotime(date("2024-06-01 00:00:00"));
|
|
|
|
|
|
$return = [];
|
|
|
$data = ApplyOrderDetail::where('del_time',0)
|
|
@@ -291,10 +296,18 @@ class ScreenController extends BaseController
|
|
|
->select('quantity','crt_time','data_id')
|
|
|
->get()->toArray();
|
|
|
$dispatch = DispatchSub::whereIn('id',array_column($data,'data_id'))
|
|
|
- ->pluck("production_quantity",'id')
|
|
|
+ ->pluck('sale_orders_product_id','id')
|
|
|
->toArray();
|
|
|
+ $sale_order_map = [];
|
|
|
+ $sale_order = SaleOrdersProduct::whereIn('id', array_unique(array_values($dispatch)))
|
|
|
+ ->select('order_quantity','id','crt_time')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ foreach ($sale_order as $value){
|
|
|
+ $sale_order_map[$value['id']] = $value;
|
|
|
+ }
|
|
|
|
|
|
- $plan = [];
|
|
|
+ $plan = $plan_2 = [];
|
|
|
foreach ($data as $value) {
|
|
|
$date = date("Y-m-d", $value['crt_time']);
|
|
|
if (isset($return[$date])) {
|
|
@@ -304,14 +317,20 @@ class ScreenController extends BaseController
|
|
|
$return[$date] = $value['quantity'];
|
|
|
}
|
|
|
|
|
|
- $n = $dispatch[$value['data_id']] ?? 0;
|
|
|
- if (isset($plan[$date])) {
|
|
|
- $quantity = bcadd($plan[$date], $n, 3);
|
|
|
- $plan[$date] = $quantity;
|
|
|
- } else {
|
|
|
- $plan[$date] = $n;
|
|
|
+ $sale_id = $dispatch[$value['data_id']] ?? 0;
|
|
|
+ $n = $sale_order_map[$sale_id] ?? [];
|
|
|
+ if(! empty($n)){
|
|
|
+ $date_2 = date("Y-m-d", $n['crt_time']);
|
|
|
+ if(isset($plan_2[$date_2]) && in_array($sale_id, $plan_2[$date_2])) continue;
|
|
|
+ if (isset($plan[$date_2])) {
|
|
|
+ $quantity = bcadd($plan[$date_2], $n['order_quantity'], 3);
|
|
|
+ $plan[$date_2] = $quantity;
|
|
|
+ } else {
|
|
|
+ $plan[$date_2] = $n['order_quantity'];
|
|
|
+ }
|
|
|
+ $plan_2[$date_2][] = $sale_id;
|
|
|
}
|
|
|
- }
|
|
|
+ }unset($plan_2);
|
|
|
|
|
|
ksort($return);
|
|
|
|
|
@@ -320,7 +339,7 @@ class ScreenController extends BaseController
|
|
|
$tmp = [
|
|
|
'time' => $key,
|
|
|
'output' => $value,
|
|
|
- 'plan' => $plan[$key] ?? 0,
|
|
|
+ 'plan' => $plan[$key] ?? $value,
|
|
|
];
|
|
|
$result[] = $tmp;
|
|
|
}
|
|
@@ -742,4 +761,338 @@ class ScreenController extends BaseController
|
|
|
|
|
|
return $this->json_return(200,'',$return);
|
|
|
}
|
|
|
+
|
|
|
+ public function deviceProduction(Request $request)
|
|
|
+ {
|
|
|
+ $now = time();
|
|
|
+
|
|
|
+ //当天的开始与结束时间戳
|
|
|
+ $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
|
|
|
+ $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
|
|
|
+
|
|
|
+ $latestTimes = SystemL::select('device_no', DB::raw('MAX(time) as max_time'))
|
|
|
+ ->whereIn('data_point_name', [SystemL::run, SystemL::work, SystemL::stop, SystemL::standBy])
|
|
|
+ ->where('time', '>=', $timestamp_today_start * 1000)
|
|
|
+ ->where('time', '<=', $timestamp_today_end * 1000)
|
|
|
+ ->groupBy('device_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map = array_column($latestTimes,null,'device_no');
|
|
|
+
|
|
|
+ //数据模型
|
|
|
+ $models = [];
|
|
|
+ $is_all_close = 1;
|
|
|
+ $e_map = Equipment::where('del_time',0)->pluck('id','code');
|
|
|
+ foreach (SystemL::$device as $k => $v){
|
|
|
+ $is_close = 1;
|
|
|
+ if(isset($map[$v])){
|
|
|
+ $max_time = intval($map[$v]['max_time']) ?? 0;
|
|
|
+ $max_time = intval($max_time / 1000);
|
|
|
+ $max_time += 3800;
|
|
|
+ if($max_time < $now) $is_close = 0;
|
|
|
+
|
|
|
+ if($is_all_close) $is_all_close = 0;
|
|
|
+ }else{
|
|
|
+ $is_close = -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($is_close < 0) {
|
|
|
+ $is_close_title = "暂未开机";
|
|
|
+ } elseif($is_close){
|
|
|
+ $is_close_title = "正在工作";
|
|
|
+ }else{
|
|
|
+ $is_close_title = "暂停工作";
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = $e_map[$v] ?? 0;
|
|
|
+ $models[$id] = [
|
|
|
+ "device_id" => $id,
|
|
|
+ "device_name" => $k,
|
|
|
+ "is_close" => $is_close,
|
|
|
+ "is_close_title" => $is_close_title,
|
|
|
+ "current_order"=> [],
|
|
|
+ "last_counting"=> [],
|
|
|
+ "now_counting"=> [],
|
|
|
+ "pending_order"=> [],
|
|
|
+ "average"=> 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前订单信息
|
|
|
+ $current_order = [];
|
|
|
+ if(! $is_all_close) $current_order = $this->getCurrentOrder();
|
|
|
+
|
|
|
+ //昨日生产
|
|
|
+ $last_counting = $this->getLastCounting();
|
|
|
+
|
|
|
+ //今日生产
|
|
|
+ $now_counting = $this->getNowCounting();
|
|
|
+
|
|
|
+ //待执行订单
|
|
|
+ $pending_order = $this->getPendingOrder();
|
|
|
+
|
|
|
+ foreach ($models as $e_id => $value){
|
|
|
+ if(isset($current_order[$e_id])) $models[$e_id]['current_order'] = $current_order[$e_id];
|
|
|
+ if(isset($last_counting[$e_id])) $models[$e_id]['last_counting'] = $last_counting[$e_id];
|
|
|
+ if(isset($pending_order[$e_id])) $models[$e_id]['pending_order'] = $pending_order[$e_id];
|
|
|
+ if(isset($now_counting[$e_id])) {
|
|
|
+ $tmp = $now_counting[$e_id] ?? [];
|
|
|
+ $models[$e_id]['now_counting'] = $tmp;
|
|
|
+ $models[$e_id]['average'] = bcdiv($tmp['finished_num'], 8);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $models = array_values($models);
|
|
|
+ usort($models, function($a, $b) {
|
|
|
+ return $b['is_close'] <=> $a['is_close'];
|
|
|
+ });
|
|
|
+
|
|
|
+ return $this->json_return(200,'', $models);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getCurrentOrder(){
|
|
|
+ $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
|
|
|
+ $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
|
|
|
+ $apply = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->where('type',ApplyOrder::type_one)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('id', array_column($apply,'data_id'))
|
|
|
+ ->select('dispatch_no','order_product_id','out_order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $equipment_map = [];
|
|
|
+ $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
|
|
|
+ ->select('dispatch_no','equipment_id','team_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($emp_sub)){
|
|
|
+ foreach ($emp_sub as $value){
|
|
|
+ if(isset($equipment_map[$value['dispatch_no']])) continue;
|
|
|
+ $equipment_map[$value['dispatch_no']] = [
|
|
|
+ 'equipment_id' => $value['equipment_id'],
|
|
|
+ 'team_id' => $value['team_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当前订单
|
|
|
+ $current_order = $team_id = [];
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $e_data = $equipment_map[$value['dispatch_no']] ?? [];
|
|
|
+ $e_id = $e_data['equipment_id'] ?? 0;
|
|
|
+ if(! $e_id || isset($current_order[$e_id])) continue;
|
|
|
+
|
|
|
+ $value['team_id'] = $e_data['team_id'];
|
|
|
+ $team_id[] = $value['team_id'];
|
|
|
+ $current_order[$e_id] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $product_no = OrdersProduct::whereIn('id', array_unique(array_column($current_order,'order_product_id')))
|
|
|
+ ->pluck('production_no','id')
|
|
|
+ ->toArray();
|
|
|
+ $team_id = array_unique($team_id);
|
|
|
+ $team_map = Team::whereIn('id', $team_id)
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $team_array = EmployeeTeamPermission::from('employee_team_permission as a')
|
|
|
+ ->leftJoin('employee as b','b.id','a.employee_id')
|
|
|
+ ->whereIn('team_id', $team_id)
|
|
|
+ ->select('b.emp_name','a.team_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($team_array as $value){
|
|
|
+ if(isset($map[$value['team_id']])){
|
|
|
+ $map[$value['team_id']] .= ',' . $value['emp_name'];
|
|
|
+ }else{
|
|
|
+ $map[$value['team_id']] = $value['emp_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($current_order as $key => $value){
|
|
|
+ $current_order[$key]['production_no'] = $product_no[$value['order_product_id']] ?? "";
|
|
|
+ $current_order[$key]['team'] = $team_map[$value['team_id']] ?? "";
|
|
|
+ $current_order[$key]['team_man'] = $map[$value['team_id']] ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $current_order;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getLastCounting(){
|
|
|
+ $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time())) - 86400;
|
|
|
+ $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time())) - 86400;
|
|
|
+ $apply = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->where('type',ApplyOrder::type_two)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::whereIn('id', array_column($apply,'data_id'))
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $equipment_map = [];
|
|
|
+ $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
|
|
|
+ ->select('dispatch_no','equipment_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($emp_sub)){
|
|
|
+ foreach ($emp_sub as $value){
|
|
|
+ if(isset($equipment_map[$value['dispatch_no']])) continue;
|
|
|
+ $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $order = [];
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
|
|
|
+ $order[$e_id][] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ foreach ($order as $e_id => $value){
|
|
|
+ $tmp = [
|
|
|
+ "finished_num" => 0,
|
|
|
+ "hg_num" => 0,
|
|
|
+ "blp_num" => 0,
|
|
|
+ "plan_num" => 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ //产出数据 合格数量
|
|
|
+ $finished_num = 0;
|
|
|
+ foreach (array_column($value,'finished_num') as $value_v){
|
|
|
+ $finished_num = bcadd($finished_num, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['finished_num'] = $tmp['hg_num'] = $finished_num;
|
|
|
+
|
|
|
+ //计划数量
|
|
|
+ $production_quantity = 0;
|
|
|
+ foreach (array_column($value,'production_quantity') as $value_v){
|
|
|
+ $production_quantity = bcadd($production_quantity, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['plan_num'] = $production_quantity;
|
|
|
+
|
|
|
+ //不良品数量
|
|
|
+ $blp = ScrappCount::where('del_time',0)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->where('dispatch_sub_id', array_column($value,'id'))
|
|
|
+ ->select('scrapp_num')
|
|
|
+ ->get()->toArray();
|
|
|
+ $scrapp_num = 0;
|
|
|
+ foreach (array_column($blp,'scrapp_num') as $value_v){
|
|
|
+ $scrapp_num = bcadd($scrapp_num, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['blp_num'] = $scrapp_num;
|
|
|
+
|
|
|
+ $return[$e_id] = $tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getNowCounting(){
|
|
|
+ //当天的开始与结束时间戳
|
|
|
+ $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
|
|
|
+ $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
|
|
|
+ $apply = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->where('type',ApplyOrder::type_two)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::whereIn('id', array_column($apply,'data_id'))
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $equipment_map = [];
|
|
|
+ $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
|
|
|
+ ->select('dispatch_no','equipment_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($emp_sub)){
|
|
|
+ foreach ($emp_sub as $value){
|
|
|
+ if(isset($equipment_map[$value['dispatch_no']])) continue;
|
|
|
+ $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $order = [];
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
|
|
|
+ $order[$e_id][] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ foreach ($order as $e_id => $value){
|
|
|
+ $tmp = [
|
|
|
+ "finished_num" => 0,
|
|
|
+ "hg_num" => 0,
|
|
|
+ "blp_num" => 0,
|
|
|
+ "plan_num" => 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ //产出数据 合格数量
|
|
|
+ $finished_num = 0;
|
|
|
+ foreach (array_column($value,'finished_num') as $value_v){
|
|
|
+ $finished_num = bcadd($finished_num, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['finished_num'] = $tmp['hg_num'] = $finished_num;
|
|
|
+
|
|
|
+ //计划数量
|
|
|
+ $production_quantity = 0;
|
|
|
+ foreach (array_column($value,'production_quantity') as $value_v){
|
|
|
+ $production_quantity = bcadd($production_quantity, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['plan_num'] = $production_quantity;
|
|
|
+
|
|
|
+ //不良品数量
|
|
|
+ $blp = ScrappCount::where('del_time',0)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->where('dispatch_sub_id', array_column($value,'id'))
|
|
|
+ ->select('scrapp_num')
|
|
|
+ ->get()->toArray();
|
|
|
+ $scrapp_num = 0;
|
|
|
+ foreach (array_column($blp,'scrapp_num') as $value_v){
|
|
|
+ $scrapp_num = bcadd($scrapp_num, $value_v,2);
|
|
|
+ }
|
|
|
+ $tmp['blp_num'] = $scrapp_num;
|
|
|
+
|
|
|
+ $return[$e_id] = $tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getPendingOrder(){
|
|
|
+ //当天的开始与结束时间戳
|
|
|
+ $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
|
|
|
+ $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->where('crt_time', '>=', $timestamp_today_start)
|
|
|
+ ->where('crt_time', '<=', $timestamp_today_end)
|
|
|
+ ->where('finished_num', 0)
|
|
|
+ ->select('dispatch_no','order_product_id','out_order_no','dispatch_quantity')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $equipment_map = [];
|
|
|
+ $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
|
|
|
+ ->select('dispatch_no','equipment_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($emp_sub)){
|
|
|
+ foreach ($emp_sub as $value){
|
|
|
+ if(isset($equipment_map[$value['dispatch_no']])) continue;
|
|
|
+ $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $product_no = OrdersProduct::whereIn('id', array_unique(array_column($dispatch,'order_product_id')))
|
|
|
+ ->pluck('production_no','id')
|
|
|
+ ->toArray();
|
|
|
+ $order = [];
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
|
|
|
+ $value['production_no'] = $product_no[$value['order_product_id']] ?? '';
|
|
|
+ $order[$e_id][] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
}
|