| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 | 
							- <?php
 
- namespace App\Service;
 
- use App\Model\Orders;
 
- use App\Model\SaleOrdersProduct;
 
- use App\Model\SaleOrdersProductStockDetail;
 
- use Illuminate\Support\Facades\DB;
 
- class FyyOrderService extends Service
 
- {
 
-     public function edit($data){
 
-         return [true,'保存成功!'];
 
-     }
 
-     public function setOrderNo(){
 
-         date_default_timezone_set('PRC');
 
-         $order_no = date('Ymd') . time() . rand(1000, 9999);
 
-         return $order_no;
 
-     }
 
-     public function add($data,$user){
 
-         //获取数据
 
-         $sqlServerModel = new FyySqlServerService();
 
-         list($status,$return,$return_stock_detail) = $sqlServerModel->getDataFromSqlServer($data);
 
-         if(! $status) return [false, $return];
 
-         //数据校验以及填充
 
-         list($status,$msg) = $this->orderRule($return);
 
-         if(!$status) return [$status,$msg];
 
-         try{
 
-             DB::beginTransaction();
 
-             $keys = array_unique(array_column($return,'out_order_no'));
 
-             $map = array_fill_keys($keys, 0);
 
-             $orders = $return_stock_detail_map = [];
 
-             foreach ($return as $key => $value){
 
-                 if(! empty($map[$value['out_order_no']])){
 
-                     $order_no = $map[$value['out_order_no']];
 
-                 }else{
 
-                     $order_no = $this->setOrderNo();
 
-                     $map[$value['out_order_no']] = $order_no;
 
-                     $orders[] = [
 
-                         'order_no' => $order_no,
 
-                         'out_order_no' => $value['out_order_no'],
 
-                         'crt_time' => time()
 
-                     ];
 
-                 }
 
-                 $return[$key]['order_no'] = $order_no;
 
-                 $return[$key]['crt_id'] = $user['id'];
 
-                 $return[$key]['crt_time'] = time();
 
-                 $keys = ($value['technology_name'] ?? '' ) . ($value['wood_name'] ?? '' ) . $value['product_no'];
 
-                 $return_stock_detail_map[$keys] = $order_no;
 
-             }
 
-             foreach ($return_stock_detail as $key => $value){
 
-                 $keys = ($value['technology_name'] ?? '' ) . ($value['wood_name'] ?? '' ) . $value['product_no'];
 
-                 $return_stock_detail[$key]['order_no'] = $return_stock_detail_map[$keys] ?? '';
 
-             }
 
-             Orders::insert($orders);
 
-             SaleOrdersProduct::insert($return);
 
-             SaleOrdersProductStockDetail::insert($return_stock_detail);
 
-             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不能为空!'];
 
-         Orders::whereIn('id',$data['id'])->update([
 
-             'del_time' => time()
 
-         ]);
 
-         SaleOrdersProduct::where('id',$data['id'])->update([
 
-             'del_time'=>time()
 
-         ]);
 
-         return [true,'删除成功'];
 
-     }
 
-     public function orderDetail($data){
 
-         return [200,''];
 
-     }
 
-     public function orderList($data){
 
-         $model = SaleOrdersProduct::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')
 
-             ->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_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
 
-         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]]);
 
-         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]]);
 
-         if(isset($data['status'])) $model->where('status',$data['status']);
 
-         $list = $this->limit($model,'',$data);
 
-         $list = $this->fillData($list);
 
-         return [true, $list];
 
-     }
 
-     public function fillData($data){
 
-         if(empty($data['data'])) return $data;
 
-         $order_no = array_filter(array_column($data['data'],'order_no'));
 
-         $detail = SaleOrdersProductStockDetail::where('del_time',0)
 
-             ->whereIn('order_no',$order_no)
 
-             ->select('order_no','product_no','product_quantity_on_hand','technology_name','wood_name','warehouse_name')
 
-             ->get()->toArray();
 
-         $detail_map = [];
 
-         foreach ($detail as $value){
 
-             $keys = $value['order_no'] . $value['product_no'];
 
-             $detail_map[$keys][] = [
 
-                 'warehouse_name' => $value['warehouse_name'],
 
-                 'product_quantity_on_hand' => $value['product_quantity_on_hand']
 
-             ];
 
-         }
 
-         foreach ($data['data'] as $key => $value){
 
-             $keys = $value['order_no'] . $value['product_no'];
 
-             $data['data'][$key]['sub'] = $detail_map[$keys] ?? [];
 
-         }
 
-         return $data;
 
-     }
 
-     public function orderRule($data){
 
-         $result = Orders::where('del_time',0)
 
-             ->whereIn('out_order_no',array_column($data,'out_order_no'))
 
-             ->select('out_order_no')
 
-             ->get()->toArray();
 
-         if(! empty($result))  return [false,'查询区间内销售订单号已存在'];
 
-         return [true,''];
 
-     }
 
-     public function fyyRefreshOnHandQuantity($data){
 
-         return [true,''];
 
-     }
 
- }
 
 
  |