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.
 
 
 
 
 
 
zhishifufei_php/application/wap/controller/Invoice.php

210 lines
5.7 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\controller;
use app\wap\model\wap\InvoiceRecords;
use service\JsonService;
use think\Validate;
use think\Request;
/**会员控制器
* Class Member
* @package app\wap\controller
*/
class Invoice extends AuthController
{
protected $invoiceModel;
protected $invoiceRecordsModel;
public function _initialize()
{
parent::_initialize();
$this->invoiceModel = new \app\wap\model\wap\Invoice();
$this->invoiceRecordsModel = new InvoiceRecords();
}
/**
* 白名单
* */
public static function WhiteList()
{
return [
];
}
/**
* 开票记录
* @param Request $request
* @return null
*/
public function records(Request $request)
{
$page = $request->get('page', 1); // 当前页码
$limit = $request->get('limit', 20); // 每页显示的记录数
$invoiceList = $this->invoiceRecordsModel->order('id', 'desc')->paginate($limit, false, ['page' => $page]);
$totalCount = $invoiceList->total();
$data = [
'page' => $page,
'total' => $totalCount,
'list' => $invoiceList->items(),
];
return JsonService::successful($data);
}
/**
* 开发票
* @param Request $request
* @return null
*/
public function make(Request $request)
{
$postData = $request->post();
$rule = [
'order_number' => 'require',
'invoice_amount' => 'require|float',
'header_type' => 'require|in:1,2',
'invoice_header' => 'require',
'tax_number' => 'require',
'address' => 'require',
'bank' => 'require'
];
$validate = new Validate($rule);
$validate->rule([
'tax_number' => 'requireIf:header_type,2',
'address' => 'requireIf:header_type,2',
'bank' => 'requireIf:header_type,2'
]);
if (!$validate->check($postData)) {
JsonService::fail($validate->getError());
}
$postData['uid'] = $this->uid;
$invoice = $this->invoiceRecordsModel->create($postData);
return JsonService::successful($invoice);
}
/**
* 抬头列表
* @param Request $request
* @return null
*/
public function list(Request $request)
{
$page = $request->get('page', 1); // 当前页码
$limit = $request->get('limit', 20); // 每页显示的记录数
$invoiceList = $this->invoiceModel->order('id', 'desc')->paginate($limit, false, ['page' => $page]);
$totalCount = $invoiceList->total();
$data = [
'page' => $page,
'total' => $totalCount,
'list' => $invoiceList->items(),
];
return JsonService::successful($data);
}
/**
* 添加抬头
* @param Request $request
* @return null
*/
public function add(Request $request)
{
$postData = $request->post();
if (isset($postData['id'])) {
unset($postData['id']);
}
$this->_validate($postData);
$postData['uid'] = $this->uid;
$invoice = $this->invoiceModel->create($postData);
return JsonService::successful($invoice);
}
/**
* 修改抬头
* @param Request $request
* @return null
*/
public function edit(Request $request)
{
$postData = $request->post();
$this->_validate($postData, true);
$invoice = $this->invoiceModel->find($postData['id']);
if (!$invoice) {
return JsonService::fail('没有发票信息');
}
$postData['uid'] = $this->uid;
$invoice->save($postData);
return JsonService::successful($invoice);
}
/**
* 删除抬头
* @param Request $request
* @return null
*/
public function delete(Request $request)
{
$postData = $request->post();
$invoice = $this->invoiceModel->find($postData['id']);
if (!$invoice) {
return JsonService::fail('没有发票信息');
}
$invoice->delete();
return JsonService::successful();
}
private function _validate($postData, $edit = false)
{
$rule = [
'header_type' => 'require|in:1,2',
'invoice_header' => 'require',
'tax_number' => 'require',
'address' => 'require',
'bank' => 'require'
];
if ($edit) {
$rule['id'] = 'require';
}
$validate = new Validate($rule);
$validate->rule([
'tax_number' => 'requireIf:header_type,2',
'address' => 'requireIf:header_type,2',
'bank' => 'requireIf:header_type,2'
]);
if (!$validate->check($postData)) {
JsonService::fail($validate->getError());
}
}
}