Files
evus.acvisa.com/app/home/controller/Detail.php

212 lines
11 KiB
PHP

<?php
namespace app\home\controller;
use api\Httpcurl;
use think\facade\Log;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;
class Detail extends Base
{
public function index()
{
View::assign('country_list', json_decode(file_get_contents('./json/country.json'), true));
View::assign('phone_prefix', json_decode(file_get_contents('./json/phone_prefix.json'), true));
View::assign('us', json_decode(file_get_contents('./json/us.json'), true));
View::assign('goods', config('app.EVUS_GOODS'));
View::assign('ismobile', isMobile() ? 1 : 0);
return View::fetch();
}
public function do_apply()
{
unset($_REQUEST['s']);
$order_sn = $_REQUEST['order_sn'] = getOrderNumber();
$total_price = $_REQUEST['total_price'];
/*判断价格是否正确*/
$config_price = array_map(function($item) {
return $item['value'];
}, config('app.EVUS_GOODS'));
if (!in_array($total_price, $config_price)) {
return $this->error('价格错误');
}
/*判断价格是否正确*/
$_REQUEST['birth_date_day'] = (string)date_parse($_REQUEST['birth_date'])['day'] ?:'0';
$_REQUEST['birth_date_month'] = (string)date_parse($_REQUEST['birth_date'])['month'] ?:'0';
$_REQUEST['birth_date_year'] = (string)date_parse($_REQUEST['birth_date'])['year'] ?:'0';
$_REQUEST['passport_expedition_date_day'] = (string)date_parse($_REQUEST['passport_expedition_date'])['day'] ?:'';
$_REQUEST['passport_expedition_date_month'] = (string)date_parse($_REQUEST['passport_expedition_date'])['month'] ?:'';
$_REQUEST['passport_expedition_date_year'] = (string)date_parse($_REQUEST['passport_expedition_date'])['year'] ?:'';
$_REQUEST['passport_expiration_date_day'] = (string)date_parse($_REQUEST['passport_expiration_date'])['day'] ?:'';
$_REQUEST['passport_expiration_date_month'] = (string)date_parse($_REQUEST['passport_expiration_date'])['month'] ?:'';
$_REQUEST['passport_expiration_date_year'] = (string)date_parse($_REQUEST['passport_expiration_date'])['year'] ?:'';
$_REQUEST['us_visa_passport_issue_date_day'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['day'] ?:'';
$_REQUEST['us_visa_passport_issue_date_month'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['month'] ?:'';
$_REQUEST['us_visa_passport_issue_date_year'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['year'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_day'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['day'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_month'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['month'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_year'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['year'] ?:'';
$_REQUEST['us_visa_birth_date_day'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['day'] ?:'';
$_REQUEST['us_visa_birth_date_month'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['month'] ?:'';
$_REQUEST['us_visa_birth_date_year'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['year'] ?:'';
$_REQUEST = formDataToJson(['vist_country', 'vist_from_date', 'vist_end_date', 'vist_country_des'], $_REQUEST, 'vistitem', 'question_i');
$_REQUEST['other_country_acquired_other'] = isset($_REQUEST['other_country_acquired_other']) ? $_REQUEST['other_country_acquired_other'] : '';
$_REQUEST['source'] = Session::get('source' );
$_REQUEST['is_mobile'] = isMobile() ? 1 : 0;
$_REQUEST['total_price'] = $total_price;
$_REQUEST['origin_price'] = $total_price;
$_REQUEST['ip'] = getIP();
$_REQUEST['coupon_code'] = isset($_REQUEST['coupon_code']) ? $_REQUEST['coupon_code']: '';
$_REQUEST['model'] = MODEL;
$_REQUEST['token'] = md5(MODEL);
$order_res = Httpcurl::request(CREATE_EVUS_ORDER_URL, 'post', $_REQUEST);
Log::info(json_encode($order_res));
$order = json_decode($order_res[0], true);
if (!$order['code']) {
return $this->error("提交失败,请联系管理员!");
}
if ($order['is_pay'] == 1) {
return $this->success('操作成功', url('home/pay/succ', ['order_sn' => $order_sn])->build());
}
return $this->success('操作成功', url('home/pay/index', ['order_sn' => $order_sn])->build());
}
public function wxminievus()
{
$openid = input('openid');
if (empty($openid)) {
return $this->error('请先授权登录');
}
$user_id = input('user_id');
if (empty($user_id)) {
return $this->error('请先授权登录');
}
$price = input('price');
$price = $price * 100;
/*判断价格是否正确*/
$config_price = array_map(function($item) {
return $item['value'];
}, config('app.EVUS_GOODS'));
if (!in_array($price, $config_price)) {
return $this->error('价格错误');
}
View::assign('openid', $openid);
View::assign('user_id', $user_id);
View::assign('price', $price);
View::assign('country_list', json_decode(file_get_contents('./json/country.json'), true));
View::assign('phone_prefix', json_decode(file_get_contents('./json/phone_prefix.json'), true));
View::assign('us', json_decode(file_get_contents('./json/us.json'), true));
View::assign('goods', config('app.EVUS_GOODS'));
View::assign('ismobile', isMobile() ? 1 : 0);
return View::fetch();
}
public function applyminievus()
{
$openid = input('openid');
if (empty($openid)) {
return $this->error('请先授权登录');
}
$user_id = input('user_id');
if (empty($user_id)) {
return $this->error('请先授权登录');
}
$user_id = authcode($user_id);
if (!is_numeric($user_id)) {
return $this->error('请先授权登录');
}
unset($_REQUEST['s']);
unset($_REQUEST['openid']);
$order_sn = $_REQUEST['order_sn'] = getOrderNumber();
$total_price = $_REQUEST['total_price'];
/*判断价格是否正确*/
$config_price = array_map(function($item) {
return $item['value'];
}, config('app.EVUS_GOODS'));
if (!in_array($total_price, $config_price)) {
return $this->error('价格错误');
}
/*判断价格是否正确*/
$_REQUEST['birth_date_day'] = (string)date_parse($_REQUEST['birth_date'])['day'] ?:'0';
$_REQUEST['birth_date_month'] = (string)date_parse($_REQUEST['birth_date'])['month'] ?:'0';
$_REQUEST['birth_date_year'] = (string)date_parse($_REQUEST['birth_date'])['year'] ?:'0';
$_REQUEST['passport_expedition_date_day'] = (string)date_parse($_REQUEST['passport_expedition_date'])['day'] ?:'';
$_REQUEST['passport_expedition_date_month'] = (string)date_parse($_REQUEST['passport_expedition_date'])['month'] ?:'';
$_REQUEST['passport_expedition_date_year'] = (string)date_parse($_REQUEST['passport_expedition_date'])['year'] ?:'';
$_REQUEST['passport_expiration_date_day'] = (string)date_parse($_REQUEST['passport_expiration_date'])['day'] ?:'';
$_REQUEST['passport_expiration_date_month'] = (string)date_parse($_REQUEST['passport_expiration_date'])['month'] ?:'';
$_REQUEST['passport_expiration_date_year'] = (string)date_parse($_REQUEST['passport_expiration_date'])['year'] ?:'';
$_REQUEST['us_visa_passport_issue_date_day'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['day'] ?:'';
$_REQUEST['us_visa_passport_issue_date_month'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['month'] ?:'';
$_REQUEST['us_visa_passport_issue_date_year'] = (string)date_parse($_REQUEST['us_visa_passport_issue_date'])['year'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_day'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['day'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_month'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['month'] ?:'';
$_REQUEST['us_visa_passport_expiration_date_year'] = (string)date_parse($_REQUEST['us_visa_passport_expiration_date'])['year'] ?:'';
$_REQUEST['us_visa_birth_date_day'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['day'] ?:'';
$_REQUEST['us_visa_birth_date_month'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['month'] ?:'';
$_REQUEST['us_visa_birth_date_year'] = (string)date_parse($_REQUEST['us_visa_birth_date'])['year'] ?:'';
$_REQUEST = formDataToJson(['vist_country', 'vist_from_date', 'vist_end_date', 'vist_country_des'], $_REQUEST, 'vistitem', 'question_i');
$_REQUEST['other_country_acquired_other'] = isset($_REQUEST['other_country_acquired_other']) ? $_REQUEST['other_country_acquired_other'] : '';
$_REQUEST['source'] = 'qlwxmini';
$_REQUEST['is_mobile'] = isMobile() ? 1 : 0;
$_REQUEST['total_price'] = $total_price;
$_REQUEST['origin_price'] = $total_price;
$_REQUEST['ip'] = getIP();
$_REQUEST['coupon_code'] = isset($_REQUEST['coupon_code']) ? $_REQUEST['coupon_code']: '';
$_REQUEST['model'] = MODEL;
$_REQUEST['token'] = md5(MODEL);
$order_res = Httpcurl::request(CREATE_EVUS_ORDER_URL, 'post', $_REQUEST);
Log::info(json_encode($order_res));
$order = json_decode($order_res[0], true);
if (!$order['code']) {
return $this->error("提交失败,请联系管理员!");
}
$order_url = 'https://pay.qlevisa.com/home/pay/miniwxevuspay';
$response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'body' => 'evus登记签证服务费', 'money' => $total_price, 'openid' => $openid, 'attach' => 'msg']);
if ($response[3]) {
return json([
'code' => 0,
'msg' => '异常错误,请重新提交',
]);
}
$pay_result = json_decode($response[0], true);
if (empty($pay_result)) {
return json([
'code' => 0,
'msg' => '异常错误,请重新提交',
]);
}
if ($pay_result['code'] !== 200) {
return json([
'code' => 0,
'msg' => $pay_result['msg'],
]);
}
$pay_result['data']['package'] = urlencode($pay_result['data']['package']);
return json([
'code' => 1,
'msg' => '提交成功',
'data' => $pay_result['data']
]);
}
}