| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | <?phpnamespace App\Service;use App\Model\OrdersProduct;use App\Model\OrdersProductBom;use App\Model\OrdersProductProcess;use App\Model\Process;use App\Model\SaleOrdersProduct;use Illuminate\Support\Facades\DB;/** * bom相关 * @package App\Models */class ProductionOrderService extends Service{    public function edit($data){}    public function setOrderNO(){        $str = date('Ymd',time());        $order_number = OrdersProduct::where('production_no','Like','%'. $str . '%')            ->max('order_number');        if(empty($order_number)){            $number = str_pad(1,3,'0',STR_PAD_LEFT);            $number = $str . $number;        }else{            $tmp = substr($order_number, -3);            $tmp = $tmp + 1;            //超过99999            if(strlen($tmp) > 3) return '';            $number = str_pad($tmp,3,'0',STR_PAD_LEFT);            $number = $str . $number;        }        return $number;    }    public function add($data,$user){        //数据校验以及填充        list($status,$msg) = $this->orderRule($data);        if(!$status) return [$status,$msg];        $production_no = $this->setOrderNO();        //工序        $process = Process::where('del_time',0)            ->orderBy('id','desc')            ->first();        if(empty($process)) return [false,'工序不存在!'];        try{            DB::beginTransaction();            $result = SaleOrdersProduct::whereIn('id',$data['id'])                ->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();            $boom = $process = [];            $time = time();            foreach ($result as $key => $value){                $result[$key]['production_no'] = $production_no;                $result[$key]['production_quantity'] = $data['quantity'][$key];                $result[$key]['production_time'] = $time;                foreach ($data['quantity'][$key] as $v){                    $boom[$value['order_no']][] = [                        'order_no' => $value['order_no'],                        'out_order_no' => $value['out_order_no'],                        'product_no' => $value['product_no'],                        'product_title' => $value['product_title'],                        'crt_time' => $time                    ];                    $process[$value['order_no']][] = [                        'process_id' => $process->id,                        'order_no' => $value['order_no'],                        'out_order_no' => $value['out_order_no'],                        'product_no' => $value['product_no'],                        'product_title' => $value['product_title'],                        'crt_time' => $time                    ];                }            }            OrdersProduct::insert($result);            foreach ($boom as $key => $value){                $boom = new OrdersProductBom(['param' => $key]);                $boom->insert($value);            }            foreach ($process as $key => $value){                $boom = new OrdersProductProcess(['param' => $key]);                $boom->insert($value);            }            DB::commit();        }catch (\Exception $e){            DB::rollBack();            return [false,$e->getLine().':'.$e->getMessage()];        }        return [true,'保存成功!'];    }    public function del($data){        if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];        return [true,'删除成功'];    }    public function orderDetail($data){        return [200,''];    }    public function orderList($data){        $model = OrdersProduct::where('del_time',0)            ->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')            ->orderBy('id','desc');        if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');        if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');        if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');        if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');        if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');        if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');        if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');        if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');        if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');        if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');        if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');        if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');        if(! empty($data['out_checker_time'])) $model->where('out_checker_time', $data['out_checker_time']);        if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');        if(! empty($data['out_order_no_time'])) $model->where('out_order_no_time', $data['out_order_no_time']);        if(isset($data['status'])) $model->where('status',$data['status']);        $list = $this->limit($model,'',$data);        return [200,$list];    }    public function orderRule($data){        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];        return [true,''];    }}
 |