ProductionOrderService.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Service;
  3. use App\Model\OrdersProduct;
  4. use App\Model\OrdersProductBom;
  5. use App\Model\OrdersProductProcess;
  6. use App\Model\Process;
  7. use App\Model\SaleOrdersProduct;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * bom相关
  11. * @package App\Models
  12. */
  13. class ProductionOrderService extends Service
  14. {
  15. public function edit($data){}
  16. public function setOrderNO(){
  17. $str = date('Ymd',time());
  18. $order_number = OrdersProduct::where('production_no','Like','%'. $str . '%')
  19. ->max('order_number');
  20. if(empty($order_number)){
  21. $number = str_pad(1,3,'0',STR_PAD_LEFT);
  22. $number = $str . $number;
  23. }else{
  24. $tmp = substr($order_number, -3);
  25. $tmp = $tmp + 1;
  26. //超过99999
  27. if(strlen($tmp) > 3) return '';
  28. $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
  29. $number = $str . $number;
  30. }
  31. return $number;
  32. }
  33. public function add($data,$user){
  34. //数据校验以及填充
  35. list($status,$msg) = $this->orderRule($data);
  36. if(!$status) return [$status,$msg];
  37. $production_no = $this->setOrderNO();
  38. //工序
  39. $process = Process::where('del_time',0)
  40. ->orderBy('id','desc')
  41. ->first();
  42. if(empty($process)) return [false,'工序不存在!'];
  43. try{
  44. DB::beginTransaction();
  45. $result = SaleOrdersProduct::whereIn('id',$data['id'])
  46. ->select('order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','product_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time')->get()->toArray();
  47. $boom = $process = [];
  48. $time = time();
  49. foreach ($result as $key => $value){
  50. $result[$key]['production_no'] = $production_no;
  51. $result[$key]['production_quantity'] = $data['quantity'][$key];
  52. $result[$key]['production_time'] = $time;
  53. foreach ($data['quantity'][$key] as $v){
  54. $boom[$value['order_no']][] = [
  55. 'order_no' => $value['order_no'],
  56. 'out_order_no' => $value['out_order_no'],
  57. 'product_no' => $value['product_no'],
  58. 'product_title' => $value['product_title'],
  59. 'crt_time' => $time
  60. ];
  61. $process[$value['order_no']][] = [
  62. 'process_id' => $process->id,
  63. 'order_no' => $value['order_no'],
  64. 'out_order_no' => $value['out_order_no'],
  65. 'product_no' => $value['product_no'],
  66. 'product_title' => $value['product_title'],
  67. 'crt_time' => $time
  68. ];
  69. }
  70. }
  71. OrdersProduct::insert($result);
  72. foreach ($boom as $key => $value){
  73. $boom = new OrdersProductBom(['param' => $key]);
  74. $boom->insert($value);
  75. }
  76. foreach ($process as $key => $value){
  77. $boom = new OrdersProductProcess(['param' => $key]);
  78. $boom->insert($value);
  79. }
  80. DB::commit();
  81. }catch (\Exception $e){
  82. DB::rollBack();
  83. return [false,$e->getLine().':'.$e->getMessage()];
  84. }
  85. return [true,'保存成功!'];
  86. }
  87. public function del($data){
  88. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  89. return [true,'删除成功'];
  90. }
  91. public function orderDetail($data){
  92. return [200,''];
  93. }
  94. public function orderList($data){
  95. $model = OrdersProduct::where('del_time',0)
  96. ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','product_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_quantity','production_no','status')
  97. ->orderBy('id','desc');
  98. if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
  99. if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
  100. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  101. if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
  102. if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
  103. if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
  104. if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
  105. if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
  106. if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
  107. if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
  108. if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
  109. if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');
  110. if(! empty($data['out_checker_time'])) $model->where('out_checker_time', $data['out_checker_time']);
  111. if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
  112. if(! empty($data['out_order_no_time'])) $model->where('out_order_no_time', $data['out_order_no_time']);
  113. if(isset($data['status'])) $model->where('status',$data['status']);
  114. $list = $this->limit($model,'',$data);
  115. return [200,$list];
  116. }
  117. public function orderRule($data){
  118. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  119. return [true,''];
  120. }
  121. }