订单组日工作量报表数据生成优化

xiaoxiao2021-02-28  26

class Order_Service_OrderWorkload { /* * 生成订单组日工作量数据 * * $startDate 0000-00-00 00:00:00 开始时间 * $endDate 0000-00-00 00:00:00 结束时间 */ public static function generateOrderWorkload($startDate, $endDate) { try { $combination = array( 'op_start_time' => $startDate, 'pickup_finish_time' => $endDate, 'op_status' => 1, ); $combinat = array( 'op_pack_start' => $startDate, 'op_pack_end' => $endDate, 'op_status' => 1, ); $combin = array( 'op_sorting_start' => $startDate, 'op_sorting_end' => $endDate, 'op_status' => 1, ); //根据订单类型分别计算订单最大可用订单票数 //A类 $configIdA = Common_Service_Config::getByAttribute(self::$MaxSortNumber[0]); if ($configIdA && $configIdA['config_value']) { $maximumUsableA = $configIdA['config_value']; } else { throw new Exception('请配置系统订单类型最大可用订单票数 '. self::$MaxSortNumber[0]); } //B类 $configIdB = Common_Service_Config::getByAttribute(self::$MaxSortNumber[1]); if ($configIdB && $configIdB['config_value']) { $maximumUsableB = $configIdB['config_value']; } else { throw new Exception('请配置系统订单类型最大可用订单票数 '. self::$MaxSortNumber[1]); } //C类 $configIdC = Common_Service_Config::getByAttribute(self::$MaxSortNumber[2]); if ($configIdC && $configIdC['config_value']) { $maximumUsableC = $configIdC['config_value']; } else { throw new Exception('请配置系统订单类型最大可用订单票数 '. self::$MaxSortNumber[2]); } //配货 $peihuos = Product_Service_Pickup::getByCondition($combination, '*'); if ($peihuos) { self::generate($peihuos, $maximumUsableA, $maximumUsableB, $maximumUsableC, $startDate, 0); } //打包 $packings = Product_Service_Pickup::getByCondition($combinat, '*'); if ($packings) { self::generate($packings, $maximumUsableA, $maximumUsableB, $maximumUsableC, $startDate, 1); } //分拣 $sorters = Product_Service_Pickup::getByCondition($combin, '*'); if ($sorters) { self::generate($sorters, $maximumUsableA, $maximumUsableB, $maximumUsableC, $startDate, 2); } } catch (Exception $ex) { echo '[ ' . date('Y-m-d H:i:s') . ' ] 出现异常,异常信息为:' . $ex->getMessage() . "\r\n"; } } /* * 生成数据 * * $combination array() 查询结果数据 * $maximumUsableA Integer A 类订单最大可用订单票数 * $maximumUsableB Integer B 类订单最大可用订单票数 * $maximumUsableC Integer C 类订单最大可用订单票数 * $startDate 0000-00-00 开始时间 * $post Integer 岗位人员 */ public static function generate($combination, $maximumUsableA, $maximumUsableB, $maximumUsableC, $startDate, $post) { $data = array(); foreach ($combination as $value) { $type = $value['op_orders_type']; $warehouseId = $value['warehouse_id']; $opmId = Order_Service_OrderPickupMap::getByfield('op_code', $value['op_code']); if ($opmId) { $row = array(); foreach ($opmId as $valu) { $row[] = $valu['orders_code']; } $countCode = count(array_unique($row)); } //根据订单类型计算花费时间、标准配置时间、岗位人员 $time = 0; if ($post == 0) { if ($value['pickup_finish_time'] != '0000-00-00 00:00:00' && $value['op_start_time'] != '0000-00-00 00:00:00') { $time = round((strtotime($value['pickup_finish_time']) - strtotime($value['op_start_time'])) / 60, 0); } $configId = Common_Service_Config::getByAttribute(self::$StandardConfigurationTime[0], $warehouseId); $userIds = $value['pickup_user_id']; } else if ($post == 1) { if ($value['op_pack_end'] != '0000-00-00 00:00:00' && $value['op_pack_start'] != '0000-00-00 00:00:00') { $time = ceil((strtotime($value['op_pack_end']) - strtotime($value['op_pack_start'])) / 60); } $configId = Common_Service_Config::getByAttribute(self::$StandardConfigurationTime[1], $warehouseId); $userIds = $value['package_user_id']; } else { if ($value['op_sorting_end'] != '0000-00-00 00:00:00' && $value['op_sorting_start'] != '0000-00-00 00:00:00') { $time = ceil((strtotime($value['op_sorting_end']) - strtotime($value['op_sorting_start'])) / 60); } $configId = Common_Service_Config::getByAttribute(self::$StandardConfigurationTime[2], $warehouseId); $userIds = $value['op_sorting_user']; } //根据岗位人员账号开通时间查询属于哪个时期 if ($userIds) { $userId = User_Service_User::getByUserId($userIds); if ($userId && $userId['create_date']) { //培训期 $trainDate = date('Y-m-d H:i:s', strtotime('+10 day', strtotime($userId['create_date']))); //试岗期 $tryDate = date('Y-m-d H:i:s', strtotime('+20 day', strtotime($userId['create_date']))); //上岗期 $postsDate = date('Y-m-d H:i:s', strtotime('+30 day', strtotime($userId['create_date']))); } //根据时期计算超时票数 $count = 0; if ($configId && $configId['config_value']) { $configValueInfo = unserialize($configId['config_value']); if ($value['op_pack_start'] <= $trainDate) { if (!empty($configValueInfo['trainA']) && $type == 0 && $configValueInfo['trainA'] <= $time) { $count = 1; } if (!empty($configValueInfo['trainB']) && $type == 1 && $configValueInfo['trainB'] <= $time) { $count = 1; } if (!empty($configValueInfo['trainC']) && $type == 2 && $configValueInfo['trainC'] <= $time) { $count = 1; } } else if ($value['op_pack_start'] > $trainDate && $value['op_pack_start'] <= $tryDate) { if (!empty($configValueInfo['try_hillockA']) && $type == 0 && $configValueInfo['try_hillockA'] <= $time) { $count = 1; } if (!empty($configValueInfo['try_hillockB']) && $type == 1 && $configValueInfo['try_hillockB'] <= $time) { $count = 1; } if (!empty($configValueInfo['try_hillockC']) && $type == 2 && $configValueInfo['try_hillockC'] <= $time) { $count = 1; } } else if ($value['op_pack_start'] > $tryDate && $value['op_pack_start'] <= $postsDate) { if (!empty($configValueInfo['postsA']) && $type == 0 && $configValueInfo['postsA'] <= $time) { $count = 1; } if (!empty($configValueInfo['postsB']) && $type == 1 && $configValueInfo['postsB'] <= $time) { $count = 1; } if (!empty($configValueInfo['postsC']) && $type == 2 && $configValueInfo['postsC'] <= $time) { $count = 1; } } else if ($value['op_pack_start'] > $postsDate) { if (!empty($configValueInfo['matureA']) && $type == 0 && $configValueInfo['matureA'] <= $time) { $count = 1; } if (!empty($configValueInfo['matureB']) && $type == 1 && $configValueInfo['matureB'] <= $time) { $count = 1; } if (!empty($configValueInfo['matureC']) && $type == 2 && $configValueInfo['matureC'] <= $time) { $count = 1; } } } //根据岗位人员和订单类型仓库作为键、组成四维数组,如果有相同的键,就把对应值相加 if (isset($data[$userIds . '-' . $post][$type][$warehouseId])) { if ($type == 0 && $countCode >= $maximumUsableA) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] += $count; } else if ($type == 1 && $countCode >= $maximumUsableB) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] += $count; } else if ($type == 2 && $countCode >= $maximumUsableC) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] += $count; } $data[$userIds . '-' . $post][$type][$warehouseId]['ow_more'] += $value['op_more']; $data[$userIds . '-' . $post][$type][$warehouseId]['ow_wrong'] += $value['op_wrong']; $data[$userIds . '-' . $post][$type][$warehouseId]['ow_leakage'] += $value['op_leakage']; } else { if ($type == 0 && $countCode >= $maximumUsableA) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] = $count; } else if ($type == 1 && $countCode >= $maximumUsableB) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] = $count; } else if ($type == 2 && $countCode >= $maximumUsableC) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_overtime_qty'] = $count; } $data[$userIds . '-' . $post][$type][$warehouseId]['ow_more'] = $value['op_more']; $data[$userIds . '-' . $post][$type][$warehouseId]['ow_wrong'] = $value['op_wrong']; $data[$userIds . '-' . $post][$type][$warehouseId]['ow_leakage'] = $value['op_leakage']; } if ($type == 0 && $countCode >= $maximumUsableA) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_orders'] += 1; $data[$userIds . '-' . $post][$type][$warehouseId]['total_time'][] = $time; } else if ($type == 1 && $countCode >= $maximumUsableB) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_orders'] += 1; $data[$userIds . '-' . $post][$type][$warehouseId]['total_time'][] = $time; } else if ($type == 2 && $countCode >= $maximumUsableC) { $data[$userIds . '-' . $post][$type][$warehouseId]['ow_orders'] += 1; $data[$userIds . '-' . $post][$type][$warehouseId]['total_time'][] = $time; } $data[$userIds . '-' . $post][$type][$warehouseId]['ow_total_pickup'] += 1; } } //分解数组写入数据库 if ($data) { foreach ($data as $key => $val) { foreach ($val as $ke => $va) { foreach ($va as $k => $v) { $combinat = array( 'user_id' => $key, 'warehouse_id' => $k, 'ow_date' => $startDate, 'ow_total_pickup' => $v['ow_total_pickup'], 'ow_type' => $ke, 'ow_fast' => isset($v['total_time']) ? min($v['total_time']) : 0, 'ow_avg' => empty($v['ow_orders']) ? 0 : round(array_sum($v['total_time']) / $v['ow_orders']), 'ow_slow' => isset($v['total_time']) ? max($v['total_time']) : 0, 'ow_orders' => isset($v['ow_orders']) ? $v['ow_orders'] : 0, 'ow_overtime_qty' => isset($v['ow_overtime_qty']) ? $v['ow_overtime_qty'] : 0, 'ow_more' => $v['ow_more'], 'ow_wrong' => $v['ow_wrong'], 'ow_leakage' => $v['ow_leakage'], 'ow_create_time' => date('Y-m-d H:i:s'), 'ow_post' => $post, ); if (!Order_Service_OrderWorkload::add($combinat)) { return '写入数据失败'; } } } } } } }
转载请注明原文地址: https://www.6miu.com/read-2600146.html

最新回复(0)