RentController.php 4.84 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/9
 * Time: 15:07
 */

namespace App\Http\Controllers\Backend\Rent;

use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Rent\DrawbackRequest;
use App\Http\Requests\Backend\Rent\StoreRentRequest;
use Illuminate\Http\Request;
use App\Modules\Models\Rent\Rent;
use App\Repositories\Backend\Rent\RentRepository;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use App\Common\Http;
use Illuminate\Support\Facades\Log;

class RentController   extends Controller
{
    private $rent;


    public function __construct(RentRepository $rent)
    {
        $this->rent = $rent;

    }


    public function index()
    {

//        $id=Create_num::add();die();
        return view('backend.rent.index');
    }


    public function  info($request)
    {

         if(!empty($request)){
           $info=  DB::table('rent')->
             select('rent.id','rent.rent_no', 'rent.number', 'rent.deposit', 'rent.one_day_price', 'rent.real_total',
               'rent.pay_time as add_time','rent.rent_type', 'production.return_time', 'spot.spotname', 'machine.mac_no',
               'customers.nick_name', 'customers.phone','rent.total', 'rent.is_pay', 'rent.is_take', 'rent.is_cancel',
               'production.refund_no', 'production.refund_time', 'production.is_refund', 'production.power_no',
               'production.rent_hatch_no', 'production.is_return')
                 ->leftjoin('spot', 'rent.spot_id', '=', 'spot.id')
                 ->leftjoin('machine', 'rent.machine_id', '=', 'machine.id')
                 ->leftjoin('production', 'rent.id', '=', 'production.rent_id')
                 ->leftjoin('customers', 'rent.customer_id', '=', 'customers.id')
                 ->where('rent.id','=',$request)
                 ->get();
         }

        return view('backend.rent.info',[
            'info'=>$info
        ]);
    }

    public function downLoad()
    {
        $spot=$this->spot();
        $busienss=$this->business();
        return view('backend.rent.download',['spot'=>$spot,'business'=>$busienss]);
    }


    public function store(StoreRentRequest $request)
    {

           $data =$request->all();

           if($data['start']>$data['end']){

               throw new GeneralException(trans('alerts.backend.rent.error'));
           }

       $start= $data['start']." 00:00:00";
       $end= $data['end']." 23:59:59";


         $info=  Rent::
           select('rent.rent_no',  'rent.real_total',
            'rent.add_time', 'customers.platform', 'spot.spotname','production.is_return',
             'customers.phone'
             )
            ->leftjoin('spot', 'rent.spot_id', '=', 'spot.id')
            ->leftjoin('production', 'rent.id', '=', 'production.rent_id')
            ->leftjoin('customers', 'rent.customer_id', '=', 'customers.id')
            ->where('production.return_time','>=',$start)
            ->where('production.return_time','<=',$end)
            ->where('customers.platform','=',$data['platform'])
            ->where('rent.spot_id','=',$data['spot_id'])
            ->get()
            ->toArray();
        foreach($info as $key=>$infos){


            if($infos['platform']==1){
                $infos['platform']= '微信';
            }else if($infos['platform']==2){
                $infos['platform']='支付宝';
            }

            $infos['real_total'] = $infos['real_total'] * 0.01;

            if($infos['is_return']==1){
                $infos['is_return'] = '已归还';
            } else if ($infos['is_return']==0){
                $infos['is_return'] = '没有还';
            }
            $res[0]= ['订单号','支付金额','租借时间','支付方式','景点','是否归还','手机号'];
            $res[$key+1]=$infos;

        }

        Excel::create('租借小程序',function($excel) use ($res){
            $excel->sheet('score', function($sheet) use ($res){
                $sheet->rows($res);

                ob_end_clean();
            });
        })->export('xls');
   }

   public function manage()
   {
       
   }

    public function Drawback(DrawbackRequest $request)
    {
        $req = $request->all();

        $datas = "machine=".$req["mac_no"].
            "&hatch_no=".$req["hatch_no"].
            "&power_no=".$req["power_no"].
            "&has_power=80".
            "&backTime=".date('Y-m-d ').$req["backTime"].
            "&isTrue=0";
        Log::info('[手动归还退款: ]'.$datas);
//        $data = "machine=".$request->input("machine")."&hatch_no=".$request->input("hatch_no")."&power_no=".$request->input("power_no")."&has_power=80&backTime=".$request->input("backTime")."&isTrue=0";

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

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

        return $this->info($req['rentId']);

    }
}