public function add_up()
{
$id = input('post.id');
//print_r('id:' . $id);
$companycode = "登录账号";
$companypassword = ‘密码’;
$companyname = ‘公司名称’;
$post_data = [
'companycode' => $companycode,
'companypassword' => $companypassword,//密码
];
$token = $this->send(json_encode($post_data));
$code = explode(",", $token);
$code = trim($code[0], '{"code":');
if($code==1){
$token= explode('"access_token":',$token);
$token= trim($token[1],"}");
$token= trim($token,'"');
}else{
echo json_encode(['code' => 1, 'msg' => '上传失败'.$token]);
exit;
}
// echo json_encode(['code' => 0, 'msg' => '上传成功!'.$token]);
$table = RepairTable::where('id', $id)->find();
$repairdate =date('Ymd',strtotime($table->add_time));
$settledate =date('Ymd',strtotime($table->complete_time));
$fueltype = $table->cartype->power_type;
if($fueltype=='燃油'){
$fueltype = 'A';
}else{
$fueltype = 'C';
}
$goods= RepairGoods::where('table_id',$id)->select();
$vehiclepartslist = [];
foreach ($goods as $v){
if(!empty($v)){
$vc['partsname']=$v->goods->title; //"配件名称",
$vc['partscode']=$v->goods->number; //"配件编码",
$vc['partsquantity']=$v->quantity; //"配件数量"
$vehiclepartslist[] = $vc;
}
}
$repair = RepairItems::where('table_id',$id)->select();
$repairprojectlist=[];
foreach ($repair as $v){
if(!empty($v)){
$vr['repairproject']=$v->member->title; //"维修项目",
$vr['workinghours']=$v->quantity; //:"工时"
$repairprojectlist[] = $vr;
}
}
$data =[
'access_token'=>$token, //"票据",
'basicInfo'=>[
'vehicleplatenumber'=>$table->car->car_number, //车牌号码
'vehicleusecharacter'=>'非营运',//车辆使用性质
'vin'=>$table->car->vin, //VIN)
'companyname'=>$companyname, //维修企业名称
'repairdate'=>$repairdate, //送修日期,格式:20100808 "
'repairmileage'=>$table->last_mileage, //"送修里程"
'faultdescription'=>$table->describe, //:"故障描述"
'settledate'=>$settledate, //"结算日期 ,格式:20100808"
'costlistcode'=>$table->number, //结算清单编号
'fueltype'=>$fueltype, //"燃料(能源)类型(字母代码),参考燃料类型代码表"
],
'vehiclepartslist'=>$vehiclepartslist, //配件
'repairprojectlist'=>$repairprojectlist, //工时
];
$add = $this->up_data(json_encode($data));
// dump($add);
$code = explode(",", $add);
// dump($code);
$code = trim($code[0], '{"code":');
// dump($code);
if($code==1){
$update = RepairTable::where('id', $id)->update(['update_dzda' =>1]);
echo json_encode(['code' =>0, 'msg' => '上传成功']);
}else{
echo json_encode(['code' => 1, 'msg' => '上传失败'.$add]);
exit;
}
}
public function send($data){
$url = 'https://你的省份获得Token的地址';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json;charset=utf-8'));
return curl_exec($ch);
}
public function up_data($data){
$url = 'https://你的省份上传接口地址';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json;charset=utf-8'));
return curl_exec($ch);
}