|
@@ -40,6 +40,21 @@ class LargeScreenService extends Service
|
|
|
->where('crt_time', "<=", strtotime(date("Y-m-t 23:59:59")))
|
|
|
->select(DB::raw('sum(order_quantity) as order_quantity'))
|
|
|
->value('order_quantity');
|
|
|
+ $device_map = [
|
|
|
+ 8 => 0.618,
|
|
|
+ 9 => 0.615,
|
|
|
+ 12 => 0.625,
|
|
|
+ 13 => 0.623,
|
|
|
+ ];
|
|
|
+ $today_total = 0;
|
|
|
+ $e = Equipment::where('del_time',0)->where('status',1)->get()->toArray();
|
|
|
+ foreach ($e as $value){
|
|
|
+ if(isset($device_map[$value['id']])){
|
|
|
+ $today_hours = (int)(time() / 3600) - (int)(strtotime('today') / 3600);
|
|
|
+ $tmp = bcmul($device_map[$value['id']], $today_hours,3);
|
|
|
+ $today_total = bcadd($tmp, $today_total,3);
|
|
|
+ }
|
|
|
+ }
|
|
|
$box = new BoxDetail(['channel'=>date("Ymd")]);
|
|
|
$data_one = $box->where('del_time', 0)
|
|
|
->where('crt_time', ">=", strtotime(date("Y-m-01 00:00:00")))
|
|
@@ -47,12 +62,11 @@ class LargeScreenService extends Service
|
|
|
->select('num as quantity', 'crt_time')
|
|
|
->get()->toArray();
|
|
|
//当日产量 当月产量
|
|
|
- $today_total = $month_total = 0;
|
|
|
+ $month_total = 0;
|
|
|
$timeStamp = strtotime(date("Y-m-d 00:00:00"));
|
|
|
$timeStampE = strtotime(date("Y-m-d 23:59:59"));
|
|
|
foreach ($data_one as $value) {
|
|
|
$month_total = bcadd($month_total, $value['quantity'], 3);
|
|
|
- if ($timeStamp <= $value['crt_time'] && $timeStampE >= $value['crt_time']) $today_total = bcadd($today_total, $value['quantity'], 3);
|
|
|
}
|
|
|
//当日产量 当月产量 ---------------------------------------------
|
|
|
|
|
@@ -840,6 +854,67 @@ class LargeScreenService extends Service
|
|
|
12 => 0.625,
|
|
|
13 => 0.623,
|
|
|
];
|
|
|
+
|
|
|
+ $orders = DeviceOrderInfo::from('device_order_info as a')
|
|
|
+ ->join('device_order as b','a.device_order_id','b.id')
|
|
|
+ ->where('a.type',3)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('b.hand_time','>=', strtotime('first day of last month 00:00:00'))
|
|
|
+ ->where('b.hand_time',"<=", time())
|
|
|
+ ->select('a.equipment_id as device_id','b.hand_time as crt_time')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ // 初始化统计数组
|
|
|
+ $todayCount = [];
|
|
|
+ $lastWeekCount = [];
|
|
|
+ $lastMonthCount = [];
|
|
|
+
|
|
|
+ foreach ($orders as $order) {
|
|
|
+ $deviceId = $order['device_id'];
|
|
|
+ $crtTime = $order['crt_time'];
|
|
|
+
|
|
|
+ // 统计当日
|
|
|
+ if ($crtTime >= $todayStart) {
|
|
|
+ if (!isset($todayCount[$deviceId])) {
|
|
|
+ $todayCount[$deviceId] = 0;
|
|
|
+ }
|
|
|
+ $todayCount[$deviceId]++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计上一周
|
|
|
+ if ($crtTime >= $lastWeekStart && $crtTime < $todayStart) {
|
|
|
+ if (!isset($lastWeekCount[$deviceId])) {
|
|
|
+ $lastWeekCount[$deviceId] = 0;
|
|
|
+ }
|
|
|
+ $lastWeekCount[$deviceId]++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计上一个月
|
|
|
+ if ($crtTime >= $lastMonthStart && $crtTime < $lastWeekStart) {
|
|
|
+ if (!isset($lastMonthCount[$deviceId])) {
|
|
|
+ $lastMonthCount[$deviceId] = 0;
|
|
|
+ }
|
|
|
+ $lastMonthCount[$deviceId]++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并结果
|
|
|
+ $result_wx = [];
|
|
|
+ $allDeviceIds = array_unique(array_merge(
|
|
|
+ array_keys($todayCount),
|
|
|
+ array_keys($lastWeekCount),
|
|
|
+ array_keys($lastMonthCount)
|
|
|
+ ));
|
|
|
+
|
|
|
+ foreach ($allDeviceIds as $deviceId) {
|
|
|
+ $result_wx[$deviceId] = [
|
|
|
+ 'today' => $todayCount[$deviceId] ?? 0,
|
|
|
+ 'last_week' => $lastWeekCount[$deviceId] ?? 0,
|
|
|
+ 'last_month' => $lastMonthCount[$deviceId] ?? 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($byDeviceDay as $device => $days) {
|
|
|
$todayHours = $lastWeekHours = $lastMonthHours = 0.0;
|
|
|
|
|
@@ -894,10 +969,9 @@ class LargeScreenService extends Service
|
|
|
$last_week_hour = round($lastWeekHours, 2);
|
|
|
$last_month_hour = round($lastMonthHours, 2);
|
|
|
|
|
|
- $last_week_emergency = 0;
|
|
|
- if($lastWeekHours >= 100) $last_week_emergency = 1;
|
|
|
- $last_month_emergency = 0;
|
|
|
- if($last_month_hour >= 300) $last_month_emergency = 3;
|
|
|
+ $wx = $result_wx[$device_id] ?? [];
|
|
|
+ $last_week_emergency = $wx['last_week'] ?? 0;
|
|
|
+ $last_month_emergency = $wx['last_month'] ?? 0;
|
|
|
|
|
|
$result[] = array_merge([
|
|
|
'device_name' => $device,
|