ReportFormsService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Employee;
  4. use App\Model\OrdersProduct;
  5. use App\Model\OrdersProductProcess;
  6. use App\Model\Scrapp;
  7. use App\Model\Team;
  8. use Illuminate\Support\Facades\DB;
  9. class ReportFormsService extends Service
  10. {
  11. //生产进度
  12. public function productionReport($data){
  13. if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
  14. //检索条件 生产订单主表----------------
  15. $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity');
  16. $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
  17. if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
  18. if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
  19. if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
  20. if(! empty($data['customer_no'])) $model->where('customer_no', 'LIKE', '%'.$data['customer_no'].'%');
  21. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  22. $orderList = $model->get()->toArray();
  23. //生产订单主表----------------
  24. //筛选出制单日期 分表的依据
  25. $out_order_no_time = array_unique(array_column($orderList,'out_order_no_time'));
  26. //制单日期
  27. $out_time = $this->checkSameQuarter($out_order_no_time);
  28. //分组以后的订单列表
  29. $list = [];
  30. foreach ($orderList as $value){
  31. if(! isset($list[$value['production_no']])){
  32. $list[$value['production_no']] = $value;
  33. }else{
  34. $list[$value['production_no']]['order_quantity'] += $value['order_quantity'];
  35. $list[$value['production_no']]['production_quantity'] += $value['production_quantity'];
  36. }
  37. }unset($orderList);
  38. //查询分表数据
  39. $production_no = array_column($list,'production_no');
  40. $detail = [];
  41. $process_id = $data['process_id'] ?? [];
  42. foreach ($out_time as $value){
  43. //子表搜索
  44. $models = new OrdersProductProcess(['channel' => $value]);
  45. $tmp = $models->whereIn('production_no',$production_no)
  46. ->where('del_time',0)
  47. ->whereIn('status',array(1,2))
  48. ->when(!empty($process_id), function ($query) use ($process_id) {
  49. return $query->whereIn('process_id', $process_id);
  50. })
  51. ->select('production_no','process_id',DB::raw('SUM(CASE WHEN status >= 1 THEN 1 ELSE 0 END) as dispatch_count'),DB::raw('SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as finish_count'))
  52. ->groupBy('production_no','process_id')
  53. ->get()->toArray();//派工和完工数据
  54. foreach ($tmp as $t){
  55. $keys = $t['production_no'] . "|" .$t['process_id'];
  56. if(isset($detail[$keys])){
  57. $detail[$keys]['dispatch_count'] += $t['dispatch_count'];
  58. $detail[$keys]['finish_count'] += $t['finish_count'];
  59. }else{
  60. $detail[$keys] = $t;
  61. }
  62. }
  63. }
  64. //返回统计数据
  65. date_default_timezone_set("PRC");
  66. foreach ($list as $key => $value) {
  67. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  68. $list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
  69. $detail_key = $value['production_no'] . "|";
  70. foreach ($detail as $key_son => $value_son) {
  71. if (strpos($key_son,$detail_key) !== false) {
  72. $value_son['rate'] = number_format($value_son['finish_count'] / $value['order_quantity'], 2);
  73. $list[$key]['process'][] = $value_son;
  74. }
  75. }
  76. if(empty($list[$key]['process'])) unset($list[$key]);
  77. }
  78. return [true,array_values($list)];
  79. }
  80. private function checkSameQuarter($timestamps) {
  81. date_default_timezone_set("PRC");
  82. $quarters = $out_time = [];
  83. foreach ($timestamps as $timestamp) {
  84. $date = date('Ym', $timestamp);
  85. $year = intval(date('Y', $timestamp));
  86. $quarter = ceil(intval(date('n', $timestamp)) / 3);
  87. if(! isset($quarters[$year]) || ! in_array($quarter,$quarters[$year])){
  88. $quarters[$year][] = $quarter;
  89. $out_time[] = $date;
  90. }
  91. }
  92. return $out_time;
  93. }
  94. //班组
  95. public function teamReport($data){
  96. if(empty($data['finish_time'][0]) || empty($data['finish_time'][1])) return [false, '完工时间必须选择!'];
  97. //班组
  98. $team_id = $data['team_id'] ?? [];
  99. //根据完工时间 扩大时间戳范围前后三个月
  100. $new_finish_time = $this->increaseTimeArea($data['finish_time']);
  101. //根据时间戳范围 获取分表的时间
  102. $return_time = $this->getTimeAreaData($new_finish_time);
  103. //检索分表数据
  104. $result = $team = [];
  105. foreach ($return_time as $value){
  106. //子表搜索
  107. $models = new OrdersProductProcess(['channel' => $value]);
  108. $tmp = $models->where('del_time',0)
  109. ->whereBetween('finished_time',[$data['finish_time'][0], $data['finish_time'][1]])
  110. ->where('status',2)
  111. ->when(!empty($team_id), function ($query) use ($team_id) {
  112. return $query->whereIn('team_id', $team_id);
  113. })
  114. ->select('team_id','finished_time','production_no')
  115. ->get()->toArray();//完工数据
  116. $result = array_merge_recursive($result,$tmp);
  117. $team = array_merge_recursive($team,array_unique(array_column($tmp,'team_id')));
  118. }
  119. if(empty($result)) return [true , []];
  120. //组织数据
  121. $team_map = Team::whereIn('id',array_unique($team))
  122. ->pluck('title','id')
  123. ->toArray();
  124. $return_team = $return_team_time_tmp = $return_team_time= [];
  125. date_default_timezone_set("PRC");
  126. foreach ($result as $value){
  127. if(isset($return_team[$value['team_id']])){
  128. $return_team[$value['team_id']]['num'] += 1;
  129. if(! in_array($value['production_no'], $return_team[$value['team_id']]['production_no'])) {
  130. $return_team[$value['team_id']]['production_no'] = array_merge_recursive($return_team[$value['team_id']]['production_no'],[$value['production_no']]);
  131. }
  132. }else{
  133. $return_team[$value['team_id']] = [
  134. 'num' => 1,
  135. 'team_name' => $team_map[$value['team_id']] ?? '',
  136. 'production_no' => [$value['production_no']]
  137. ];
  138. }
  139. $tmp = date("Y-m-d",$value['finished_time']);
  140. if(isset($return_team_time_tmp[$tmp][$value['team_id']])){
  141. $return_team_time_tmp[$tmp][$value['team_id']]['num'] += 1;
  142. }else{
  143. $return_team_time_tmp[$tmp][$value['team_id']] = [
  144. 'time' => $tmp,
  145. 'num' => 1,
  146. 'team_name' => $team_map[$value['team_id']] ?? '',
  147. ];
  148. }
  149. }ksort($return_team_time_tmp);unset($result);
  150. $all_team_map = Team::where('del_time',0)
  151. ->pluck('title','id')
  152. ->toArray();
  153. foreach ($return_team_time_tmp as $key => $value){
  154. $t_k = array_keys($value);
  155. foreach ($all_team_map as $k => $v){
  156. if(! in_array($k,$t_k)){
  157. $return_team_time_tmp[$key][$k] = [
  158. 'time' => $key,
  159. 'num' => 0,
  160. 'team_name' => $v,
  161. ];
  162. }
  163. }
  164. ksort($return_team_time_tmp[$key]);
  165. $tmp = [];
  166. $tmp['time'] = $key;
  167. $tmp['sub'] = array_values($return_team_time_tmp[$key]);
  168. $return_team_time[] = $tmp;
  169. }unset($return_team_time_tmp);
  170. //列表数据 图表数据
  171. return [true,['list'=>array_values($return_team),'chart'=>$return_team_time]];
  172. }
  173. private function increaseTimeArea($time_area){
  174. // 增加三个月的时间戳
  175. $newStartTimestamp = strtotime('-3 months', $time_area[0]);
  176. $newEndTimestamp = strtotime('+3 months', $time_area[1]);
  177. return [$newStartTimestamp,$newEndTimestamp];
  178. }
  179. private function getTimeAreaData($time_area){
  180. $startYear = date('Y', $time_area[0]);
  181. $endYear = date('Y', $time_area[1]);
  182. $return = [];
  183. for ($year = $startYear; $year <= $endYear; $year++) {
  184. for ($quarter = 1; $quarter <= 4; $quarter++) {
  185. $quarterStart = strtotime($year . '-' . (($quarter - 1) * 3 + 1) . '-01');
  186. $quarterEnd = strtotime($year . '-' . ($quarter * 3) . '-01') - 1;
  187. if ($quarterStart <= $time_area[1] && $quarterEnd >= $time_area[0]) {
  188. // $tmp = $year . sprintf('%02d', $quarter);//年季度
  189. $return[] = $year .sprintf('%02d',($quarter - 1) * 3 + 1);
  190. }
  191. }
  192. }
  193. return $return;
  194. }
  195. //班组 详情
  196. public function teamReportDetail($data){
  197. if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
  198. $list = OrdersProduct::whereIn('production_no',$data['production_no'])
  199. ->select('production_time','production_no','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark')
  200. ->get()->toArray();
  201. date_default_timezone_set("PRC");
  202. foreach ($list as $key => $value) {
  203. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  204. }
  205. return [true,$list];
  206. }
  207. //不良品
  208. public function badGoodsReport($data){
  209. if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
  210. //检索条件 生产订单主表----------------
  211. $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man');
  212. $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
  213. if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
  214. if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
  215. if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
  216. if(! empty($data['customer_no'])) $model->where('customer_no', 'LIKE', '%'.$data['customer_no'].'%');
  217. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  218. if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
  219. $orderList = $model->get()->toArray();
  220. //生产订单主表----------------
  221. //筛选出制单日期 分表的依据
  222. $out_order_no_time = array_unique(array_column($orderList,'out_order_no_time'));
  223. //制单日期
  224. $out_time = $this->checkSameQuarter($out_order_no_time);
  225. //分组以后的订单列表
  226. $list = [];
  227. foreach ($orderList as $value){
  228. if(! isset($list[$value['production_no']])){
  229. $list[$value['production_no']] = $value;
  230. }else{
  231. $list[$value['production_no']]['order_quantity'] += $value['order_quantity'];
  232. $list[$value['production_no']]['production_quantity'] += $value['production_quantity'];
  233. }
  234. }unset($orderList);
  235. //查询分表数据
  236. $production_no = array_column($list,'production_no');
  237. $detail = [];
  238. foreach ($out_time as $value){
  239. //子表搜索
  240. $models = new OrdersProductProcess(['channel' => $value]);
  241. $tmp = $models->whereIn('production_no',$production_no)
  242. ->where('del_time',0)
  243. ->where('status',4)
  244. ->select('production_no',DB::raw('COUNT(id) as bad_goods_num'))
  245. ->groupBy('production_no')
  246. ->get()->toArray();//不良品数据
  247. foreach ($tmp as $t){
  248. if(isset($detail[$t['production_no']])){
  249. $detail[$t['production_no']]['bad_goods_num'] += $t['bad_goods_num'];
  250. }else{
  251. $detail[$t['production_no']] = $t;
  252. }
  253. }
  254. }
  255. //返回统计数据
  256. date_default_timezone_set("PRC");
  257. foreach ($list as $key => $value) {
  258. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  259. $list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
  260. $del_num = $detail[$value['production_no']] ?? 0;
  261. $list[$key]['bad_goods_num'] = $del_num;
  262. $list[$key]['rate'] = number_format($del_num / $value['production_quantity'], 2);
  263. }
  264. return [true,array_values($list)];
  265. }
  266. //不良品 详情
  267. public function badGoodsReportDetail($data){
  268. if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
  269. $list = OrdersProduct::where('production_no',$data['production_no'])
  270. ->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity')
  271. ->get()->toArray();
  272. //筛选出制单日期 分表的依据
  273. $out_order_no_time = array_unique(array_column($list,'out_order_no_time'));
  274. //制单日期
  275. $out_time = $this->checkSameQuarter($out_order_no_time);
  276. $detail = $detail_scrapp = [];
  277. foreach ($out_time as $value){
  278. //子表搜索
  279. $models = new OrdersProductProcess(['channel' => $value]);
  280. $tmp = $models->where('production_no',$data['production_no'])
  281. ->where('del_time',0)
  282. ->where('status',4)
  283. ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'), DB::raw("GROUP_CONCAT(DISTINCT scrapp_id ORDER BY scrapp_id SEPARATOR ',') as scrapp_ids"))
  284. ->groupBy('order_product_id')
  285. ->get()
  286. ->toArray();//不良品数据
  287. foreach ($tmp as $v){
  288. if(isset($detail[$v['order_product_id']])){
  289. $detail[$v['order_product_id']] += $v['bad_goods_num'];
  290. }else{
  291. $detail[$v['order_product_id']] = $v['bad_goods_num'];
  292. }
  293. if(isset($detail_scrapp[$v['order_product_id']])){
  294. $detail_scrapp[$v['order_product_id']] .= "," . $v['scrapp_ids'];
  295. }else{
  296. $detail_scrapp[$v['order_product_id']] = $v['scrapp_ids'];
  297. }
  298. }
  299. }
  300. date_default_timezone_set("PRC");
  301. $scrapp_map = Scrapp::where('del_time',0)->pluck('title','id')->toArray();
  302. foreach ($list as $key => $value) {
  303. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  304. $list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
  305. $list[$key]['bad_goods_num'] = $detail[$value['id']] ?? 0;
  306. $list[$key]['rate'] = number_format($list[$key]['bad_goods_num'] / $value['production_quantity'], 2);
  307. $scrapp = $detail_scrapp[$value['id']] ?? '';
  308. $tmp_str = '';
  309. if(! empty($scrapp)){
  310. $tmp = explode(',',$scrapp);
  311. foreach ($tmp as $vv){
  312. $tmp_str .= ($scrapp_map[$vv] ? $scrapp_map[$vv] . ',' : '');
  313. }
  314. }
  315. $list[$key]['scrapp_name'] = rtrim($tmp_str,',');
  316. }
  317. return [true, $list];
  318. }
  319. //不良品原因
  320. public function badGoodsReasonReport($data){
  321. if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
  322. //检索条件 生产订单主表----------------
  323. $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man');
  324. $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
  325. if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
  326. if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
  327. if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
  328. if(! empty($data['customer_no'])) $model->where('customer_no', 'LIKE', '%'.$data['customer_no'].'%');
  329. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  330. if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
  331. $orderList = $model->get()->toArray();
  332. //生产订单主表----------------
  333. //筛选出制单日期 分表的依据
  334. $out_order_no_time = array_unique(array_column($orderList,'out_order_no_time'));
  335. //制单日期
  336. $out_time = $this->checkSameQuarter($out_order_no_time);
  337. //分组以后的订单列表
  338. $list = [];
  339. foreach ($orderList as $value){
  340. if(! isset($list[$value['production_no']])){
  341. $list[$value['production_no']] = $value;
  342. }else{
  343. $list[$value['production_no']]['order_quantity'] += $value['order_quantity'];
  344. $list[$value['production_no']]['production_quantity'] += $value['production_quantity'];
  345. }
  346. }unset($orderList);
  347. //查询分表数据
  348. $production_no = array_column($list,'production_no');
  349. $detail = [];
  350. foreach ($out_time as $value){
  351. //子表搜索
  352. $models = new OrdersProductProcess(['channel' => $value]);
  353. $tmp = $models->whereIn('production_no',$production_no)
  354. ->where('del_time',0)
  355. ->where('status',4)
  356. ->select('production_no',DB::raw('COUNT(id) as bad_goods_num'))
  357. ->groupBy('production_no')
  358. ->get()->toArray();//不良品数据
  359. foreach ($tmp as $t){
  360. if(isset($detail[$t['production_no']])){
  361. $detail[$t['production_no']]['bad_goods_num'] += $t['bad_goods_num'];
  362. }else{
  363. $detail[$t['production_no']] = $t;
  364. }
  365. }
  366. }
  367. //返回统计数据
  368. date_default_timezone_set("PRC");
  369. foreach ($list as $key => $value) {
  370. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  371. $list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
  372. $del_num = $detail[$value['production_no']] ?? 0;
  373. $list[$key]['bad_goods_num'] = $del_num;
  374. $list[$key]['rate'] = number_format($del_num / $value['production_quantity'], 2);
  375. }
  376. return [true,array_values($list)];
  377. }
  378. //不良品原因 详情
  379. public function badGoodsReasonReportDetail($data){
  380. if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
  381. $list = OrdersProduct::where('production_no',$data['production_no'])
  382. ->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity')
  383. ->get()->toArray();
  384. //筛选出制单日期 分表的依据
  385. $out_order_no_time = array_unique(array_column($list,'out_order_no_time'));
  386. //制单日期
  387. $out_time = $this->checkSameQuarter($out_order_no_time);
  388. $detail = $scrapp_id = $team = $man = [];
  389. foreach ($out_time as $value){
  390. //子表搜索
  391. $models = new OrdersProductProcess(['channel' => $value]);
  392. $tmp = $models->where('production_no',$data['production_no'])
  393. ->where('del_time',0)
  394. ->where('status',4)
  395. ->select('order_product_id','scrapp_id','team_id','finished_id',DB::raw('COUNT(id) as bad_goods_num'))
  396. ->groupBy('order_product_id','scrapp_id')
  397. ->get()->toArray();//不良品数据
  398. foreach ($tmp as $v){
  399. if(! in_array($v['scrapp_id'], $scrapp_id)) $scrapp_id[] = $v['scrapp_id'];
  400. if(! in_array($v['team_id'], $team)) $team[] = $v['team_id'];
  401. if(! in_array($v['finished_id'], $man)) $man[] = $v['finished_id'];
  402. if(isset($detail[$v['order_product_id']])){
  403. foreach ($detail[$v['order_product_id']] as $k => $d){
  404. if($d['scrapp_id'] == $v['scrapp_id']){
  405. $detail[$v['order_product_id']][$k]['bad_goods_num'] += $v['bad_goods_num'];
  406. }else{
  407. $detail[$v['order_product_id']][] = $v;
  408. }
  409. }
  410. }else{
  411. $detail[$v['order_product_id']][] = $v;
  412. }
  413. }
  414. }
  415. date_default_timezone_set("PRC");
  416. //次品原因 班组 人员
  417. $map = Scrapp::whereIn('id',$scrapp_id)
  418. ->pluck('title','id')
  419. ->toArray();
  420. $map1 = Team::whereIn('id',$team)
  421. ->pluck('title','id')
  422. ->toArray();
  423. $map2 = Employee::whereIn('id',$man)
  424. ->pluck('emp_name','id')
  425. ->toArray();
  426. foreach ($list as $key => $value) {
  427. $list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  428. $list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
  429. $list[$key]['rate'] = number_format(($detail[$value['id']] ?? 0) / $value['production_quantity'], 2);
  430. $del_tmp = $detail[$value['id']] ?? [];
  431. foreach ($del_tmp as $dk => $dv){
  432. $del_tmp[$dk]['rate'] = number_format($dv['bad_goods_num'] / $value['production_quantity'], 2);
  433. $del_tmp[$dk]['scrapp_name'] = $map[$dv['scrapp_id']] ?? '';
  434. $del_tmp[$dk]['team_name'] = $map1[$dv['team_id']] ?? '';
  435. $del_tmp[$dk]['man_name'] = $map2[$dv['finished_id']] ?? '';
  436. }
  437. $list[$key]['bad_goods'] = $del_tmp;
  438. }
  439. return [true, $list];
  440. }
  441. }