FinishedOrderService.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <?php
  2. namespace App\Service;
  3. use App\Jobs\ProcessDataJob;
  4. use App\Model\Box;
  5. use App\Model\BoxDetail;
  6. use App\Model\DispatchSub;
  7. use App\Model\Employee;
  8. use App\Model\EmployeeTeamPermission;
  9. use App\Model\Equipment;
  10. use App\Model\FinishedOrder;
  11. use App\Model\FinishedOrderScrapp;
  12. use App\Model\FinishedOrderSub;
  13. use App\Model\OrdersProduct;
  14. use App\Model\OrdersProductProcess;
  15. use App\Model\Process;
  16. use App\Model\ReportWorking;
  17. use App\Model\ReportWorkingDetail;
  18. use App\Model\SaleOrdersProduct;
  19. use App\Model\Scrapp;
  20. use App\Model\ScrappCount;
  21. use App\Model\Team;
  22. use App\Service\Box\BoxService;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Redis;
  25. class FinishedOrderService extends Service
  26. {
  27. public function edit($data){}
  28. public function setOrderNO(){
  29. $str = date('Ymd',time());
  30. $order_number = FinishedOrder::where('finished_no','Like','%'. $str . '%')
  31. ->max('finished_no');
  32. if(empty($order_number)){
  33. $number = str_pad(1,3,'0',STR_PAD_LEFT);
  34. $number = $str . $number;
  35. }else{
  36. $tmp = substr($order_number, -3);
  37. $tmp = $tmp + 1;
  38. //超过99999
  39. if(strlen($tmp) > 3) return '';
  40. $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
  41. $number = $str . $number;
  42. }
  43. return $number;
  44. }
  45. public function add($data,$user){
  46. //数据校验以及填充
  47. list($status,$msg) = $this->orderRule($data);
  48. if(!$status) return [$status,$msg];
  49. //数据源
  50. $result = $msg;
  51. $time = time();
  52. try{
  53. DB::beginTransaction();
  54. $em = new EmployeeService();
  55. $auto = $em->is_auto($user, "wg_auto");
  56. //班组下的人
  57. $team_man = [];
  58. $team_array = EmployeeTeamPermission::select('employee_id', 'team_id')->get()->toArray();
  59. foreach ($team_array as $v){
  60. $team_man[$v['team_id']][] = $v['employee_id'];
  61. }
  62. $last_update = $last_update2 = $str_tmp = [];
  63. foreach ($result as $value){
  64. $finished_num = $value['quantity'] + $value['finished_num'];
  65. $waste_num = $value['waste_quantity'] + $value['waste_num'];
  66. DispatchSub::where('id',$value['id'])->update([
  67. 'finished_num' => $finished_num,
  68. 'waste_num' => $waste_num,
  69. 'wg_status' => $auto,
  70. ]);
  71. $tmp = [
  72. 'id' => $value['id'],
  73. 'quantity' => $value['quantity'],
  74. 'product_no' => $value['product_no'] ?? "",
  75. 'product_title' => $value['product_title'] ?? "",
  76. 'product_size' => $value['product_size'] ?? "",
  77. 'product_unit' => $value['product_unit'] ?? "",
  78. ];
  79. $str = $value['order_product_id'] . $value['crt_time'] . $value['product_no'] . $value['technology_name'];
  80. if(! in_array($str, $str_tmp)){
  81. $last_update[] = $tmp;
  82. $str_tmp[] = $str;
  83. }
  84. //班组下的人
  85. $man = $team_man[$value['team_id']] ?? [];
  86. $f_m = 0;
  87. if(! in_array($value['finish_id'], $man) && $value['finish_id'] > 0) {
  88. $man[] = $value['finish_id'];
  89. $f_m = 1;
  90. }
  91. $tmp['process_id'] = $value['process_id'];
  92. foreach ($man as $m_v){
  93. if($f_m && $m_v == $value['finish_id']){
  94. $tmp['team_id'] = 0;
  95. }else{
  96. $tmp['team_id'] = $value['team_id'];
  97. }
  98. $tmp['finished_id'] = $m_v;
  99. $last_update2[] = $tmp;
  100. }
  101. $insert_waste = $scrapp = [];
  102. if(! empty($value['waste_array'])){
  103. foreach ($value['waste_array'] as $k => $v){
  104. // $num = $v['num'] * 1000;
  105. // for($i = 0 ;$i < $num; $i++){
  106. // $insert_waste[] = [
  107. // 'order_product_id' => $value['order_product_id'],
  108. // 'order_no' => $value['order_no'],
  109. // 'product_no' => $value['product_no'],
  110. // 'product_title' => $value['product_title'],
  111. // 'process_id' => $value['process_id'],
  112. // 'crt_time' => $time,
  113. // 'dispatch_no' => $value['dispatch_no'],
  114. // 'status' => 4,//不良品
  115. // 'team_id' => $value['team_id'],
  116. // 'finished_id' => $value['finish_id'],
  117. // 'equipment_id' => $value['device_id'],
  118. // 'scrapp_id' => $v['scrapp_id']
  119. // ];
  120. // }
  121. $scrapp[] = [
  122. 'sale_orders_product_id' => $value['sale_orders_product_id'],
  123. 'order_product_id' => $value['order_product_id'],
  124. 'dispatch_sub_id' => $value['id'],
  125. 'out_order_no' => $value['out_order_no'],
  126. 'order_no' => $value['order_no'],
  127. 'customer_no' => $value['customer_no'],
  128. 'customer_name' => $value['customer_name'],
  129. 'product_no' => $value['product_no'],
  130. 'product_title' => $value['product_title'],
  131. 'product_size' => $value['product_size'],
  132. 'product_unit' => $value['product_unit'],
  133. 'technology_material' => $value['technology_material'],
  134. 'technology_name' => $value['technology_name'],
  135. 'wood_name' => $value['wood_name'],
  136. 'price' => $value['price'],
  137. 'process_mark' => $value['process_mark'],
  138. 'table_body_mark' => $value['table_body_mark'],
  139. 'table_header_mark' => $value['table_header_mark'],
  140. 'crt_id' => 1,
  141. 'crt_time' => $time,
  142. 'scrapp_num' => $v,
  143. 'scrapp_id' => $k,
  144. 'team_id' => $value['team_id'],
  145. 'finished_id' => $value['finish_id'],
  146. 'equipment_id' => $value['device_id'],
  147. 'order_number' => $value['id'] . $time . $value['process_id'],
  148. 'process_id' => $value['process_id'],
  149. 'quantity' => $value['quantity'],
  150. ];
  151. }
  152. }
  153. $quantity = $value['quantity'] * 1000;
  154. //工序表
  155. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  156. $process_model->where('order_product_id',$value['order_product_id'])
  157. ->where('process_id',$value['process_id'])
  158. ->where('dispatch_no',$value['dispatch_no'])
  159. ->where('status', 1)
  160. ->take($quantity)
  161. ->update([
  162. 'finished_time' => $time,
  163. 'status' => 2,
  164. 'finished_id' => $value['finish_id'],
  165. 'team_id' => $value['team_id'],
  166. 'equipment_id' => $value['device_id'],
  167. ]);
  168. if(! empty($insert_waste)) $process_model->insert($insert_waste);
  169. if(! empty($scrapp)) {
  170. $scrapp_model = new ScrappCount();
  171. $scrapp_model->insert($scrapp);
  172. }
  173. //
  174. // if(! empty($value['waste_quantity'])){
  175. // $num = $value['waste_quantity'];
  176. // OrdersProduct::where('id',$value['order_product_id'])->update([
  177. // 'scrapp_num' => DB::raw("scrapp_num + {$num}"),
  178. // ]);
  179. // }
  180. }
  181. //反写数量
  182. //生产订单
  183. $id = array_column($result,'order_product_id');
  184. $this->writeFinishedQuantityByOrdersProductId($id);
  185. //销售订单
  186. $this->writeFinishedQuantity($id);
  187. //生成完工入库申请单
  188. $service = new BoxService();
  189. list($status, $msg) = $service->createWGSQ($last_update, $user);
  190. if(! $status) return [false, $msg];
  191. //生成报工单
  192. list($status, $msg) = $this->createbg($last_update2, $user);
  193. if(! $status) return [false, $msg];
  194. DB::commit();
  195. }catch (\Exception $e){
  196. DB::rollBack();
  197. return [false,$e->getFile() . $e->getLine(). $e->getMessage()];
  198. }
  199. return [true, ''];
  200. }
  201. public function createbg($insert, $user){
  202. //报工单
  203. $em = new EmployeeService();
  204. $auto = $em->is_auto($user, "wgbg_auto");
  205. $order_number = (new ApplyOrderService())->setOrderNO2();
  206. if(empty($order_number)) return [false, '报工单编号生成失败'];
  207. try {
  208. DB::beginTransaction();
  209. $time = time();
  210. $model = new ReportWorking();
  211. $model->order_number = $order_number;
  212. $model->report_time = $time;
  213. $model->mark = $data['mark']?? "";
  214. $model->crt_id = $user['id'];
  215. $model->status = $auto;
  216. $model->save();
  217. $id = $model->id;
  218. $detail_insert = [];
  219. foreach ($insert as $v){
  220. $detail_insert[] = [
  221. 'report_working_id' => $id,
  222. 'data_id' => $v['id'],
  223. 'quantity' => $v['quantity'] ?? 0,
  224. 'finished_id' => $v['finished_id'] ?? 0,
  225. 'process_id' => $v['process_id'] ?? 0,
  226. 'team_id' => $v['team_id'] ?? 0,
  227. 'crt_time' => $time,
  228. ];
  229. }
  230. ReportWorkingDetail::insert($detail_insert);
  231. DB::commit();
  232. }catch (\Throwable $exception){
  233. DB::rollBack();
  234. return [false, $exception->getFile() . $exception->getMessage() . $exception->getLine()];
  235. }
  236. return [true, ''];
  237. }
  238. //产成品入库
  239. public function U8Rdrecord10Save($package_data, $user){
  240. if(empty($package_data)) return [false, '产成品入库为空,请确认!'];
  241. try{
  242. //获取包装单信息
  243. $box = $package_data;
  244. $boxDetail = new BoxDetail(['channel'=>$box['top_order_no']]);
  245. $boxDetail = $boxDetail->where('del_time',0)
  246. ->where('order_no',$box['order_no'])
  247. ->select('id','top_id','num','ext_1','ext_2','ext_3','ext_4','ext_5','out_order_no','box_type','price')
  248. ->get()->toArray();
  249. //用友数据插入------------
  250. if(! empty($boxDetail)){
  251. $sqlServerModel = new FyySqlServerService($user);
  252. if($sqlServerModel->error) return [false, $sqlServerModel->error];
  253. $username = $sqlServerModel->getYongyouName();
  254. $box['create_name'] = $username;
  255. list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($box,$boxDetail);
  256. if(! $status) return [false, $msg];
  257. }
  258. //用友数据插入------------
  259. }catch (\Exception $e){
  260. return [false,$e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine()];
  261. }
  262. return [true,''];
  263. }
  264. //销售发货出库
  265. public function U8Rdrecord32Save($send_data, $user){
  266. if(empty($send_data)) return [false, '销售发货出库为空,请确认!'];
  267. try{
  268. //用友数据插入------------
  269. $sqlServerModel = new FyySqlServerService($user);
  270. if($sqlServerModel->error) return [false, $sqlServerModel->error];
  271. $create_name = $sqlServerModel->getYongyouName();
  272. list($status,$msg) = $sqlServerModel->U8Rdrecord32Save($send_data,$create_name);
  273. if(! $status) return [false, $msg];
  274. //用友数据插入------------
  275. }catch (\Exception $e){
  276. return [false,$e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine()];
  277. }
  278. return [true,''];
  279. }
  280. public function addInJob($result,$data,$user){
  281. try{
  282. //获取数据库连接
  283. $database = $this->getConnectionName($user['zt']);
  284. //用友数据插入------------
  285. $insert_sql_server = [];
  286. foreach ($result as $key => $value){
  287. $quantity_tmp = $data['quantity'][$key];
  288. $result[$key]['quantity'] = $quantity_tmp;
  289. //工序表
  290. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  291. $process_model->setConnection($database);
  292. $process_id = $process_model->select('process_id')
  293. ->where('sort',$process_model->where('del_time',0)
  294. ->where('order_product_id',$value['order_product_id'])
  295. ->max('sort'))
  296. ->first();
  297. if(empty($process_id)) return [false,"未找到最后一道工序"];
  298. $process_id = $process_id->process_id;
  299. if($process_id == $value['process_id']){
  300. $insert_sql_server[] = $result[$key];
  301. }
  302. }
  303. if(! empty($insert_sql_server)){
  304. $sqlServerModel = new FyySqlServerService($user);
  305. if($sqlServerModel->error) return [false,$sqlServerModel->error];
  306. foreach ($insert_sql_server as $value){
  307. // list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($value);
  308. // if(! $status) return [false,$msg];
  309. }
  310. }
  311. //用友数据插入结束----------
  312. //本地数据更新
  313. DB::beginTransaction();
  314. $waste = [];
  315. foreach ($data['waste'] as $key => $value){
  316. $waste[$key] = array_sum(array_column($value,'num'));
  317. }
  318. $time = time();
  319. foreach ($result as $key => $value){
  320. $finished_id_tmp = $data['finish_id'][$key];
  321. $team_tmp = $data['team_id'][$key];
  322. $equipment_id_tmp = $data['equipment_id'][$key];
  323. $finished_num = $value['quantity'] + $value['finished_num'];
  324. $model = new DispatchSub();
  325. $model->setConnection($database);
  326. $model->where('id',$value['id'])->update([
  327. 'finished_num' => $finished_num,
  328. 'waste_num' => $waste[$key],
  329. 'job_status' => 0,
  330. 'dispatch_quantity' => DB::raw("dispatch_quantity + {$waste[$key]}"),//派工数量增加 派工单可以继续派送
  331. ]);
  332. $insert_waste = $insert_dispatch = $scrapp = [];
  333. if(! empty($data['waste'][$key])){
  334. foreach ($data['waste'][$key] as $v){
  335. for($i = 0 ;$i < $v['num']; $i++){
  336. $insert_waste[] = [
  337. 'order_product_id' => $value['order_product_id'],
  338. 'order_no' => $value['order_no'],
  339. 'product_no' => $value['product_no'],
  340. 'product_title' => $value['product_title'],
  341. 'process_id' => $value['process_id'],
  342. 'crt_time' => $time,
  343. 'dispatch_no' => $value['dispatch_no'],
  344. 'status' => 4,//不良品
  345. 'team_id' => $team_tmp,
  346. 'finished_id' => $finished_id_tmp,
  347. 'equipment_id' => $equipment_id_tmp,
  348. 'scrapp_id' => $v['scrapp_id']
  349. ];
  350. $insert_dispatch[] = [
  351. 'order_product_id' => $value['order_product_id'],
  352. 'out_order_no' => $value['out_order_no'],
  353. 'order_no' => $value['order_no'],
  354. 'product_no' => $value['product_no'],
  355. 'product_title' => $value['product_title'],
  356. 'process_id' => $value['process_id'],
  357. 'crt_time' => $time,
  358. 'dispatch_no' => $value['dispatch_no'],
  359. 'status' => 1, //已派工
  360. 'team_id' => 0,
  361. 'finished_id' => 0,
  362. 'equipment_id' => 0,
  363. 'scrapp_id' => 0
  364. ];
  365. }
  366. $scrapp[] = [
  367. 'sale_orders_product_id' => $value['sale_orders_product_id'],
  368. 'order_product_id' => $value['order_product_id'],
  369. 'out_order_no' => $value['out_order_no'],
  370. 'order_no' => $value['order_no'],
  371. 'customer_no' => $value['customer_no'],
  372. 'customer_name' => $value['customer_name'],
  373. 'product_no' => $value['product_no'],
  374. 'product_title' => $value['product_title'],
  375. 'product_size' => $value['product_size'],
  376. 'product_unit' => $value['product_unit'],
  377. 'technology_material' => $value['technology_material'],
  378. 'technology_name' => $value['technology_name'],
  379. 'wood_name' => $value['wood_name'],
  380. 'price' => $value['price'],
  381. 'process_mark' => $value['process_mark'],
  382. 'table_body_mark' => $value['table_body_mark'],
  383. 'table_header_mark' => $value['table_header_mark'],
  384. 'crt_time' => $time,
  385. 'scrapp_num' => $v['num'],
  386. 'scrapp_id' => $v['scrapp_id']
  387. ];
  388. }
  389. }
  390. //工序表
  391. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  392. $process_model->setConnection($database);
  393. $process_model->where('order_product_id',$value['order_product_id'])
  394. ->where('process_id',$value['process_id'])
  395. ->where('dispatch_no',$value['dispatch_no'])
  396. ->take($value['quantity'])
  397. ->update([
  398. 'finished_time' => $time,
  399. 'status' => 2,
  400. 'finished_id' => $finished_id_tmp,
  401. 'team_id' => $team_tmp,
  402. 'equipment_id' => $equipment_id_tmp
  403. ]);
  404. if(! empty($insert_waste)) $process_model->insert($insert_waste);
  405. if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
  406. if(! empty($scrapp)) {
  407. $scrapp_model = new ScrappCount();
  408. $scrapp_model->setConnection($database);
  409. $scrapp_model->insert($scrapp);
  410. }
  411. //生产订单数量
  412. if(! empty($waste[$key])){
  413. $num = $waste[$key];
  414. $model2 = new OrdersProduct();
  415. $model2->setConnection($database);
  416. $model2->where('id',$value['order_product_id'])->update([
  417. 'production_quantity' => DB::raw("production_quantity + {$num}"),
  418. 'scrapp_num' => DB::raw("scrapp_num + {$num}"),
  419. 'dispatch_complete_quantity' => DB::raw("dispatch_complete_quantity + {$num}"),//已派工数量增加
  420. ]);
  421. }
  422. }
  423. //反写数量
  424. // $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$database);
  425. // $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$database);
  426. DB::commit();
  427. }catch (\Exception $e){
  428. DB::rollBack();
  429. return [false,$e->getFile() . $e->getLine(). $e->getMessage()];
  430. }
  431. return [true,''];
  432. }
  433. public function del($data){
  434. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  435. return [true,'删除成功'];
  436. }
  437. public function orderDetail($data){
  438. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  439. $first = DispatchSub::where('id',$data['id'])->first();
  440. $result = [];
  441. $scrapp = ScrappCount::where('del_time',0)
  442. ->whereIn('order_product_id',$first->order_product_id)
  443. ->select('order_product_id','scrapp_num as num', 'scrapp_id')
  444. ->get()->toArray();
  445. foreach ($scrapp as $value){
  446. if(isset($result[$value['order_product_id']])){
  447. $tmp = bcadd($result[$value['scrapp_id']],$value['num'],3);
  448. $result[$value['scrapp_id']] = $tmp;
  449. }else{
  450. $result[$value['scrapp_id']] = $value['num'];
  451. }
  452. }
  453. $result = array_values($result);
  454. // $first = DispatchSub::where('id',$data['id'])->first();
  455. // $process_model = new OrdersProductProcess(['channel' => date("Ymd",$first->out_order_no_time)]);
  456. //
  457. // $result = $process_model->where('del_time',0)
  458. // ->where('dispatch_no',$first->dispatch_no)
  459. // ->where('order_product_id',$first->order_product_id)
  460. // ->where('status',4)
  461. // ->select(DB::raw('count(id) as num'),'scrapp_id')
  462. // ->groupBy('scrapp_id')
  463. // ->get()->toArray();
  464. $map = Scrapp::whereIn('id',array_column($result,'scrapp_id'))
  465. ->pluck('title','id')
  466. ->toArray();
  467. foreach ($result as $key => $value){
  468. $result[$key]['scrapp_name'] = $map[$value['scrapp_id']] ?? '';
  469. }
  470. return [true,$result];
  471. }
  472. public function is_same_month($timestamp1,$timestamp2){
  473. // 格式化时间戳为年份和月份
  474. $year1 = date('Y', $timestamp1);
  475. $month1 = date('m', $timestamp1);
  476. $year2 = date('Y', $timestamp2);
  477. $month2 = date('m', $timestamp2);
  478. if ($year1 === $year2 && $month1 === $month2) {
  479. return true;
  480. } else {
  481. return false;
  482. }
  483. }
  484. public function orderRule($data){
  485. if(! isset($data['is_finish_all'])) return [false, '完工类型不能为空!'];
  486. if(empty($data['detail'])) return [false, '完工明细数据不能为空!'];
  487. $detail_map = $id = $detail_map2 = $waste_map = [];
  488. //班组下的人
  489. $team_man = [];
  490. $team_array = EmployeeTeamPermission::select('employee_id', 'team_id')->get()->toArray();
  491. foreach ($team_array as $v){
  492. $team_man[$v['team_id']][] = $v['employee_id'];
  493. }
  494. foreach ($data['detail'] as $value){
  495. if(empty($value['id'])) return [false,'请选择完工数据!'];
  496. $id[] = $value['id'];
  497. if(empty($value['device_id'])) return [false, '请选择设备!'];
  498. if(empty($value['team_id'])) return [false, '班组必须选择'];
  499. if(empty($team_man[$value['team_id']])) return [false, '班组下的人不能为空,请设置'];
  500. // if(empty($value['team_id']) && empty($value['finish_id'])) return [false,'班组和人员必须选择一个!'];
  501. if(! is_numeric($value['quantity']) || $value['quantity'] < 0) return [false,'完工数量不能小于0!'];
  502. if(! empty($value['waste'])){
  503. foreach ($value['waste'] as $waste){
  504. if(empty($waste['scrapp_id'])) return [false,'请选择损耗原因!'];
  505. if(! is_numeric($waste['num']) || $waste['num'] < 0) return [false,'损耗数量不能小于0!'];
  506. if(isset($waste_map[$value['id']])){
  507. $waste_map[$value['id']] += $waste['num'];
  508. }else{
  509. $waste_map[$value['id']] = $waste['num'];
  510. }
  511. }
  512. }
  513. //完工数量
  514. if(isset($detail_map[$value['id']])){
  515. $detail_map[$value['id']] += $value['quantity'];
  516. }else{
  517. $detail_map[$value['id']] = $value['quantity'];
  518. }
  519. if(! isset($detail_map2[$value['id']])){
  520. $detail_map2[$value['id']] = $value;
  521. }
  522. }
  523. //校验
  524. $result = DispatchSub::where('del_time',0)
  525. ->whereIn('id',$id)
  526. ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price','customer_name','technology_material','technology_name','wood_name','customer_no','out_order_no','waste_num','product_size','product_unit','process_mark','table_body_mark','table_header_mark','sale_orders_product_id','crt_time')
  527. ->get()->toArray();
  528. if(empty($result)) return [false, '派工单不存在或已被删除!'];
  529. $process_map = Process::whereIn('id',array_unique(array_column($result,'process_id')))->pluck('title','id')->toArray();
  530. $search = "";$args = [];
  531. foreach ($result as $key => $value){
  532. $detail2 = $detail_map2[$value['id']] ?? [];
  533. $result[$key]['device_id'] = $detail2['device_id'] ?? 0;
  534. $result[$key]['team_id'] = $detail2['team_id'] ?? 0;
  535. $result[$key]['finish_id'] = $detail2['finish_id'] ?? 0;
  536. $result[$key]['waste_quantity'] = $waste_map[$value['id']] ?? 0;
  537. $tmp = [];
  538. if(! empty($detail2['waste'])){
  539. foreach ($detail2['waste'] as $v){
  540. if(isset($tmp[$v['id']])){
  541. $n = bcadd($v['num'],$tmp[$v['scrapp_id']],3);
  542. $tmp[$v['scrapp_id']] = $n;
  543. }else{
  544. $tmp[$v['scrapp_id']] = $v['num'];
  545. }
  546. }
  547. }
  548. $result[$key]['waste_array'] = $tmp;
  549. $q = $detail_map[$value['id']] ?? 0;
  550. $quantity_tmp = bcadd($q,$value['finished_num'],3);
  551. if($quantity_tmp > $value['dispatch_quantity']) {
  552. $process_tmp = $process_map[$value['process_id']] ?? "";
  553. return [false,'派工单:' . $value['dispatch_no']. '的工序' . $process_tmp .'完工数量不能大于派工数量'];
  554. }
  555. $result[$key]['quantity'] = $q;
  556. $search_key = $value['order_product_id'] . $value['crt_time'];
  557. if($data['is_finish_all'] && ! in_array($search_key , $args)){
  558. $search .= "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
  559. $args[] = $search_key;
  560. }
  561. }
  562. $search = rtrim($search,'OR ');
  563. $search = "($search)";
  564. if($data['is_finish_all']){
  565. //系统帮助完工的数据
  566. $result2 = DispatchSub::where('del_time',0)
  567. ->whereNotIn('id',$id)
  568. ->whereColumn('dispatch_quantity', '>', 'finished_num')
  569. ->whereRaw($search)
  570. ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price','customer_name','technology_material','technology_name','wood_name','customer_no','out_order_no','waste_num','product_size','product_unit','process_mark','table_body_mark','table_header_mark','sale_orders_product_id','crt_time')
  571. ->get()->toArray();
  572. if(! empty($result2)){
  573. foreach ($result2 as $key => $value){
  574. $not_finished_num = $value['dispatch_quantity'] - $value['finished_num'];
  575. $result2[$key]['quantity'] = $not_finished_num;
  576. $result2[$key]['waste_array'] = [];
  577. $result2[$key]['waste_quantity'] = 0;
  578. $result2[$key]['device_id'] = 0;
  579. $result2[$key]['team_id'] = 0;
  580. $result2[$key]['finish_id'] = 0;
  581. }
  582. }
  583. $result = array_merge_recursive($result, $result2);
  584. }
  585. return [true, $result];
  586. }
  587. public function orderList($data){
  588. $model = FinishedOrderSub::where('del_time',0)
  589. ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','dispatch_quantity','finished_num','status','crt_id','process_id','equipment_id','team_id','dispatch_time_start','dispatch_time_end','dispatch_time','crt_time','dispatch_no')
  590. ->orderBy('upd_time','desc')
  591. ->orderBy('id','desc');
  592. if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
  593. if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
  594. if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
  595. if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
  596. if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
  597. if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
  598. if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
  599. if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
  600. if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
  601. if(! empty($data['dispatch_time'][0]) && ! empty($data['dispatch_time'][1])) $model->whereBetween('dispatch_time',[$data['dispatch_time'][0],$data['dispatch_time'][1]]);
  602. if(! empty($data['employee_id'])) {
  603. $team_id = Employee::from('employee as a')
  604. ->leftJoin('employee_team_permission as b','b.employee_id','a.id')
  605. ->where('a.id', $data['employee_id'])
  606. ->select('b.team_id')
  607. ->get()->toArray();
  608. $team_id = array_column($team_id,'team_id');
  609. $model->where('team_id',$team_id ?? []);
  610. }
  611. if(isset($data['status'])) $model->where('status',$data['status']);
  612. $list = $this->limit($model,'',$data);
  613. $list = $this->fillData($list);
  614. return [true,$list];
  615. }
  616. public function fillData($data){
  617. if(empty($data['data'])) return $data;
  618. $waste_map = $waste_map_2 = [];
  619. $waste = FinishedOrderScrapp::where('del_time',0)
  620. ->whereIn('finished_order_id',array_column($data['data'],'id'))
  621. ->select('finished_order_id','num','scrapp_id')
  622. ->get()->toArray();
  623. if(! empty($waste)){
  624. foreach ($waste as $value){
  625. $waste_map[$value['finished_order_id']][] = [
  626. 'num' => $value['num'],
  627. 'scrapp_id' => $value['scrapp_id']
  628. ];
  629. if(isset($waste_map_2[$value['finished_order_id']])){
  630. $waste_map_2[$value['finished_order_id']] += $value['num'];
  631. }else{
  632. $waste_map_2[$value['finished_order_id']] = $value['num'];
  633. }
  634. }
  635. }
  636. $team = EmployeeTeamPermission::from('employee_team_permission as a')
  637. ->leftJoin('employee as b','b.id','a.employee_id')
  638. ->whereIn('a.team_id',array_column($data['data'],'team_id'))
  639. ->select('b.emp_name','a.team_id')
  640. ->get()
  641. ->toArray();
  642. $team_map = [];
  643. if(! empty($team)){
  644. foreach ($team as $value){
  645. if(isset($team_map[$value['team_id']])){
  646. $team_map[$value['team_id']] .= ','. $value['emp_name'];
  647. }else{
  648. $team_map[$value['team_id']] = $value['emp_name'];
  649. }
  650. }
  651. }
  652. $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
  653. ->pluck('title','id')
  654. ->toArray();
  655. $team_maps = Team::whereIn('id',array_column($data['data'],'team_id'))
  656. ->pluck('title','id')
  657. ->toArray();
  658. $equipment_map = Equipment::whereIn('id',array_column($data['data'],'equipment_id'))
  659. ->pluck('title','id')
  660. ->toArray();
  661. foreach ($data['data'] as $key => $value){
  662. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
  663. $time1 = $value['dispatch_time_start'] ? date('Y-m-d',$value['dispatch_time_start']) : '';
  664. $time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
  665. $data['data'][$key]['dispatch_plan_time'] = $time1 . ' ' . $time2;
  666. $data['data'][$key]['dispatch_time'] = $value['dispatch_time'] ? date('Y-m-d',$value['dispatch_time']) : '';
  667. $data['data'][$key]['team_man'] = $team_map[$value['team_id']] ?? '';
  668. $data['data'][$key]['process_name'] = $process_map[$value['process_id']] ?? '';
  669. $data['data'][$key]['team_name'] = $team_maps[$value['team_id']] ?? '';
  670. $data['data'][$key]['equipment_name'] = $equipment_map[$value['equipment_id']] ?? '';
  671. $data['data'][$key]['waste'] = $waste_map[$value['id']] ?? [];
  672. $data['data'][$key]['waste_quantity'] = $waste_map_2[$value['id']] ?? 0;
  673. $data['data'][$key]['not_finished_num'] = $value['dispatch_quantity'] - $value['finished_num'];
  674. }
  675. $data['finished_num'] = $this->getTotal($data['data'], 'finished_num');
  676. $data['dispatch_quantity'] = $this->getTotal($data['data'], 'dispatch_quantity');
  677. $data['waste_quantity'] = $this->getTotal($data['data'], 'waste_quantity');
  678. $data['not_finished_num'] = $this->getTotal($data['data'], 'not_finished_num');
  679. return $data;
  680. }
  681. //反写销售订单完工数量
  682. public function writeFinishedQuantity($orders_product_id){
  683. if(empty($orders_product_id)) return;
  684. $sale_orders_product_id = OrdersProduct::where('del_time',0)
  685. ->whereIn('id', $orders_product_id)
  686. ->select('sale_orders_product_id')
  687. ->get()->toArray();
  688. $sale_orders_product_id = array_unique(array_column($sale_orders_product_id,'sale_orders_product_id'));
  689. $production_order = OrdersProduct::where('del_time',0)
  690. ->whereIn('sale_orders_product_id', $sale_orders_product_id)
  691. ->select(DB::raw("sum(finished_num) as finished_num"),'sale_orders_product_id')
  692. ->groupby('sale_orders_product_id')
  693. ->pluck('finished_num','sale_orders_product_id')
  694. ->toArray();
  695. foreach ($production_order as $sale_orders_product_id => $finished_num){
  696. SaleOrdersProduct::where('id',$sale_orders_product_id)->update([
  697. 'finished_num' => $finished_num,
  698. ]);
  699. }
  700. }
  701. //反写生产订单完工数量
  702. public function writeFinishedQuantityByOrdersProductId($order_product_id){
  703. if(empty($order_product_id)) return;
  704. $result = DispatchSub::where('del_time',0)
  705. ->whereIn('order_product_id',$order_product_id)
  706. ->select('finished_num','order_product_id','crt_time','process_id')
  707. ->get()
  708. ->toArray();
  709. if(empty($result)) return;
  710. //生产订单
  711. $production_order = OrdersProduct::where('del_time',0)
  712. ->whereIn('id',array_unique(array_column($result,'order_product_id')))
  713. ->select('process_id','id','production_quantity')
  714. ->get()
  715. ->toArray();
  716. $judge = [];
  717. foreach ($result as $value){
  718. if(isset($judge[$value['order_product_id']][$value['process_id']])){
  719. $judge[$value['order_product_id']][$value['process_id']] += $value['finished_num'];
  720. }else{
  721. $judge[$value['order_product_id']][$value['process_id']] = $value['finished_num'];
  722. }
  723. }
  724. foreach ($production_order as $value){
  725. //生产订单下的所有工序派工单
  726. $tmp = $judge[$value['id']] ?? [];
  727. if(empty($tmp)) continue;
  728. //生产订单下的工序种类
  729. $ori_process = explode(',',$value['process_id']);
  730. $ori_process_count = count($ori_process);
  731. //生产订单下的派工单的工序种类
  732. $process = array_keys($tmp);
  733. $process_count = count($process);
  734. if($ori_process_count != $process_count) continue;
  735. //获取工序里最小的数值
  736. $min_finished_num = min($tmp);
  737. //更新完工数量
  738. OrdersProduct::where('id',$value['id'])->update([
  739. 'finished_num' => $min_finished_num
  740. ]);
  741. }
  742. }
  743. public function mobileAdd($data,$user){
  744. //数据校验以及填充
  745. list($status,$msg,$count_arr) = $this->orderMobileRule($data);
  746. if(!$status) return [$status,$msg];
  747. $user = [
  748. 'id' => $user['id'],
  749. 'operate_time' => time(),
  750. 'zt' => Request()->header('zt'),
  751. ];
  752. $redis = [
  753. 'result' => $msg,
  754. 'data' => $data,
  755. 'quantity_count' => $count_arr,
  756. ];
  757. $job = ProcessDataJob::dispatch($redis,$user,3)->onQueue(ProcessDataJob::job_one);
  758. if(! $job) return [false,'任务没有进入队列!'];
  759. //错误计数
  760. Redis::hSet('order_failures', md5(json_encode($redis)), 0);
  761. //标记进入队列的数据
  762. DispatchSub::whereIn('id',array_column($msg,'id'))->update([
  763. 'job_status' => 1,
  764. ]);
  765. return [true,'任务已进入队列!'];
  766. }
  767. public function addMobileInJob($result, $data, $count_arr,$user){
  768. try{
  769. //获取数据库连接
  770. $database = $this->getConnectionName($user['zt']);
  771. //用友数据写入------------
  772. $insert_sql_server = [];
  773. foreach ($result as $key => $value){
  774. $quantity_tmp = $count_arr[$value['id']];
  775. $result[$key]['quantity'] = $quantity_tmp;
  776. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  777. $process_model->setConnection($database);
  778. $process_id = $process_model->select('process_id')
  779. ->where('sort',$process_model->where('del_time',0)
  780. ->where('order_product_id',$value['order_product_id'])
  781. ->max('sort'))
  782. ->first();
  783. if(empty($process_id)) return [false,"未找到最后一道工序"];
  784. $process_id = $process_id->process_id;
  785. if($process_id == $value['process_id']){
  786. $insert_sql_server[] = $result[$key];
  787. }
  788. }
  789. if(! empty($insert_sql_server)){
  790. $sqlServerModel = new FyySqlServerService($user);
  791. if($sqlServerModel->error) return [false,$sqlServerModel->error];
  792. foreach ($insert_sql_server as $value){
  793. // list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($value);
  794. // if(! $status) return [false,$msg];
  795. }
  796. }
  797. //用友数据写入结束------------
  798. //本地数据写入-----------
  799. DB::beginTransaction();
  800. $waste = $waste2 = [];
  801. foreach ($data as $value){
  802. if(! empty($value['waste'])){
  803. foreach ($value['waste'] as $v){
  804. if(isset($waste[$value['id']])){
  805. $waste[$value['id']] += $v['num'];
  806. $waste2[$value['order_product_id']] += $v['num'];
  807. }else{
  808. $waste[$value['id']] = $v['num'];
  809. $waste2[$value['order_product_id']] = $v['num'];
  810. }
  811. }
  812. }
  813. }
  814. $time = time();
  815. foreach ($result as $value){
  816. $finished_num = $value['quantity'] + $value['finished_num'];
  817. $watste_num = $waste[$value['id']] ?? 0;
  818. $model = new DispatchSub();
  819. $model->setConnection($database);
  820. $model->where('id',$value['id'])->update([
  821. 'finished_num' => $finished_num,
  822. 'waste_num' => $watste_num,
  823. 'job_status' => 0,
  824. 'dispatch_quantity' => DB::raw("dispatch_quantity + {$watste_num}"),//派工数量增加 派工单可以继续派送
  825. ]);
  826. //生产订单数量
  827. if(! empty($waste2[$value['order_product_id']])){
  828. $num = $waste2[$value['order_product_id']];
  829. $model2 = new OrdersProduct();
  830. $model2->setConnection($database);
  831. $model2->where('id',$value['order_product_id'])->update([
  832. 'production_quantity' => DB::raw("production_quantity + {$num}"),
  833. 'scrapp_num' => DB::raw("scrapp_num + {$num}"),
  834. 'dispatch_complete_quantity' => DB::raw("dispatch_complete_quantity + {$num}"),//已派工数量增加
  835. ]);
  836. }
  837. //损耗和派工 损耗统计
  838. $insert_waste = $insert_dispatch = $scrapp = [];
  839. //工序
  840. $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
  841. $process_model->setConnection($database);
  842. foreach ($data as $d){
  843. if($d['id'] == $value['id']){
  844. $process_model->where('order_product_id',$value['order_product_id'])
  845. ->where('process_id',$value['process_id'])
  846. ->where('dispatch_no',$value['dispatch_no'])
  847. ->take($d['quantity'])
  848. ->update([
  849. 'finished_time' => $time,
  850. 'status' => 2,
  851. 'finished_id' => $d['finished_id'],
  852. 'team_id' => $d['team_id'],
  853. 'equipment_id' => $d['equipment_id']
  854. ]);
  855. if(! empty($d['waste'])){
  856. foreach ($d['waste'] as $v){
  857. for($i = 0 ;$i < $v['num']; $i++){
  858. $insert_waste[] = [
  859. 'order_product_id' => $value['order_product_id'],
  860. 'out_order_no' => $value['out_order_no'],
  861. 'order_no' => $value['order_no'],
  862. 'product_no' => $value['product_no'],
  863. 'product_title' => $value['product_title'],
  864. 'process_id' => $value['process_id'],
  865. 'crt_time' => $time,
  866. 'dispatch_no' => $value['dispatch_no'],
  867. 'status' => 4,
  868. 'team_id' => $d['team_id'],
  869. 'finished_id' => $d['finished_id'],
  870. 'equipment_id' => $d['equipment_id'],
  871. 'scrapp_id' => $v['scrapp_id']
  872. ];
  873. $insert_dispatch[] = [
  874. 'order_product_id' => $value['order_product_id'],
  875. 'out_order_no' => $value['out_order_no'],
  876. 'order_no' => $value['order_no'],
  877. 'product_no' => $value['product_no'],
  878. 'product_title' => $value['product_title'],
  879. 'process_id' => $value['process_id'],
  880. 'crt_time' => $time,
  881. 'dispatch_no' => $value['dispatch_no'],
  882. 'status' => 1, //已派工
  883. 'team_id' => 0,
  884. 'finished_id' => 0,
  885. 'equipment_id' => 0,
  886. 'scrapp_id' => 0
  887. ];
  888. }
  889. $scrapp[] = [
  890. 'sale_orders_product_id' => $value['sale_orders_product_id'],
  891. 'order_product_id' => $value['order_product_id'],
  892. 'out_order_no' => $value['out_order_no'],
  893. 'order_no' => $value['order_no'],
  894. 'customer_no' => $value['customer_no'],
  895. 'customer_name' => $value['customer_name'],
  896. 'product_no' => $value['product_no'],
  897. 'product_title' => $value['product_title'],
  898. 'product_size' => $value['product_size'],
  899. 'product_unit' => $value['product_unit'],
  900. 'technology_material' => $value['technology_material'],
  901. 'technology_name' => $value['technology_name'],
  902. 'wood_name' => $value['wood_name'],
  903. 'price' => $value['price'],
  904. 'process_mark' => $value['process_mark'],
  905. 'table_body_mark' => $value['table_body_mark'],
  906. 'table_header_mark' => $value['table_header_mark'],
  907. 'crt_time' => $time,
  908. 'scrapp_num' => $v['num'],
  909. 'scrapp_id' => $v['scrapp_id']
  910. ];
  911. }
  912. }
  913. }
  914. }
  915. if(! empty($insert_waste)) $process_model->insert($insert_waste);
  916. if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
  917. if(! empty($scrapp)) {
  918. $scrapp_model = new ScrappCount();
  919. $scrapp_model->setConnection($database);
  920. $scrapp_model->insert($scrapp);
  921. }
  922. }
  923. //反写数量
  924. // $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$database);
  925. // $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$database);
  926. DB::commit();
  927. //本地数据写入结束-----------
  928. }catch (\Exception $e){
  929. DB::rollBack();
  930. return [false,$e->getFile() . $e->getLine() . $e->getMessage()];
  931. }
  932. return [true,''];
  933. }
  934. public function orderMobileRule($data){
  935. if(empty($data)) return [false,'数据不能为空!',''];
  936. $dispatch_id = array_unique(array_column($data,'id'));
  937. $bool = DispatchSub::whereIn('id',$dispatch_id)->where('job_status',1)->exists();
  938. if($bool) return [false,'正在队列中,请不要重复操作!',''];
  939. $post = $waste = [];
  940. foreach ($data as $value){
  941. if(! is_numeric($value['quantity']) || $value['quantity'] <= 0) return [false,'请填写正确的完工数量!',''];
  942. if(empty($value['finished_id']) && empty($value['team_id'])) return [false,'人员和班组必须填写一项!',''];
  943. if(isset($post[$value['id']])){
  944. $post[$value['id']] += $value['quantity'];
  945. }else{
  946. $post[$value['id']] = $value['quantity'];
  947. }
  948. if(! empty($value['waste'])){
  949. foreach ($value['waste'] as $v){
  950. if(isset($waste[$value['id']])){
  951. $waste[$value['id']] += $v['num'];
  952. }else{
  953. $waste[$value['id']] = $v['num'];
  954. }
  955. }
  956. }
  957. }
  958. $result = DispatchSub::whereIn('id',$dispatch_id)
  959. ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price','customer_name','technology_material','technology_name','wood_name','customer_no','out_order_no','waste_num','product_size','product_unit','process_mark','table_body_mark','table_header_mark','sale_orders_product_id')
  960. ->orderBy('id','desc')
  961. ->get()->toArray();
  962. foreach ($result as $key => $value){
  963. $tmp = $waste[$value['id']] ?? 0;
  964. $quantity_tmp = $post[$value['id']] + $value['finished_num'] + $value['waste_num'] + $tmp;
  965. if($quantity_tmp > $value['dispatch_quantity']) return [false,"完工数量加上损耗数量不能大于派工数量",''];
  966. }
  967. return [true, $result, $post];
  968. }
  969. public function getConnectionName($name)
  970. {
  971. $mysql = "mysql";
  972. if ($name === '001') {
  973. $mysql = "mysql_001";
  974. } elseif ($name === '002') {
  975. $mysql = "mysql_002";
  976. }
  977. return $mysql;
  978. }
  979. public function insertYy($order, $user){
  980. //包装单
  981. $package_data = json_decode($order['post'], true);
  982. if(! empty($package_data)) {
  983. //用友 ------产成品入库
  984. $service = new FinishedOrderService();
  985. list($status,$msg) = $service->U8Rdrecord10Save($package_data,$user);
  986. if(! $status) return [false, $msg];
  987. }
  988. return [true, ''];
  989. }
  990. }