添加发票
This commit is contained in:
120
application/api/controller/Invoice.php
Normal file
120
application/api/controller/Invoice.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\admin\model\InvoiceLog;
|
||||
use think\Db;
|
||||
|
||||
class Invoice extends ApiBase
|
||||
{
|
||||
|
||||
//添加发票
|
||||
public function add()
|
||||
{
|
||||
$dataPost = $this->request->post();
|
||||
if (empty($dataPost['type'])){
|
||||
return $this->_error('请选择发票类型');
|
||||
}
|
||||
if (empty($dataPost['invoice_type'])){
|
||||
return $this->_error('请选择类型');
|
||||
}
|
||||
if (empty($dataPost['invoice_title'])){
|
||||
return $this->_error('请填写发票抬头');
|
||||
}
|
||||
if (empty($dataPost['identification'])){
|
||||
return $this->_error('请填写纳税人识别号');
|
||||
}
|
||||
$uid = $this->user_id;
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'type' => $dataPost['type'],
|
||||
'invoice_type' => $dataPost['invoice_type'],
|
||||
'invoice_title' => $dataPost['invoice_title'],
|
||||
'identification' => $dataPost['identification'],
|
||||
'address' => $dataPost['address'],
|
||||
'phone' => $dataPost['phone'],
|
||||
'bank' => $dataPost['bank'],
|
||||
'account' => $dataPost['account'],
|
||||
'create_time' => date('Y-m-d H:i:s', time())
|
||||
];
|
||||
$res = Db::name('invoice')->insert($data);
|
||||
if ($res){
|
||||
return $this->_success('添加成功');
|
||||
}else{
|
||||
return $this->_error('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发票列表
|
||||
public function list()
|
||||
{
|
||||
$uid = $this->user_id;
|
||||
$list = Db::name('invoice')->where('uid', $uid)->select();
|
||||
return $this->_success('成功', $list);
|
||||
}
|
||||
|
||||
//申请发票
|
||||
public function apply()
|
||||
{
|
||||
$dataPost = $this->request->post();
|
||||
if (empty($dataPost['invoice_id'])) {
|
||||
return $this->_error('请选择发票信息');
|
||||
}
|
||||
if (empty($dataPost['order_id'])) {
|
||||
return $this->_error('请选择要开票订单');
|
||||
}
|
||||
$uid = $this->user_id;
|
||||
//查询是否存在该开票信息
|
||||
$invoice = Db::name('invoice')->where('id', $dataPost['invoice_id'])->find();
|
||||
if (!$invoice) {
|
||||
return $this->_error('发票信息不存在');
|
||||
}
|
||||
$order = Db::name('order')->where('id', $dataPost['order_id'])->find();
|
||||
if (!$order) {
|
||||
return $this->_error('订单信息不存在');
|
||||
}
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'invoice_id' => $dataPost['invoice_id'],
|
||||
'oid' => $dataPost['order_id'],
|
||||
'state' => 1,
|
||||
'create_time' => date('Y-m-d H:i:s', time())
|
||||
];
|
||||
$res = Db::name('invoice_log')->insert($data);
|
||||
if ($res) {
|
||||
return $this->_success('申请成功');
|
||||
} else {
|
||||
return $this->_error('申请失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发票申请列表
|
||||
public function applyList()
|
||||
{
|
||||
$uid = $this->user_id;
|
||||
$list = InvoiceLog::with([
|
||||
'invoice' => function ($query) {
|
||||
$query->field('id,type,invoice_type,invoice_title');
|
||||
},
|
||||
'order' => function ($query) {
|
||||
$query->field('id,order_sn,settle_amount');
|
||||
}
|
||||
])->where('uid', $uid)->paginate(10);
|
||||
$data = [];
|
||||
if ($list != null){
|
||||
foreach ($list as $value){
|
||||
$data[] = [
|
||||
'id' => $value['id'],
|
||||
'state' => $value['state'],
|
||||
'type' => $value['invoice']['type'],
|
||||
'invoice_type' => $value['invoice']['invoice_type'],
|
||||
'invoice_title' => $value['invoice']['invoice_title'],
|
||||
'order_sn' => $value['order']['order_sn'] ?? '',
|
||||
'order_money' => $value['order']['settle_amount'] ?? 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
$datas = ['data_list' => $data, 'total' => $list->total()];
|
||||
return $this->_success('成功', $datas);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user