You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
5.1 KiB
141 lines
5.1 KiB
<?php
|
|
|
|
namespace app\controller\admin;
|
|
|
|
use app\model\InvoiceHead;
|
|
use app\util\ReturnCode;
|
|
use think\Response;
|
|
use app\model\InvoiceIssuance as InvoiceIssuanceModel;
|
|
|
|
class InvoiceIssuance extends Base
|
|
{
|
|
|
|
/**
|
|
* 获取发票申请列表
|
|
* @return Response
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function index(): Response
|
|
{
|
|
|
|
$param = $this->request->get();
|
|
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
|
|
$start = $this->request->get('page', 1);
|
|
|
|
$where = [];
|
|
|
|
if (isset($param['pucode']) && !empty($param['pucode'])) {
|
|
$where[] = ['pucode', 'like', "%{$param['pucode']}%"];
|
|
}
|
|
|
|
if (isset($param['project_id']) && !empty($param['project_id'])) {
|
|
$where[] = ['project_id', '=', $param['project_id']];
|
|
}
|
|
|
|
if (isset($param['mobile']) && !empty($param['mobile'])) {
|
|
$where[] = ['mobile', 'like', "%{$param['mobile']}%"];
|
|
}
|
|
|
|
if (isset($param['merge']) && !empty($param['merge'])) {
|
|
$where[] = ['merge', '=', $param['merge']];
|
|
}
|
|
|
|
if (isset($param['status']) && in_array($param['status'], [0, 3, 4])) {
|
|
$where[] = ['status', '=', $param['status']];
|
|
}
|
|
|
|
if (isset($param['start_time']) && !empty($param['start_time'])) {
|
|
$where[] = ['create_time', '>=', strtotime($param['start_time'] . ' 00:00:00')];
|
|
}
|
|
|
|
if (isset($param['end_time']) && !empty($param['end_time'])) {
|
|
$where[] = ['create_time', '<=', strtotime($param['end_time'] . ' 23:59:59')];
|
|
}
|
|
|
|
if (isset($param['head_type']) && in_array($param['status'], [0, 1])) {
|
|
$invoice_head_id = (new InvoiceHead())->where(['type' => $param['head_type']])->column('id');
|
|
$where[] = ['invoice_head_id', 'in', $invoice_head_id];
|
|
}
|
|
|
|
|
|
$InvoiceIssuanceModel = new InvoiceIssuanceModel();
|
|
$InvoiceHead = new InvoiceHead();
|
|
|
|
$field = 'id,project_id,merge,pucode,expire_time,mobile,email,create_time,status,amount,invoice_head_id,cancel_time,issuance_time,cancel_time';
|
|
|
|
$listObj = $InvoiceIssuanceModel->where($where)
|
|
->order('create_time', 'DESC')
|
|
->field($field)
|
|
->paginate(['page' => $start, 'list_rows' => $limit])->each(function ($item, $key) use ($InvoiceHead) {
|
|
|
|
$item->project_itle = InvoiceIssuanceModel::$projectArr[$item->project_id] ?? '';
|
|
$item->status = InvoiceIssuanceModel::$statusArr[$item->status] ?? '';
|
|
$item->merge = $item->merge ? '合并' : '不合并';
|
|
$item->expire_time = $item->expire_time ? date("Y-m", $item->expire_time) : '';
|
|
$item->cancel_time = $item->cancel_time ? date("Y-m-d H:i:s", $item->cancel_time) : '';
|
|
$item->issuance_time = $item->issuance_time ? date("Y-m-d H:i:s", $item->issuance_time) : '';
|
|
|
|
$InvoiceHeadRes = $InvoiceHead->where('id', $item->invoice_head_id)->find();
|
|
$item->head_type = '';
|
|
$item->head_title = '';
|
|
if ($InvoiceHeadRes) {
|
|
$item->head_type = InvoiceHead::$typeArr[$InvoiceHeadRes['type']];
|
|
$item->head_title = $InvoiceHeadRes['title'];
|
|
}
|
|
unset($item->invoice_head_id, $item->project_id);
|
|
})->toArray();
|
|
$listInfo = $listObj['data'];
|
|
|
|
return $this->buildSuccess([
|
|
'list' => $listInfo,
|
|
'count' => $listObj['total']
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取发票项目选项
|
|
* @return Response
|
|
*/
|
|
public function getIndexData(): Response
|
|
{
|
|
$projectArr = InvoiceIssuanceModel::$projectArr;
|
|
|
|
unset($projectArr[0]);
|
|
|
|
$keyArr = [];
|
|
foreach ($projectArr as $key => $value) {
|
|
$keyArr[] = [
|
|
'value' => $key,
|
|
'text' => $value
|
|
];
|
|
}
|
|
return $this->buildSuccess($keyArr);
|
|
}
|
|
|
|
/**
|
|
* 发票申请作废
|
|
* @return Response
|
|
*/
|
|
public function cancel(): Response
|
|
{
|
|
try {
|
|
$id = $this->request->get('id', '');
|
|
if (!$id) {
|
|
throw new \Exception('缺少必要参数');
|
|
}
|
|
$InvoiceIssuance = (new InvoiceIssuanceModel())->where('id', $id)->find();
|
|
if (in_array($InvoiceIssuance['status'], [3, 4])) {
|
|
$status = $InvoiceIssuance['status'] == 3 ? '已开票' : '已作废';
|
|
throw new \Exception($status . ',无法作废');
|
|
}
|
|
$data = ['status' => 4, 'cancel_time' => time()];
|
|
$result = $InvoiceIssuance->save($data);
|
|
if (!$result) {
|
|
throw new \Exception('作废失败');
|
|
}
|
|
return $this->buildSuccess();
|
|
} catch (\Exception $e) {
|
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|