ScrappService.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. namespace App\Service;
  3. use App\Model\DispatchSub;
  4. use App\Model\Employee;
  5. use App\Model\EmployeeTeamPermission;
  6. use App\Model\Equipment;
  7. use App\Model\OrdersProduct;
  8. use App\Model\Process;
  9. use App\Model\ReportWorking;
  10. use App\Model\ReportWorkingDetail;
  11. use App\Model\SaleOrdersProduct;
  12. use App\Model\Scrapp;
  13. use App\Model\ScrappCount;
  14. use App\Model\Team;
  15. use App\Model\Zj;
  16. use App\Model\ZjPlan;
  17. use Illuminate\Support\Facades\DB;
  18. /**
  19. * 报废原因
  20. * @package App\Models
  21. */
  22. class ScrappService extends Service
  23. {
  24. public function scrappEdit($data){
  25. list($status,$msg) = $this->scrappRule($data,false);
  26. if(!$status) return [$status,$msg];
  27. $update = $msg['data'][0];
  28. Scrapp::where('id',$data['id'])->update($update);
  29. return [true,'保存成功!'];
  30. }
  31. public function scrappAdd($data){
  32. list($status,$msg) = $this->scrappRule($data);
  33. if(!$status) return [$status,$msg];
  34. Scrapp::insert($msg['data']);
  35. return [true,'保存成功!'];
  36. }
  37. public function scrappDel($data){
  38. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  39. Scrapp::whereIn('id',$data['id'])->update([
  40. 'del_time' => time()
  41. ]);
  42. return [true,'删除成功'];
  43. }
  44. public function scrappList($data){
  45. $model = Scrapp::where('del_time',0)
  46. ->select('*');
  47. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  48. $list = $this->limit($model,'',$data);
  49. return [200,$list];
  50. }
  51. public function zjdaList($data){
  52. $model = Zj::where('del_time',0)
  53. ->select('*');
  54. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  55. $list = $this->limit($model,'',$data);
  56. return [200,$list];
  57. }
  58. public function zjPlanList($data){
  59. $model = ZjPlan::where('del_time',0)
  60. ->select('*');
  61. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  62. $list = $this->limit($model,'',$data);
  63. $map = Zj::where('del_time',0)->pluck('title','id')->toArray();
  64. foreach ($list['data'] as $key => $value){
  65. $zj_plan_title = "";
  66. $tmp = explode(',', $value['zj_id']);
  67. foreach ($tmp as $v){
  68. $t = $map[$v];
  69. if(empty($t)) continue;
  70. $zj_plan_title .= $t . ",";
  71. }
  72. $list['data'][$key]['zj_plan_title'] = rtrim($zj_plan_title,',');
  73. }
  74. return [200,$list];
  75. }
  76. public function scrappRule($data,$is_add = true){
  77. if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
  78. $title = array_column($data['data'],'title');
  79. $title = array_map(function($val) {
  80. return $val !== null ? $val : 0;
  81. }, $title);
  82. $title_count = array_count_values($title);
  83. foreach ($title as $value){
  84. if(empty($value)) return [false,'名称不能为空!'];
  85. if($title_count[$value] > 1) return [false,'名称不能重复'];
  86. }
  87. foreach ($data['data'] as $key => $value){
  88. $data['data'][$key]['upd_time'] = time();
  89. if($is_add){
  90. $bool = Scrapp::whereRaw("title = '{$value['title']}'")
  91. ->where('del_time',0)
  92. ->exists();
  93. $data['data'][$key]['crt_time'] = time();
  94. }else{
  95. if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
  96. $bool = Scrapp::whereRaw("title = '{$value['title']}'")
  97. ->where('id','<>',$data['id'])
  98. ->where('del_time',0)
  99. ->exists();
  100. }
  101. if($bool) return [false,'名称不能重复'];
  102. }
  103. return [true,$data];
  104. }
  105. //质检单
  106. public function zjList($data, $user){
  107. $process = Process::where('del_time',0)
  108. ->where('is_need_remain',1)
  109. ->pluck('id')
  110. ->toArray();
  111. $model = ScrappCount::where('del_time',0)
  112. ->whereIn('process_id', $process)
  113. ->select('*')
  114. ->orderBy('order_number','desc');
  115. if(! empty($data['sq'])) $model->where('result',ReportWorking::type_two);
  116. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  117. if(! empty($data['dispatch_no'])) {
  118. $dispatch_id = DispatchSub::where('del_time',0)
  119. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
  120. ->select('id')
  121. ->get()->toArray();
  122. $dispatch_id = array_column($dispatch_id,'id');
  123. $model->whereIn('dispatch_sub_id', $dispatch_id);
  124. }
  125. if(! empty($data['sale_order_number'])) {
  126. $sales_id = SaleOrdersProduct::where('del_time',0)
  127. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  128. ->select('id')
  129. ->get()->toArray();
  130. $sales_id = array_column($sales_id,'id');
  131. $model->whereIn('sale_orders_product_id', $sales_id);
  132. }
  133. if(! empty($data['team_id'])) $model->where('team_id', $data['team_id']);
  134. if(! empty($data['team_man_id'])) {
  135. $team_id = EmployeeTeamPermission::where('employee_id',$data['team_man_id'])
  136. ->select('team_id')
  137. ->get()->toArray();
  138. $model->whereIn('team_id', array_unique(array_column($team_id,'team_id')));
  139. }
  140. if(! empty($data['finished_id'])) $model->where('finished_id', $data['finished_id']);
  141. if(! empty($data['equipment_id'])) $model->where('equipment_id', $data['equipment_id']);
  142. if(! empty($data['process_id'])) $model->where('process_id', $data['process_id']);
  143. $list = $this->limit($model,'',$data);
  144. $list = $this->fillZjList($list, $data, $user);
  145. return [true,$list];
  146. }
  147. public function fillZjList($data, $erg, $user){
  148. if(empty($data['data'])) return $data;
  149. $team_id = array_unique(array_column($data['data'],'team_id'));
  150. $team_maps = Team::whereIn('id',$team_id)
  151. ->pluck('title','id')
  152. ->toArray();
  153. $team_man = EmployeeTeamPermission::whereIn('team_id',$team_id)
  154. ->select('team_id','employee_id')
  155. ->get()->toArray();
  156. $emp_map = Employee::whereIn('id',array_merge_recursive(array_column($data['data'],'finished_id'),array_column($team_man,'employee_id')))
  157. ->pluck('emp_name','id')
  158. ->toArray();
  159. $team_man_maps = [];
  160. foreach ($team_man as $value){
  161. $t = $emp_map[$value['employee_id']] ?? "";
  162. if(empty($t)) continue;
  163. if(isset($team_man_maps[$value['team_id']])){
  164. $team_man_maps[$value['team_id']] .= ',' . $t;
  165. }else{
  166. $team_man_maps[$value['team_id']] = $t;
  167. }
  168. }
  169. $equipment_map = Equipment::whereIn('id',array_column($data['data'],'equipment_id'))
  170. ->pluck('title','id')
  171. ->toArray();
  172. $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
  173. ->pluck('title','id')
  174. ->toArray();
  175. $sales_number = SaleOrdersProduct::whereIn('id',array_unique(array_column($data['data'],'sale_orders_product_id')))
  176. ->pluck('out_order_no','id')
  177. ->toArray();
  178. $dispatch_no = DispatchSub::whereIn('id',array_column($data['data'], 'dispatch_sub_id'))
  179. ->pluck('dispatch_no','id')
  180. ->toArray();
  181. $return = [];
  182. if(! empty($erg['material'])){
  183. $product_no = array_unique(array_column($data['data'],'product_no'));
  184. $service = new FyyOrderService();
  185. list($status, $msg) = $service->getProductDataFromSqlServer(['product_no' => $product_no], $user);
  186. if($status) $return = $msg;
  187. }
  188. foreach ($data['data'] as $key => $value){
  189. $data['data'][$key]['material'] = $return[$value['product_no']] ?? [];
  190. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d", $value['crt_time']) : '';
  191. $data['data'][$key]['finished_title'] = $emp_map[$value['finished_id']] ?? '';
  192. $data['data'][$key]['team_title'] = $team_maps[$value['team_id']] ?? '';
  193. $data['data'][$key]['team_man'] = $team_man_maps[$value['team_id']] ?? '';
  194. $data['data'][$key]['equipment_title'] = $equipment_map[$value['equipment_id']] ?? '';
  195. $data['data'][$key]['process_title'] = $process_map[$value['process_id']] ?? '';
  196. $data['data'][$key]['sale_order_number'] = $sales_number[$value['sale_orders_product_id']] ?? "";
  197. $dispatch_t = $dispatch_no[$value['dispatch_sub_id']] ?? "";
  198. $data['data'][$key]['dispatch_no'] = $dispatch_t;
  199. // $data['data'][$key]['crt_time'] = date("Y-m-d",strtotime(substr($dispatch_t,0,8)));
  200. }
  201. return $data;
  202. }
  203. public function zjDetail($data, $user){
  204. if(empty($data['order_number'])) return [false, '请选择质检单数据'];
  205. $result = ScrappCount::where('del_time',0)
  206. ->where('order_number', $data['order_number'])
  207. ->get()->toArray();
  208. if(empty($result)) return [false, '质检单不存在或已被删除'];
  209. $first = $result[0] ?? [];
  210. $order['order_number'] = $first['order_number'];
  211. $order['process_title'] = Process::where('id',$first['process_id'])->value("title");
  212. $order['team_title'] = Team::where('id',$first['team_id'])->value("title");
  213. $order['finished_title'] = Employee::where('id',$first['finished_id'])->value("emp_name");
  214. $order['equipment_title'] = Equipment::where('id',$first['equipment_id'])->value("title");
  215. $dispatch = DispatchSub::where('id',$first['dispatch_sub_id'])->first();
  216. $dispatch = empty($dispatch) ? [] : $dispatch->toArray();
  217. $order['dispatch_no'] = $dispatch['dispatch_no'] ?? "";
  218. $order['crt_time'] = date("Y-m-d", $first['crt_time']);
  219. $team_man = EmployeeTeamPermission::where('team_id',$first['team_id'])
  220. ->select('team_id','employee_id')
  221. ->get()->toArray();
  222. $emp_map = Employee::whereIn('id',array_column($team_man,'employee_id'))
  223. ->pluck('emp_name','id')
  224. ->toArray();
  225. $team_man_maps = "";
  226. foreach ($team_man as $value){
  227. $t = $emp_map[$value['employee_id']] ?? "";
  228. if(empty($t)) continue;
  229. if(! empty($team_man_maps)){
  230. $team_man_maps .= ',' . $t;
  231. }else{
  232. $team_man_maps = $t;
  233. }
  234. }
  235. $order['team_man'] = $team_man_maps;
  236. $scrapp_quantity = array_sum(array_column($result, 'scrapp_num')); // 不良品数量
  237. $detail = [
  238. 'product_no' => $first['product_no'],
  239. 'product_title' => $first['product_title'],
  240. 'product_size' => $first['product_size'],
  241. 'product_unit' => $first['product_unit'],
  242. 'technology_name' => $first['technology_name'],
  243. 'production_quantity' => $dispatch['production_quantity'] ?? 0, // 生产数量
  244. 'dispatch_quantity' => $dispatch['dispatch_quantity'] ?? 0, // 派工数量
  245. 'quantity' => $first['quantity'], // 完工数量
  246. 'scrapp_quantity' => $scrapp_quantity, // 不良品数量
  247. 'zj_quantity' => $first['quantity'] + $scrapp_quantity, // 质检数量
  248. 'hg_quantity' => $first['quantity'], // 合格数量
  249. ];
  250. $order['detail'][] = $detail;
  251. $table1 = $table2 = [];
  252. if(! empty($dispatch['zj_plan_id'])){
  253. $plan = ZjPlan::where('id',$dispatch['zj_plan_id'])->first();
  254. if(! empty($plan)){
  255. $plan = $plan->toArray();
  256. $map = Zj::where('del_time',0)->pluck('title','id')->toArray();
  257. $tmp = explode(',', $plan['zj_id']);
  258. foreach ($tmp as $value){
  259. $table1[] = [
  260. 'zj_title' => $map[$value] ?? "",
  261. 'number' => $first['quantity'],
  262. 'mark' => ''
  263. ];
  264. }
  265. }
  266. }
  267. if(! empty($first['scrapp_id'])){
  268. $scrapp = Scrapp::where('id', $first['scrapp_id'])
  269. ->pluck('title','id')
  270. ->toArray();
  271. $table2[] = [
  272. 'zj_title' => $scrapp[$first['scrapp_id']] ?? "", // 不良品原因
  273. 'number' => $scrapp_quantity,
  274. 'mark' => ''
  275. ];
  276. }
  277. $order['table1'] = $table1;
  278. $order['table2'] = $table2;
  279. return [true, $order];
  280. }
  281. //不良品
  282. public function blpList($data, $user){
  283. $model = ScrappCount::where('del_time',0)
  284. ->where('scrapp_num','>',0)
  285. ->select('id','dispatch_sub_id','crt_time','team_id','finished_id','equipment_id','order_number','process_id','sale_orders_product_id')
  286. ->orderBy('dispatch_sub_id','desc')
  287. ->groupBy('order_number');
  288. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  289. if(! empty($data['dispatch_no'])) {
  290. $dispatch_id = DispatchSub::where('del_time',0)
  291. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
  292. ->select('id')
  293. ->get()->toArray();
  294. $dispatch_id = array_column($dispatch_id,'id');
  295. $model->whereIn('dispatch_sub_id', $dispatch_id);
  296. }
  297. if(! empty($data['sale_order_number'])) {
  298. $sales_id = SaleOrdersProduct::where('del_time',0)
  299. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  300. ->select('id')
  301. ->get()->toArray();
  302. $sales_id = array_column($sales_id,'id');
  303. $model->whereIn('sale_orders_product_id', $sales_id);
  304. }
  305. if(! empty($data['team_id'])) $model->where('team_id', $data['team_id']);
  306. if(! empty($data['finished_id'])) $model->where('finished_id', $data['finished_id']);
  307. if(! empty($data['team_man_id'])) {
  308. $team_id = EmployeeTeamPermission::where('employee_id',$data['team_man_id'])
  309. ->select('team_id')
  310. ->get()->toArray();
  311. $model->whereIn('team_id', array_unique(array_column($team_id,'team_id')));
  312. }
  313. if(! empty($data['equipment_id'])) $model->where('equipment_id', $data['equipment_id']);
  314. if(! empty($data['process_id'])) $model->where('process_id', $data['process_id']);
  315. $list = $this->limit($model,'',$data);
  316. $list = $this->fillBLPList($list);
  317. return [true,$list];
  318. }
  319. public function fillBLPList($data){
  320. if(empty($data['data'])) return $data;
  321. $team_id = array_unique(array_column($data['data'],'team_id'));
  322. $team_maps = Team::whereIn('id',$team_id)
  323. ->pluck('title','id')
  324. ->toArray();
  325. $team_man = EmployeeTeamPermission::whereIn('team_id',$team_id)
  326. ->select('team_id','employee_id')
  327. ->get()->toArray();
  328. $emp_map = Employee::whereIn('id',array_merge_recursive(array_column($data['data'],'finished_id'),array_column($team_man,'employee_id')))
  329. ->pluck('emp_name','id')
  330. ->toArray();
  331. $team_man_maps = [];
  332. foreach ($team_man as $value){
  333. $t = $emp_map[$value['employee_id']] ?? "";
  334. if(empty($t)) continue;
  335. if(isset($team_man_maps[$value['team_id']])){
  336. $team_man_maps[$value['team_id']] .= ',' . $t;
  337. }else{
  338. $team_man_maps[$value['team_id']] = $t;
  339. }
  340. }
  341. $equipment_map = Equipment::whereIn('id',array_column($data['data'],'equipment_id'))
  342. ->pluck('title','id')
  343. ->toArray();
  344. $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
  345. ->pluck('title','id')
  346. ->toArray();
  347. $sales_number = SaleOrdersProduct::whereIn('id',array_unique(array_column($data['data'],'sale_orders_product_id')))
  348. ->pluck('out_order_no','id')
  349. ->toArray();
  350. $dispatch_no = DispatchSub::whereIn('id',array_column($data['data'], 'dispatch_sub_id'))
  351. ->pluck('dispatch_no','id')
  352. ->toArray();
  353. foreach ($data['data'] as $key => $value){
  354. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d", $value['crt_time']) : '';
  355. $data['data'][$key]['finished_title'] = $emp_map[$value['finished_id']] ?? '';
  356. $data['data'][$key]['team_title'] = $team_maps[$value['team_id']] ?? '';
  357. $data['data'][$key]['team_man'] = $team_man_maps[$value['team_id']] ?? '';
  358. $data['data'][$key]['equipment_title'] = $equipment_map[$value['equipment_id']] ?? '';
  359. $data['data'][$key]['process_title'] = $process_map[$value['process_id']] ?? '';
  360. $data['data'][$key]['sale_order_number'] = $sales_number[$value['sale_orders_product_id']] ?? "";
  361. $dispatch_t = $dispatch_no[$value['dispatch_sub_id']] ?? "";
  362. $data['data'][$key]['dispatch_no'] = $dispatch_t;
  363. // $data['data'][$key]['crt_time'] = date("Y-m-d",strtotime(substr($dispatch_t,0,8)));
  364. }
  365. return $data;
  366. }
  367. public function blpDetail($data, $user){
  368. if(empty($data['order_number'])) return [false, '请选择质检单数据'];
  369. $result = ScrappCount::where('del_time',0)
  370. ->where('order_number', $data['order_number'])
  371. ->get()->toArray();
  372. if(empty($result)) return [false, '不良品单不存在或已被删除'];
  373. $first = $result[0] ?? [];
  374. $order['order_number'] = $first['order_number'];
  375. $order['process_title'] = Process::where('id',$first['process_id'])->value("title");
  376. $order['team_title'] = Team::where('id',$first['team_id'])->value("title");
  377. $order['finished_title'] = Employee::where('id',$first['finished_id'])->value("emp_name");
  378. $order['equipment_title'] = Equipment::where('id',$first['equipment_id'])->value("title");
  379. $dispatch = DispatchSub::where('id',$first['dispatch_sub_id'])->first();
  380. $dispatch = empty($dispatch) ? [] : $dispatch->toArray();
  381. $order['dispatch_no'] = $dispatch['dispatch_no'] ?? "";
  382. $order['crt_time'] = date("Y-m-d",$first['crt_time']);
  383. $team_man = EmployeeTeamPermission::where('team_id',$first['team_id'])
  384. ->select('team_id','employee_id')
  385. ->get()->toArray();
  386. $emp_map = Employee::whereIn('id',array_column($team_man,'employee_id'))
  387. ->pluck('emp_name','id')
  388. ->toArray();
  389. $team_man_maps = "";
  390. foreach ($team_man as $value){
  391. $t = $emp_map[$value['employee_id']] ?? "";
  392. if(empty($t)) continue;
  393. if(! empty($team_man_maps)){
  394. $team_man_maps .= ',' . $t;
  395. }else{
  396. $team_man_maps = $t;
  397. }
  398. }
  399. $order['team_man'] = $team_man_maps;
  400. $scrapp = Scrapp::whereIn('id', array_unique(array_column($result,'scrapp_id')))
  401. ->pluck('title','id')
  402. ->toArray();
  403. $detail = [];
  404. foreach ($result as $value){
  405. $tmp = [
  406. 'product_no' => $first['product_no'],
  407. 'product_title' => $first['product_title'],
  408. 'product_size' => $first['product_size'],
  409. 'product_unit' => $first['product_unit'],
  410. 'technology_name' => $first['technology_name'],
  411. 'scrapp_quantity' => $value['scrapp_num'], // 不良品数量
  412. 'scrapp_title' => $scrapp[$value['scrapp_id']] ?? "", // 不良品原因
  413. ];
  414. $detail[] = $tmp;
  415. }
  416. $order['detail'] = $detail;
  417. return [true, $order];
  418. }
  419. public function processFlowList($data, $user){
  420. $model = OrdersProduct::where('del_time',0)
  421. ->select('id as order_number','production_no','out_order_no','production_time','customer_name','product_title','technology_name','product_size','product_unit','dispatch_complete_quantity as quantity')
  422. ->orderBy('id','desc');
  423. if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
  424. if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
  425. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  426. if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
  427. if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
  428. if(! empty($data['order_number'])) {
  429. $order_number = str_replace('FC','',$data['order_number']);
  430. $model->where('id', 'LIKE', '%'.$order_number.'%');
  431. }
  432. if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
  433. if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
  434. if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
  435. if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
  436. if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
  437. if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');
  438. if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
  439. if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) $model->whereBetween('out_checker_time',[$data['out_checker_time'][0],$data['out_checker_time'][1]]);
  440. 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]]);
  441. if(! empty($data['production_time'][0]) && ! empty($data['production_time'][1])) $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
  442. $list = $this->limit($model,'',$data);
  443. $list = $this->fillData($list, $user);
  444. return [200,$list];
  445. }
  446. public function fillData($data, $user){
  447. if(empty($data['data'])) return $data;
  448. foreach ($data['data'] as $key => $value){
  449. $data['data'][$key]['order_number'] = "FC". $value['order_number'];
  450. $data['data'][$key]['title'] = "工艺路线(默认)";
  451. $data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
  452. }
  453. return $data;
  454. }
  455. public function processFlowDetail($data, $user){
  456. if(empty($data['order_number'])) return [false, '工艺流程卡单号不能为空'];
  457. $order_number = str_replace('FC','',$data['order_number']);
  458. $order = OrdersProduct::where('del_time',0)
  459. ->where('id',$order_number)
  460. ->select('id as order_number','production_no','out_order_no','production_time','customer_name','product_title','technology_name','product_size','product_unit','dispatch_complete_quantity as quantity', 'production_quantity')
  461. ->first();
  462. if(empty($order)) return [false, '工艺流程卡不存在或已被删除'];
  463. $order = $order->toArray();
  464. $id = $order['order_number'];
  465. $order['order_number'] = "FC". $order['order_number'];
  466. $order['not_quantity'] = bcsub($order['production_quantity'], $order['quantity'],3);
  467. $order['title'] = "工艺路线(默认)";
  468. $order['production_time'] = $order['production_time'] ? date('Y-m-d', $order['production_time']) : '';
  469. $dispatch = DispatchSub::where('del_time',0)
  470. ->where('order_product_id', $id)
  471. ->select('process_id','dispatch_quantity','finished_num','finished_num as bg_num','finished_num as hg_num','waste_num','team_id','device_id','dispatch_time_start','dispatch_time_end')
  472. ->get()->toArray();
  473. $team_map = Team::whereIn('id',array_unique(array_column($dispatch,'team_id')))
  474. ->pluck('title','id')
  475. ->toArray();
  476. $equipment_map = Equipment::whereIn('id',array_unique(array_column($dispatch,'device_id')))
  477. ->pluck('title','id')
  478. ->toArray();
  479. $process_map = Process::whereIn('id',array_column($dispatch,'process_id'))
  480. ->pluck('title','id')
  481. ->toArray();
  482. foreach ($dispatch as $key => $value){
  483. $time1 = $value['dispatch_time_start'] ? date('Y-m-d',$value['dispatch_time_start']) : '';
  484. $time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
  485. $dispatch[$key]['dispatch_time'] = $time1 . ' ' . $time2;
  486. $dispatch[$key]['process_name'] = $process_map[$value['process_id']] ?? '';
  487. $dispatch[$key]['team_name'] = $team_map[$value['team_id']] ?? "";
  488. $dispatch[$key]['device_name'] = $equipment_map[$value['device_id']] ?? "";
  489. }
  490. $order['table'] = $dispatch;
  491. return [true, $order];
  492. }
  493. public function bgOrZj($data, $user){
  494. // $order_number = (new ApplyOrderService())->setOrderNO2(0);dd($order_number);
  495. // // 1. 获取所有需要更新的记录(按 id 升序)
  496. // $records = ReportWorking::where('del_time', 0)
  497. // ->where('id', '>=', 10151)
  498. // ->orderBy('id') // 关键:按 id 排序
  499. // ->get();
  500. // // 2. 设置起始 order_number(你可以根据需要修改)
  501. // $startNumber = 202510101000;
  502. //
  503. // $updateData = [];
  504. //
  505. // foreach ($records as $index => $record) {
  506. // $newOrderNumber = $startNumber + $index;
  507. //
  508. // // 收集要更新的数据
  509. // $updateData[] = [
  510. // 'id' => $record->id,
  511. // 'order_number' => (string)$newOrderNumber, // 转为字符串保持类型一致
  512. // ];
  513. // }
  514. // foreach ($updateData as $value){
  515. // ReportWorking::where('id', $value['id'])->update(['order_number' => $value['order_number']]);
  516. // }
  517. // dd(1);
  518. if(empty($user['role'])) return [false, '当前账号暂未配置角色,无法确认操作报工或质检'];
  519. $role = $user['role'][0];
  520. if(! in_array($role,[9,12,13,14,15,16,17])) return [false, '当前账号角色信息错误'];
  521. if(empty($data['order_number'])) return [false, '工艺流程卡号不能为空'];
  522. $order_number = str_replace('FC','',$data['order_number']);
  523. $order = OrdersProduct::where('del_time',0)
  524. ->where('id',$order_number)
  525. ->select('id')
  526. ->first();
  527. if(empty($order)) return [false, '工艺流程卡不存在或已被删除'];
  528. $order = $order->toArray();
  529. $map = [
  530. 9 => 12, //清洗脱水
  531. 12 => 14, //注塑成型
  532. 15 => 11, //破碎分离
  533. 16 => 13, //挤出造粒
  534. 17 => 15, //混合搅拌
  535. 13 => 12,
  536. 14 => 14,
  537. ];
  538. $role = 13;
  539. $process_id = $map[$role];
  540. if(in_array($role, [9,12,15,16,17])){
  541. $dispatch_no = DispatchSub::where('del_time',0)
  542. ->where('order_product_id',$order['id'])
  543. ->where('process_id', $process_id)
  544. ->value('dispatch_no');
  545. list($status, $msg) = (new DispatchService())->dispatchOrderList(['dispatch_no' => $dispatch_no]);
  546. $type = 1;
  547. }else{
  548. $crt_time = DispatchSub::where('del_time',0)
  549. ->where('order_product_id',$order['id'])
  550. ->where('process_id', $process_id)
  551. ->value('crt_time');
  552. $crt_time = $crt_time ? $crt_time->timestamp : 0;
  553. $dispatch_id = DispatchSub::where('del_time',0)
  554. ->where('order_product_id',$order['id'])
  555. ->where('crt_time',$crt_time)
  556. ->pluck('id')->toArray();
  557. $report = ReportWorkingDetail::from('report_working_detail as a')
  558. ->join('scrapp_count as b','b.report_id','a.report_working_id')
  559. ->where('a.del_time',0)
  560. ->where('b.del_time',0)
  561. ->whereIn('a.data_id',$dispatch_id)
  562. ->where('a.process_id',$process_id)
  563. ->whereRaw('a.quantity > (b.quantity + b.scrapp_num)')
  564. ->select('a.report_working_id')
  565. ->first();
  566. if(empty($report)){
  567. $report = ReportWorkingDetail::from('report_working_detail as a')
  568. ->join('scrapp_count as b','b.report_id','a.report_working_id')
  569. ->where('a.del_time',0)
  570. ->where('b.del_time',0)
  571. ->whereIn('a.data_id',$dispatch_id)
  572. ->where('a.process_id',$process_id)
  573. ->select('a.report_working_id')
  574. ->first();
  575. }
  576. $report = $report->toArray();
  577. list($status, $msg) = (new ApplyOrderService())->reportWorkingDetail(['id' => $report['report_working_id']]);
  578. $type = 2;
  579. }
  580. return [$status, ['type' => $type, 'order' => $msg]];
  581. }
  582. }