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

138 lines
4.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\home\controller;
use api\Httpcurl;
use think\facade\Db;
use think\facade\View;
class Miniinvoice extends Base
{
public function index()
{
$openid = input('openid');
if (empty($openid)) {
return $this->error('请先授权登录');
}
$origin_userid = $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('请先授权登录');
}
$principals = Db::name('order_principals')->where(['order_sn' => $_REQUEST['order_sn']])->find();
if (empty($principals)) {
$res['msg'] = '无此数据';
return json($res);
}
if ($principals['type']==1){
$data = Db::name('msg')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}elseif ($principals['type']==2){
$data = Db::name('esta')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}elseif ($principals['type']==3){
$data = Db::name('visa')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}
//获取数据
if (empty($data)) {
return $this->error('无此数据');
}
$total_price = $data['total_price'] ? $data['total_price'] : $data['origin_price'];
$data['total_price'] = ($total_price / 100) . "元";
View::assign('data', $data);
View::assign('openid', $openid);
View::assign('user_id', $origin_userid);
return View::fetch();
}
public function add_invoice()
{
$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('请先授权登录');
}
$res = [
'status' => 0,
'msg' => '操作失败,请重新填写'
];
unset($_REQUEST['s'],$_REQUEST['openid'],$_REQUEST['user_id']);
$_REQUEST['uid'] = $user_id;
if(strpos( $_REQUEST['tax_number']," ")){
$res['msg'] = '税号包含空格,请删除后重新填写';
return json($res);
}
$principals = Db::name('order_principals')->where(['order_sn' => $_REQUEST['order_sn']])->find();
if (empty($principals)) {
$res['msg'] = '无此数据';
return json($res);
}
if ($principals['type']==1){
$content = "EVUS有新的发票申请,请及时处理";
$order = Db::name('msg')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}elseif ($principals['type']==2){
$content = "ESTA有新的发票申请,请及时处理";
$order = Db::name('esta')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}elseif ($principals['type']==3){
$content = "美签有新的发票申请,请及时处理";
$order = Db::name('visa')->where(['order_sn' => $_REQUEST['order_sn']])->where('order_status','>',0)->find();
}
if (empty($order)) {
$res['msg'] = '无此数据';
return json($res);
}
$data = Db::name('userinvoice')->where([ 'order_id' => $order['id'],'type'=>$principals['type'] ])->find();
if (!empty($data)) {
$res['msg'] = '请勿重复开票';
return json($res);
}
$lastyear = date('Y',strtotime($order['reg_time']));
$year = date('Y');
if ($year-$lastyear > 2) {
$res['msg'] = '开票期限已过';
return json($res);
}
$_REQUEST['title'] = trim($_REQUEST['title']);
$_REQUEST['money'] = $order['total_price'] ? $order['total_price'] : $order['origin_price'];
//进行插入
unset($_REQUEST['etype']);
$re = Db::name('userinvoice')->insert($_REQUEST);
if (!$re) {
$res['msg'] = '操作失败,请重新填写';
return json($res);
}
$res = [
'status' => 1,
'msg' => '操作成功',
'url' => url('user/order', [], '', true)->build()
];
//推送发票
$url='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a0d594ce-0580-4a9a-bf4f-712193b65531';
$data = array('msgtype' => 'text', 'text' => [
'content' => $content,
]);
Httpcurl::request($url, 'post', json_encode($data), [
'Content-Type: application/json'
]);
return json($res);
}
}