浏览代码

Merge branch 'Haozi' of ssh://was.baoshi56.com:10022/var/git/bswas

 Conflicts:
	app/Http/Controllers/TestController.php
LD 4 年之前
父节点
当前提交
cff65e0b9e

+ 3 - 3
app/Http/Controllers/ProcurementController.php

@@ -78,7 +78,7 @@ class ProcurementController extends Controller
                     $build->whereIn('id',$owner_ids);
                 });
             })
-            ->paginate($param['paginate'] ?? 50);
+            ->paginate($paginateParams['paginate'] ?? 50);
         foreach ($procurements as $procurement){
             if ($procurement->procurement_quotations_count>0 && $procurement->status==0) $procurement->status=1;
             if (empty($procurement->procurementDeliveries))continue;
@@ -287,7 +287,7 @@ class ProcurementController extends Controller
                     });
                 });
             })
-            ->paginate($param['paginate'] ?? 50);
+            ->paginate($paginateParams['paginate'] ?? 50);
         $suppliers=Supplier::query()->select('id','name')->get();
         $materials=Material::query()->select('id','name')->get();
         return view('procurement/finance/checkBill',compact('procurementCheckSheets','suppliers','paginateParams','materials'));
@@ -348,7 +348,7 @@ class ProcurementController extends Controller
                 });
             })
             ->where('type',0) //只取采购单
-            ->paginate($param['paginate'] ?? 50);
+            ->paginate($paginateParams['paginate'] ?? 50);
         foreach ($procurements as $procurement){
             if (empty($procurement->procurementDeliveries))continue;
             $procurement->receive_amount=$procurement->procurementDeliveries->sum('amount');

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

@@ -1523,4 +1523,12 @@ TEXT;
         Cache::forget('laborReportsCountingRecords_2020_年');
         Cache::forget('laborReportsCountingRecords_2021_年');
     }
+    public function testApi()
+    {
+        $headers = array();
+        array_push($headers, "Authorization:APPCODE " . 20202020);
+        //根据API的要求,定义相对应的Content-Type
+        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
+        dd($headers);
+    }
 }

+ 5 - 1
app/Jobs/LogisticYTOSync.php

@@ -53,6 +53,10 @@ class LogisticYTOSync implements ShouldQueue
         $nativeResponse = $this->logisticYTOService->query($this->logistic_number);
         $formattedData = $this->logisticYTOService->format($nativeResponse);
         $this->orderPackageReceivedSyncService = app('OrderPackageReceivedSyncService');
-        $this->orderPackageReceivedSyncService->update([$formattedData]);
+        if ($formattedData['logistic_number']){
+            $this->orderPackageReceivedSyncService->update([$formattedData]);
+        }else{
+            LogService::log(LogisticYTOService::class, "YTO快递无快递异常", $formattedData);
+        }
     }
 }

+ 1 - 1
app/Logistic.php

@@ -17,7 +17,7 @@ class Logistic extends Model
     use ModelLogChanging;
     use SoftDeletes;
     use ModelTimeFormat;
-    protected $fillable = ['name','code',"type","mobile","remark","delivery_fee","is_bunched","english_name"];
+    protected $fillable = ['name','code',"type","mobile","remark","delivery_fee","is_bunched","english_name",'belong_company'];
 
 
     static function nameById($id){

+ 4 - 2
app/Providers/AppServiceProvider.php

@@ -127,6 +127,7 @@ use App\Services\OrderPackageExceptionTypeCountingRecordService;
 use App\Services\LogisticYDService;
 use App\Services\ForeignZhenCangService;
 use App\Services\StorageService;
+use App\Services\LogisticAliJiSuApiService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -214,17 +215,17 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('FeatureService',FeatureService::class);
         app()->singleton('ForeignHaiRoboticsService',ForeignHaiRoboticsService::class);
         app()->singleton('ForeignZhenCangService',ForeignZhenCangService::class);
-        app()->singleton('LogisticZopService', LogisticZopService::class);
         app()->singleton('InventoryAccountMissionService', InventoryAccountMissionService::class);
         app()->singleton('InventoryCompareService', InventoryCompareService::class);
         app()->singleton('InventoryDailyLogService', InventoryDailyLogService::class);
         app()->singleton('LaborReportsCountingRecordService', LaborReportsCountingRecordService::class);
-        app()->singleton('OrderPackageReceivedSyncRecordService', OrderPackageReceivedSyncRecordService::class);
         app()->singleton('LogService', LogService::class);
+        app()->singleton('LogisticAliJiSuApiService',LogisticAliJiSuApiService::class);
         app()->singleton('LogisticSFService', LogisticSFService::class);
         app()->singleton('LogisticService', LogisticService::class);
         app()->singleton('LogisticYDService', LogisticYDService::class);
         app()->singleton('LogisticYTOService', LogisticYTOService::class);
+        app()->singleton('LogisticZopService', LogisticZopService::class);
         app()->singleton('MaterialBoxService', MaterialBoxService::class);
         app()->singleton('OracleActAllocationDetailService', OracleActAllocationDetailService::class);
         app()->singleton('OracleBasCustomerService', OracleBasCustomerService::class);
@@ -243,6 +244,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('OrderPackageCommoditiesService', OrderPackageCommoditiesService::class);
         app()->singleton('OrderPackageCommoditySerialNumberService', OrderPackageCommoditySerialNumberService::class);
         app()->singleton('OrderPackageExceptionTypeCountingRecordService', OrderPackageExceptionTypeCountingRecordService::class);
+        app()->singleton('OrderPackageReceivedSyncRecordService', OrderPackageReceivedSyncRecordService::class);
         app()->singleton('OrderPackageReceivedSyncService', OrderPackageReceivedSyncService::class);
         app()->singleton('OrderPackageService', OrderPackageService::class);
         app()->singleton('OrderService', OrderService::class);

+ 124 - 0
app/Services/LogisticAliJiSuApiService.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+use App\LogisticAliJiSuApi;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\Http;
+
+class LogisticAliJiSuApiService
+{
+    use ServiceAppAop;
+
+    public function query($logistic_number)
+    {
+        $app_code = config('api_logistic.AliJiSu.prod.app-code');
+        $type = config('api_logistic.AliJiSu.prod.type');
+        $host = config('api_logistic.AliJiSu.prod.search.host');
+        $path = config('api_logistic.AliJiSu.prod.search.path');
+        $method = config('api_logistic.AliJiSu.prod.method');
+        $headers = array();
+        array_push($headers, "Authorization:APPCODE " . $app_code);
+        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
+        $query='number='.$logistic_number.'&type='.$type;
+        $bodys = "null";
+        $url = $host . $path . "?" . $query;
+//        $response = Http::withHeaders($headers)->get($url);
+//        return json_decode($response->body());
+
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+//        curl_setopt($curl, CURLOPT_HEADER, true);
+        if (1 == strpos("$".$host, "https://"))
+        {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
+        return json_decode(curl_exec($curl));
+    }
+
+    public function format($response): array
+    {
+        $result = [];
+        if (!isset($response)) {return [];}
+        else {
+            try {
+                if ($response->result->number??false)$result['logistic_number'] = $response->result->number;
+            } catch (\Exception $e) {
+                LogService::log(LogisticYTOService::class, "AliJiSu快递信息异常", $response);
+            }
+            $list=$response->result->list;
+            if (!empty($list) && is_array($list)) {
+                $lastNativeRoute = $list[0];
+                $result['status'] = $this->getStatus($response);
+                if ($result['status'] == '已收件') $result['received_at'] = $lastNativeRoute->time;
+                $result['transfer_status'] = $this->getTransferStatus($list);
+                $result['routes_length'] = array_key_exists('transfer_status', $result) ? count($result['transfer_status']) : 0;
+                $orderPackageReceivedSyncService = app('OrderPackageReceivedSyncService');
+                $exceptionData = $orderPackageReceivedSyncService->setExceptionType($result, $lastNativeRoute ? $lastNativeRoute->time : null);
+                $result['exception_type'] = $exceptionData['exception_type'];
+                $result['exception'] = $exceptionData['exception'];
+
+            } else {
+                $result['status'] = null;
+                $result['transfer_status'] = [];
+            }
+            if (!array_key_exists('status', $result)) {$result['status'] = null;$result['transfer_status'] = [];}
+            //如果没有发现额外的异常,且查询到物流轨迹,将异常置为无
+            if (!array_key_exists('exception', $result)
+                && !array_key_exists('exception_type', $result)
+                && array_key_exists('transfer_status', $result)
+            ) {$result['exception_type'] = '无';$result['exception'] = '否';}
+            return $result;
+        }
+    }
+    /**
+     * @param $nativeData
+     * @return string
+     */
+    private function getStatus($nativeData): string
+    {
+        $status = null;
+        switch ($nativeData->result->deliverystatus) {
+            case '1':
+                $status = '在途';
+                break;
+            case '2':
+                $status = '派送中';
+                break;
+            case '3':
+                $status = '已收件';
+                break;
+            case '4':
+                $status = '派送异常';
+                break;
+            default:
+                $status = '无';
+        }
+        return $status;
+    }
+    /**
+     * @param $nativeRoutes
+     * @return array
+     */
+    private function getTransferStatus($nativeRoutes): array
+    {
+        $transferStatus = [];
+        foreach ($nativeRoutes as $nativeRoute) {
+            $item = [];
+            $item['accept_time'] = $nativeRoute->time;
+            $item['accept_address'] = $nativeRoute->status;
+            $item['remark'] = "";
+            $transferStatus[] = $item;
+        }
+        return $transferStatus;
+    }
+
+
+}

+ 13 - 0
config/api_logistic.php

@@ -152,6 +152,19 @@ return [
             ],
         ],
     ],
+    'AliJiSu' => [
+        'prod' => [
+            'app-key' => '203946797',
+            'app-secret' => '5jlb4OfKkVFAbEXa7ebvnSQt5wCLQqWb',
+            'app-code' => '531dca65c4df41bfaa0c58cb52f444db',
+            'type' => 'auto',
+            'method' => 'GET',
+            'search' => [
+                'host' => 'https://jisukdcx.market.alicloudapi.com',
+                'path' => '/express/query',
+            ],
+        ],
+    ],
     'init_date' => '2021-05-17 23:59:59',
     'days' => 2,
 ];

+ 32 - 0
database/migrations/2021_06_04_114431_add_belong_company_to_logistics.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddBelongCompanyToLogistics extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->string('belong_company')->nullable()->comment('隶属公司');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->dropColumn('belong_company');
+        });
+    }
+}

+ 7 - 0
resources/views/maintenance/logistic/create.blade.php

@@ -90,6 +90,13 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="belong_company" class="col-2 col-form-label text-right">隶属公司</label>
+                        <div class="col-8">
+                            <input id="belong_company" type="text" class="form-control"
+                                   name="belong_company" autocomplete="off" value="{{ old('belong_company') }}" >
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="remark" class="col-2 col-form-label text-right">备注</label>
                         <div class="col-8">

+ 7 - 0
resources/views/maintenance/logistic/edit.blade.php

@@ -96,6 +96,13 @@
                             @enderror
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="belong_company" class="col-2 col-form-label text-right">隶属公司</label>
+                        <div class="col-8">
+                            <input id="belong_company" type="text" class="form-control "
+                                   name="belong_company" autocomplete="off" value="@if(old('belong_company')){{old('belong_company')}}@else{{$logistic->belong_company}}@endif" >
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="remark" class="col-2 col-form-label text-right">备注</label>
                         <div class="col-8">

+ 3 - 1
resources/views/maintenance/logistic/index.blade.php

@@ -21,6 +21,7 @@
                         <th>承运商联系方式</th>
                         <th>承运商类型</th>
                         <th>承运商送货费</th>
+                        <th>隶属公司</th>
                         <th>备注</th>
                         <th>创建时间</th>
                         <th>操作</th>
@@ -33,6 +34,7 @@
                         <td>@{{logistic.mobile}}</td>
                         <td>@{{logistic.type}}</td>
                         <td>@{{logistic.delivery_fee}}</td>
+                        <td>@{{logistic.belong_company}}</td>
                         <td>@{{logistic.remark}}</td>
                         <td class="text-muted">@{{logistic.created_at}}</td>
                         <td>
@@ -58,7 +60,7 @@
                     @foreach( $logistics as $logistic )
                     {id:'{{$logistic->id}}',name:'{{$logistic->name}}',code:'{{$logistic->code}}',
                         mobile:"{{$logistic->mobile}}",type:"{{$logistic->type}}",delivery_fee:"{{$logistic->delivery_fee}}",
-                        remark:"{{$logistic->remark}}",created_at:'{{$logistic->created_at}}',is_bunched:"{{$logistic->is_bunched}}"},
+                        remark:"{{$logistic->remark}}",belong_company:"{{$logistic->belong_company}}",created_at:'{{$logistic->created_at}}',is_bunched:"{{$logistic->is_bunched}}"},
                     @endforeach
                 ],
                 selectTr:0

+ 2 - 2
resources/views/procurement/finance/procurementBill.blade.php

@@ -39,8 +39,8 @@
                 <td><span v-if="procurement.receive_amount">@{{ procurement.receive_amount }}</span></td>
                 <td><span>@{{ procurement.cost_price }}</span></td> {{--采购单价--}}
                 <td><span>@{{ procurement.unit_price }}</span></td>  {{--销售单价--}}
-                <td><span>@{{ procurement.amount*procurement.cost_price }}</span></td> {{--应收--}}
-                <td><span>@{{ procurement.quantity*procurement.unit_price }}</span></td> {{--应付--}}
+                <td><span>@{{ (procurement.amount*procurement.cost_price).toFixed(2) }}</span></td> {{--应收--}}
+                <td><span>@{{ (procurement.quantity*procurement.unit_price).toFixed(2) }}</span></td> {{--应付--}}
                 <td><span>@{{ procurement_status[procurement.status] }}</span></td>
                 <td>
                     <span v-if="procurement.status<9">

+ 1 - 1
resources/views/procurement/procurement/index.blade.php

@@ -131,7 +131,7 @@
 {{--                </td>--}}
                 <td class="text-center"><span>@{{ procurement.unit_price }}</span></td>
                 <td class="text-center"><span v-if="procurement.deliver_amount">@{{ procurement.deliver_amount }}</span></td>
-                <td class="text-center"><span>@{{ procurement.quantity*procurement.unit_price }}</span></td>
+                <td class="text-center"><span>@{{ (procurement.quantity*procurement.unit_price).toFixed(2) }}</span></td>
                 <td class="text-muted"><span v-if="procurement.supplier">@{{ procurement.supplier.phone }}</span></td>
             </tr>
         </table>

+ 40 - 0
tests/Services/LogisticAliJiSuApiService/FormatTest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Tests\Services\LogisticAliJiSuApiService;
+
+use App\Services\LogisticYDService;
+use App\Services\LogisticYTOService;
+use BeyondCode\DumpServer\DumpServerServiceProvider;
+use Tests\TestCase;
+use App\LogisticYD;
+use App\Traits\TestMockSubServices;
+
+class FormatTest extends TestCase
+{
+    use TestMockSubServices;
+
+    /** @var LogisticYTOService $service */
+    public $service;
+    private $data;
+    private $amount = 2;
+
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('LogisticAliJiSuApiService');
+    }
+
+    /**
+     * @test
+     */
+    public function format_test()
+    {
+        $response=$this->service->query('9882947888708');
+        dump($response);
+        if ($response && $response->status==0){
+            $result = $this->service->format($response);
+            dd($result);
+        }
+
+    }
+}

+ 36 - 0
tests/Services/LogisticAliJiSuApiService/QueryTest.php

@@ -0,0 +1,36 @@
+<?php
+
+
+namespace Tests\Services\LogisticAliJiSuApiService;
+
+use App\OrderPackage;
+use App\Services\LogisticYDService;
+use App\Services\LogisticYTOService;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+class QueryTest extends TestCase
+{
+    /**
+     * @var LogisticYTOService $service
+     */
+    private $service;
+
+    protected function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('LogisticAliJiSuApiService');
+
+    }
+
+    /**
+     * @test
+     */
+    public function prod_test()
+    {
+       $response = $this->service->query('4280174475389');
+       dd($response);
+       if (is_object($response))$this->assertEquals('1001', $response->code);
+       if (!is_object($response))$this->assertNotEmpty($response);
+    }
+}