Ver Fonte

分支-合并的二次提交

Zhouzhendong há 5 anos atrás
pai
commit
5ae10f7d99

+ 2 - 0
app/Http/Controllers/TestController.php

@@ -288,6 +288,8 @@ class TestController extends Controller
     /*1*/
     function test()
     {/**/
+        $waybill=Waybill::selectRaw('waybills.*')->where('type','专线');
+        dd($waybill->getTable());
     }
 
 }

+ 4 - 3
app/Http/Controllers/WaybillsController.php

@@ -77,11 +77,11 @@ class WaybillsController extends Controller
         }
         if ($request->input('created_at_start')){
             $created_at_start=$request->input('created_at_start')." 00:00:00";
-            $waybills=$waybills->where('waybills.created_at','>=',$created_at_start);
+            $waybills=$waybills->where('created_at','>=',$created_at_start);
         }
         if ($request->input('created_at_end')){
             $created_at_end=$request->input('created_at_end')." 23:59:59";
-            $waybills=$waybills->where('waybills.created_at','<=',$created_at_end);
+            $waybills=$waybills->where('created_at','<=',$created_at_end);
         }
         if ($request->input('status')){
             $waybills=$waybills->where('status',$request->input('status'));
@@ -999,7 +999,8 @@ class WaybillsController extends Controller
     public function getWaybills(){
         $waybills = Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
             return $query->with('user');
-        }])->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update')
+        }])
+            ->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update,waybill_on_tops.created_at top_created_at')
             ->leftJoin('waybill_on_tops','waybill_on_tops.waybill_id','=','waybills.id')
             ->whereNull('waybill_on_tops.deleted_at')
             ->orderBy('waybill_on_tops.updated_at','desc')

+ 0 - 1
app/Process.php

@@ -54,7 +54,6 @@ class Process extends Model
     public function automaticSupplementSign(){
         return $this->hasOne('App\Sign','signable_id','id')
             ->where('signable_type','processes')->where('field','automatic_supplement');
-            ->where('signable_type','processes')->where('field','unit_price');
     }
     public function signUnitPrice(){
         return $this->hasOne('App\Sign','signable_id','id')

+ 26 - 0
app/Services/WaybillService.php

@@ -0,0 +1,26 @@
+<?php 
+
+namespace App\Services; 
+
+use App\Services\common\QueryService;
+use App\Waybill;
+use Illuminate\Http\Request;
+
+Class WaybillService
+{
+    private function conditionQuery(Request $request){
+        $waybills = Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
+            return $query->with('user');
+        }])->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update')
+            ->leftJoin('waybill_on_tops','waybill_on_tops.waybill_id','=','waybills.id')
+            ->whereNull('waybill_on_tops.deleted_at')
+            ->orderBy('waybill_on_tops.updated_at','desc')
+            ->orderBy('waybills.id','desc');
+        $columnQueryRules=[
+            //TODO: 规则待完善
+        ];
+        $waybills = app(QueryService::class)->query($request,$waybills,$columnQueryRules,"waybills");
+        return $waybills;
+    }
+
+}

+ 12 - 11
app/Services/common/QueryService.php

@@ -15,14 +15,15 @@ Class QueryService
      * @param Request $request
      * @param object $query
      * @param array $columnQueryRules
+     * @param string $tableName
      * @return object
      */
-    public function query(Request $request,$query,array $columnQueryRules)
+    public function query(Request $request,$query,array $columnQueryRules,$tableName = null)
     {
         foreach ($request->input() as $param => $value){
             if ($param === 'paginate' || $param === 'page')continue;
             if (!$value || isset($columnQueryRules[$param]))continue;
-            $query = $query->where($param,$value);
+            $query = $query->where($tableName.$param,$value);
         }
         //rules: alias timeLimit startDate endDate like
         foreach ($columnQueryRules as $param => $rules){
@@ -37,32 +38,32 @@ Class QueryService
                 if ($rule === 'timeLimit'){
                     $today=Carbon::now()->subDays($value);
                     $queryTemp=clone $query;
-                    $queryTemp=$queryTemp->where($column,'like','%'.$request->input($param).'%')
-                        ->where('created_at','>',$today->format('Y-m-d'));
+                    $queryTemp=$queryTemp->where($tableName.$column,'like','%'.$request->input($param).'%')
+                        ->where($tableName.'created_at','>',$today->format('Y-m-d'));
                     if($queryTemp->count()==0 || $queryTemp->first()[$column]==$request->input($param)){
-                        $query=$query->where($column,$request->input($param));
+                        $query=$query->where($tableName.$column,$request->input($param));
                     }else{
-                        $query=$query->where($column,'like','%'.$request->input($param).'%')
-                            ->where('created_at','>',$today->format('Y-m-d'));
+                        $query=$query->where($tableName.$column,'like','%'.$request->input($param).'%')
+                            ->where($tableName.'created_at','>',$today->format('Y-m-d'));
                     }
                     $isExecute = true;
                 }
                 if ($rule === 'startDate'){
                     $startDate = $request->input($param).$value;
-                    $query = $query->where($column,'>=',$startDate);
+                    $query = $query->where($tableName.$column,'>=',$startDate);
                     $isExecute = true;
                 }
                 if ($rule === 'endDate'){
                     $endDate = $request->input($param).$value;
-                    $query = $query->where($column,'<=',$endDate);
+                    $query = $query->where($tableName.$column,'<=',$endDate);
                     $isExecute = true;
                 }
                 if ($rule === 'like'){
-                    $query = $query->where($column,'like','%'.$request->input($param).'%');
+                    $query = $query->where($tableName.$column,'like','%'.$request->input($param).'%');
                     $isExecute = true;
                 }
             }
-            if (!$isExecute) $query = $query->where($column,$request->input($param));
+            if (!$isExecute) $query = $query->where($tableName.$column,$request->input($param));
         }
         return $query;
     }