LD 6 лет назад
Родитель
Сommit
8eff588aa6

+ 17 - 1
app/Commodity.php

@@ -6,5 +6,21 @@ use Illuminate\Database\Eloquent\Model;
 
 class Commodity extends Model
 {
-    protected $fillable=['barcode','name','sku','owner_name'];
+    protected $fillable=['name','sku','owner_name'];
+    protected $appends=['barcode'];
+
+    public function barcodes()
+    {
+        return $this->hasMany('\App\CommodityBarcode');
+    }
+    public function getBarcodeAttribute(){
+        return $this->barcodes()->first()['code'];
+    }
+    public function newBarcode($barcode){
+        $commodityBarcode=CommodityBarcode::where('commodity_id',$this['id'])->where('code',$barcode)->first();
+        if(!$commodityBarcode){
+            $commodityBarcode=new CommodityBarcode(['commodity_id'=>$this['id'],'code'=>$barcode]);
+            $commodityBarcode->save();
+        }
+    }
 }

+ 10 - 0
app/CommodityBarcode.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CommodityBarcode extends Model
+{
+    protected $fillable=['code','commodity_id'];
+}

+ 85 - 0
app/Http/Controllers/CommodityBarcodeController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\CommodityBarcode;
+use Illuminate\Http\Request;
+
+class CommodityBarcodeController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\CommodityBarcode  $commodityBarcode
+     * @return \Illuminate\Http\Response
+     */
+    public function show(CommodityBarcode $commodityBarcode)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\CommodityBarcode  $commodityBarcode
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(CommodityBarcode $commodityBarcode)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\CommodityBarcode  $commodityBarcode
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, CommodityBarcode $commodityBarcode)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\CommodityBarcode  $commodityBarcode
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(CommodityBarcode $commodityBarcode)
+    {
+        //
+    }
+}

+ 5 - 1
app/Http/Controllers/CommodityController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\Commodity;
 use App\Imports\CommodityImport;
 use Exception;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Auth;
@@ -49,6 +50,7 @@ class CommodityController extends Controller
         $this->validatorCreate($request->all())->validate();
         $commodity=new Commodity($request->all());
         $commodity->save();
+        $commodity->newBarcode($request->input('barcode'));
 
         $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
         return redirect('maintenance/commodity/create')->with('successTip',"成功录入商品信息:“{$request->input('name')}”");
@@ -153,7 +155,9 @@ class CommodityController extends Controller
         $barcode=$request->input('barcode');
         $name = '';
         if($barcode){
-            $commodity=Commodity::where('barcode',$barcode)->first();
+            $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
+                $query->where('code',$barcode);
+            })->first();
             if($commodity&&$commodity['name']) $name=$commodity['name'];
         }
         return ['success'=>'true','name'=>$name];

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

@@ -6,6 +6,7 @@ namespace App\Http\Controllers;
 use App\Authority;
 use App\Batch;
 use App\Carrier;
+use App\CommodityBarcode;
 use App\Events\CancelOrder;
 use App\Events\WeighedEvent;
 use App\Events\WmsReceiveNewEvent;
@@ -39,8 +40,13 @@ class TestController extends Controller
         return call_user_func([$this, $method],$request);
     }
     function t1(Request $request){ //x
-        $url=url(config('api.flux.receive.new'));
-        dd($url,config('api.flux.receive'),config('api.flux'));
+//        $codes=CommodityBarcode::groupBy('code','commodity_id')->havingRaw('count(*) > ?', [1])->get();
+//        $codes->each(function(CommodityBarcode $code){
+//            $delCodes=CommodityBarcode::where('code',$code['code'])->where('commodity_id',$code['commodity_id'])->where('id','!=',$code['id'])->get();
+//            $delCodes->each(function(CommodityBarcode $delcode){
+//                $delcode->delete();
+//            });
+//        });
     }
     function tj(Request $request){
         $bills=RejectedBill::where('is_loaded',2)->where('created_at','<',Carbon::now()->subHours(10)->toDateTimeString());

+ 2 - 0
app/Http/Controllers/api/thirdPart/flux/ReceiveController.php

@@ -246,6 +246,7 @@ class ReceiveController extends Controller
             }
             if($json&&isset($json['Response'])){
                 if($json['Response']['return']['returnFlag']=='2'){
+                    (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
                     return true;
                 }
                 if(isset($json['Response']['return']['returnDesc'])&&strpos($json['Response']['return']['returnDesc'],'唯一约束')!==false){
@@ -260,6 +261,7 @@ class ReceiveController extends Controller
             if($noIssues&&$json['Response']['return']['returnFlag']=='1'){
                 $wmsReceived['is_uploaded']=1;
                 $wmsReceived->save();
+                (new Controller())->log(__METHOD__,'success_'.__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
                 return true;
             }else{
                 $success=false;

+ 1 - 1
app/Http/Controllers/api/thirdPart/flux/StoreController.php

@@ -123,7 +123,7 @@ class StoreController extends Controller
             if($noIssues&&$json['Response']['return']['returnFlag']=='1'){
                 $wmsReceived['is_uploaded']=1;
                 $wmsReceived->save();
-                (new Controller())->log($METHOD, 'success_' . $FUNCTION, $response->body() );
+                (new Controller())->log($METHOD, 'success_' . $FUNCTION, $response->body());
                 return true;
             }else {
                 $success = false;

+ 7 - 3
app/Imports/CommodityImport.php

@@ -3,6 +3,7 @@
 namespace App\Imports;
 
 use App\Commodity;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\ToCollection;
 use Maatwebsite\Excel\Concerns\WithHeadingRow;
@@ -30,7 +31,9 @@ class CommodityImport implements ToCollection, WithHeadingRow
             $name = $row['商品名称'] ?? $row['name'] ?? $row['NAME'] ?? $row['Name'] ?? '';
             $sku = $row['商品编码'] ?? $row['sku'] ?? $row['SKU'] ?? $row['Sku'] ?? '';
             $owner = $row['货主'] ?? $row['owner'] ?? $row['owner_name'] ?? $row['OWNER'] ?? $row['Owner'] ?? '';
-            $commodity=Commodity::where('barcode',$barcode)->first();
+            $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
+                $query->where('code',$barcode);
+            })->first();
             if($commodity){
                 if($this->isOverride){
                     $name?$commodity['name']= $name:false;
@@ -39,12 +42,13 @@ class CommodityImport implements ToCollection, WithHeadingRow
                     $commodity->update();
                 }
             }else{
-                Commodity::create([
+                $commodity=new Commodity([
                     'name' => $name,
                     'sku' => $sku,
                     'owner_name' => $owner,
-                    'barcode' => $barcode,
                 ]);
+                $commodity->save();
+                $commodity->newBarcode($barcode);
             }
         }
     }

+ 1 - 1
app/Listeners/WmsReceiveNewListener.php

@@ -92,8 +92,8 @@ class WmsReceiveNewListener
         $lastReceive=$wmsReceives->first();
         if($lastReceive&&$lastReceive['created_at'])
             if(Carbon::now()->greaterThan(Carbon::make($lastReceive['created_at'])->addHours(6))){
-                (new RejectedBillItemController())->sendRejectedToThirdPart($actualGotItems,$bills->first());
                 (new Controller())->log(__METHOD__,  __FUNCTION__,  '下发小于实收,发给客户:'.$logisticNumberReturn);
+                (new RejectedBillItemController())->sendRejectedToThirdPart2($actualGotItems,$bills->first());
                 return;
             }
 

+ 5 - 2
app/RejectedBillItem.php

@@ -2,6 +2,7 @@
 
 namespace App;
 
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
@@ -33,7 +34,9 @@ class RejectedBillItem extends Model
         if(!$this['name_goods'])return;
         $barcode=$this['barcode_goods'];
         $name=$this['name_goods'];
-        $commodity=Commodity::where('barcode', $barcode)->first();
+        $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
+            $query->where('code',$barcode);
+        })->first();
         if($commodity){
             if($commodity['name']!=$name){
                 $commodity['name']=$name;
@@ -45,10 +48,10 @@ class RejectedBillItem extends Model
         }
         else{
             $commodity = new Commodity();
-            $commodity['barcode']=$barcode;
             $commodity['name']=$name;
             $commodity['owner_name']=$this->rejectedBill->owner->name;
             $commodity->save();
+            $commodity->newBarcode($barcode);
         }
     }
     public function getQualityLabelAttribute(){

+ 1 - 1
config/database.php

@@ -56,7 +56,7 @@ return [
             'collation' => 'utf8mb4_unicode_ci',
             'prefix' => '',
             'prefix_indexes' => true,
-            'strict' => true,
+            'strict' => false,
             'engine' => null,
             'options' => extension_loaded('pdo_mysql') ? array_filter([
                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),

+ 12 - 0
database/factories/CommodityBarcodeFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\CommodityBarcode;
+use Faker\Generator as Faker;
+
+$factory->define(CommodityBarcode::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 1 - 0
database/migrations/2019_08_20_134833_create_logs_table.php

@@ -22,6 +22,7 @@ class CreateLogsTable extends Migration
             $table->longText('description')->nullable();
             $table->bigInteger('id_user')->index()->nullable();
             $table->timestamps();
+            $table->timestamp('created_at')->index()->nullable()->change();
         });
     }
 

+ 32 - 0
database/migrations/2020_03_30_103931_create_commodity_barcodes_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCommodityBarcodesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('commodity_barcodes', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('code')->index();
+            $table->string('commodity_id')->index();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('commodity_barcodes');
+    }
+}

+ 35 - 0
database/migrations/2020_03_30_112202_drop_commodity_barcode_column_to_barcode_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use App\CommodityBarcode;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DropCommodityBarcodeColumnToBarcodeTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::insert('INSERT commodity_barcodes (code,commodity_id) SELECT barcode, id FROM commodities');
+        $this->delRepeated();
+        Schema::table('commodities', function (Blueprint $table) {
+            $table->dropColumn('barcode');
+        });
+    }
+
+    private function delRepeated(){
+        $codes=CommodityBarcode::groupBy('code','commodity_id')->havingRaw('count(*) > ?', [1])->get();
+        $codes->each(function(CommodityBarcode $code){
+            $delCodes=CommodityBarcode::where('code',$code['code'])->where('commodity_id',$code['commodity_id'])->where('id','!=',$code['id'])->get();
+            $delCodes->each(function(CommodityBarcode $delcode){
+                $delcode->delete();
+            });
+        });
+    }
+
+}

+ 1 - 2
public/t.php

@@ -1,5 +1,4 @@
 <?php
 
 
-
-var_dump(intval(microtime(true)*10000));
+echo date('Y-m-d h:i:s', 1585274333);

+ 19 - 16
resources/views/weight/package/statistics.blade.php

@@ -73,8 +73,8 @@
                                             <td>
                                                 <div class="form-inline">
                                                     <div class="form-group">
-                                                        <input  style="width: 170px;transform:scale(0.8)" type="date" v-model="filterData.date_start" class="form-control">
-                                                        <input id="hour_input" type="text" class="form-control"  placeholder="00:00"
+                                                        <input  style="width: 170px;transform:scale(0.8)" type="date" v-model="filterData.date_start" class="form-control" @change="makeFilterDuration">
+                                                        <input id="hour_input" type="text" class="form-control"  placeholder="00:00" @change="makeFilterDuration" autocomplete="off"
                                                                @input="hourFilter($event)" v-model="inputtingAdd_start" style="transform:scale(0.8);width: 80px"
                                                                @keypress="hourFilter($event)" >
                                                         <input v-if="filterData.date_start" hidden  name="date_start" :value="filterData.date_start+' '+inputtingAdd_start">
@@ -82,8 +82,8 @@
                                                 </div>
                                                 <div class="form-inline">
                                                     <div class="form-group">
-                                                        <input style="transform:scale(0.8);width: 170px"  type="date" v-model="filterData.date_end" class="form-control" >
-                                                        <input id="hour_input" type="text" class="form-control"  placeholder="00:00"
+                                                        <input style="transform:scale(0.8);width: 170px"  type="date" v-model="filterData.date_end" class="form-control" @change="makeFilterDuration">
+                                                        <input id="hour_input" type="text" class="form-control"  placeholder="00:00" @change="makeFilterDuration" autocomplete="off"
                                                                @input="hourFilter($event)" v-model="inputtingAdd_end" style="transform:scale(0.8);width:80px"
                                                                @keypress="hourFilter($event)" >
                                                         <input v-if="filterData.date_end" hidden  name="date_end" :value="filterData.date_end+' '+inputtingAdd_end">
@@ -99,7 +99,7 @@
                                     </table>
                                     <span class="text-muted"
                                           style="position: absolute;  bottom: 48px;left:30px;transform: scale(0.65)" v-if="filterData.date_start || filterData.date_end">
-                                        时间区间:@{{ dateTime }}</span>
+                                        @{{ dateTime }}</span>
 
                                 </td>
                                 <td>
@@ -259,19 +259,22 @@
                 this.initInputs();
                 $(".tooltipTarget").tooltip({'trigger':'hover'});
                 $('#statistics').removeClass('d-none');
-                let date=new Date();
-                let thisDate=this.getDate(date);
-                let startTime=this.inputtingAdd_start;
-                let endTime=this.inputtingAdd_end;
-                let endDate=this.filterData.date_end;
-                let startDate=this.filterData.date_start;
-                if (this.filterData.date_start && !this.inputtingAdd_start)  startTime="00:00";
-                if (this.filterData.date_end && !this.inputtingAdd_end)  endTime="23:59";
-                if (this.filterData.date_start && !this.filterData.date_end) endDate=thisDate;
-                if (this.filterData.date_end && !this.filterData.date_start) startDate="2000-01-01 00:00";
-                this.dateTime=startDate+" "+startTime+" - "+endDate+" "+endTime;
+                this.makeFilterDuration();
             },
             methods: {
+                makeFilterDuration(){
+                    let date=new Date();
+                    let thisDate=this.getDate(date);
+                    let startTime=this.inputtingAdd_start;
+                    let endTime=this.inputtingAdd_end;
+                    let endDate=this.filterData.date_end;
+                    let startDate=this.filterData.date_start;
+                    if (this.filterData.date_start && !this.inputtingAdd_start)  startTime="00:00";
+                    if (this.filterData.date_end && !this.inputtingAdd_end)  endTime="23:59";
+                    if (this.filterData.date_start && !this.filterData.date_end) endDate=thisDate;
+                    if (this.filterData.date_end && !this.filterData.date_start) startDate="2000-01-01 00:00";
+                    this.dateTime="选择区间:"+startDate+" "+startTime+" 至 "+endDate+" "+endTime;
+                },
                 getDate(date){
                     let da=[
                         date.getFullYear(),