NoReturnOrder.php 2.25 KB
<?php

namespace App\Console\Commands;

use App\Common\Http;
use App\Modules\Models\Production\Production;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class NoReturnOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'NoReturnOrder {--day=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '未归还的订单费用';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $datas = Production::select('machine.mac_no', 'production.power_no', 'production.rent_hatch_no','production.is_return', 'power.machine_id', 'rent.deposit', 'rent.one_day_price', 'rent.pay_time')
            ->leftjoin('power', 'production.power_no', '=', 'power.power_no')
            ->leftjoin('rent', 'rent.id', '=', 'production.rent_id')
            ->leftjoin('machine', 'machine.id', '=', 'production.rent_machine_id')
            ->where('production.is_return', '=', 0)
            ->where('rent.is_over', '=', 0)
            ->whereNull('power.machine_id')
            ->get()
            ->toArray();

        foreach ($datas as $key => $data){
            $days = ceil($data['deposit'] / $data['one_day_price']);
            if(time() > (strtotime($data['pay_time']) + $days * 60 * 60 * 24)){
                //todo 请求归还接口

                $datas = "machine=".$data["mac_no"].
                    "&hatch_no=".$data["rent_hatch_no"].
                    "&power_no=".$data["power_no"].
                    "&has_power=80".
                    "&backTime=".date('Y-m-d H:i:s').
                    "&isTrue=0";

                $url = "http://api.ssw-htzn.com/api/v1/customers/manualReturn";

                json_decode( Http::post($datas, $url ), true) ;

                Log::info('未归还设备请求手动归还: '. $data['power_no']);
            }

        }
        Log::info('未归还设备请求手动归还---------------------end---------------------------');
    }
}