123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/6/15
- * Time: 17:02
- */
- namespace App\Http\Controllers\Api;
- use App\Services\InvoiceService;
- use Illuminate\Http\Request;
- class CustomerInvoicesController extends Controller
- {
- /*
- * 发票作废申请
- */
- public function voidedOrderAdd(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'reason' => 'required|string',
- 'files' => 'required|array',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- $reason = $request->input('reason');
- $files = $request->input('files');
- if(!empty($files)){
- $files = array_map(function($val){
- return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
- },$files);
- }
- list($res, $code) = InvoiceService::voidedOrderAdd($id, $reason, $files);
- return self::returnValue($res, $code);
- }
- /*
- * 发票作废申请审批
- */
- public function verifyVoidedInvoice(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'status' => 'required|int',
- 'verify_note' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = (int)$request->input('id');
- $status = $request->input('status');
- $verifyNote = $request->input('verify_note');
- $res = InvoiceService::verifyVoidedInvoice($id, $status, $verifyNote);
- if( !$res ){
- return self::returnValue($res, 7003);
- }
- return self::returnValue($res);
- }
- public function voidedOrderUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'reason' => 'required|string',
- 'files' => 'required|array',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- $reason = $request->input('reason');
- $files = $request->input('files');
- if(!empty($files)){
- $files = array_map(function($val){
- return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
- },$files);
- }
- list($res, $code) = InvoiceService::voidedOrderUpdate($id, $reason, $files);
- return self::returnValue($res, $code);
- }
- /*
- * 新版发票编辑(删除原来的发票,并且生成新的发票)
- * 判断发票状态为驳回还是撤销
- */
- public function editInvoiceNew(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'tax_id' => 'nullable|string',
- 'address_tel' => 'nullable|string',
- 'bank_account' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $user = \Auth::user();
- $id = (int)$request->input('id');
- #判断开票资格
- if(!InvoiceService::verifyInvoiceReply($id)){
- return self::returnValue(['error'=>'已经重新申请开票了或者结算单被撤销了'], 1102);
- }
- $params = array();
- $params['tax_id'] = $request->input('tax_id');
- $params['address_tel'] = $request->input('address_tel');
- $params['bank_account'] = $request->input('bank_account');
- $params['service_type'] = $request->input('service_type');
- $params['consignee'] = $request->input('consignee');//收件人
- $params['contacts'] = $request->input('contacts');//联系人
- $params['contact_number'] = $request->input('contact_number');//联系电话
- $params['mail_address'] = $request->input('mail_address');//联系电话
- $params['note'] = $request->input('note');
- $files = $request->input('files');
- if(!empty($files)){
- $files = array_map(function($val){
- return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
- },$files);
- }
- $params['url_json'] = json_encode($files);
- $params = array_filter($params);
- if(empty($params)){
- return self::returnValue(['未做修改'], 4199);
- }
- list($res, $code) = InvoiceService::editInvoiceNew($id, $params);
- return self::returnValue($res, $code);
- }
- /*
- * 发票撤销(财务及出纳权限)
- * 财务审核通过状态
- * 直接将发票enable更新为0
- */
- public function invoiceCancel(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'verify_note' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = (int)$request->input('id');
- $verify_note = $request->input('verify_note');
- $res = InvoiceService::invoiceCancel($id, $verify_note);
- if( !$res ){
- return self::returnValue($res, 7003);
- }
- return self::returnValue($res);
- }
- /*
- * 发票撤回申请
- * 待审核状态
- */
- public function invoiceWithdraw(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = (int)$request->input('id');
- list($res, $code) = InvoiceService::invoiceWithdraw($id);
- return self::returnValue($res, $code);
- }
- // 红字发票申请列表
- public function redInvoicesList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'customer_name' => 'nullable|string',
- 'status' => 'nullable|int',
- 'cdate' => 'nullable|date',
- 'page' => 'required|int|min:1',
- 'approved_start_date' => 'nullable|date_format:Y-m-d',
- 'approved_end_date' => 'nullable|date_format:Y-m-d',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- $search = array();
- #销售媒介只能看自己提的
- if($role_id == 9 || $role_id == 11){
- $search['handler_id'] = $user->id;
- }
- $search['status'] = $request->input('status');
- $search['customer_name'] = $request->input('customer_name');
- $search['cdate'] = $request->input('cdate');
- $search['company'] = $request->input('company');
- $search['approved_start_date'] = $request->input('approved_start_date');
- $search['approved_end_date'] = $request->input('approved_end_date');
- $search['id'] = $request->input('id');
- $page = (int)$request->input('page', 1);
- $pagesize = (int)$request->input('pagesize', 20);
- list($data, $total) = InvoiceService::redInvoiceList($search, $page, $pagesize);
- return self::returnPageValue($data, $total, $pagesize, $page);
- }
- // 红字发票详情
- public function redInvoicesDetail(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = (int)$request->input('id');
- $res = InvoiceService::redInvoiceDetail($id);
- return self::returnValue($res);
- }
- // 红字发票审核
- public function redInvoicesVerify(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'status' => 'required|int',
- 'verify_note' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = (int)$request->input('id');
- $status = $request->input('status');
- $verify_note = $request->input('verify_note');
- $res = InvoiceService::redInvoicesVerify($id, $status, $verify_note);
- if(!$res) {
- return self::returnValue($res, 7003);
- }
- return self::returnValue($res, 0);
- }
- public function redInvoiceEdit(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'tax_id' => 'nullable|string',
- 'address_tel' => 'nullable|string',
- 'bank_account' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $user = \Auth::user();
- $id = (int)$request->input('id');
- #判断开票资格
- if(!InvoiceService::verifyRedInvoiceReply($id)){
- return self::returnValue(['error'=>'已经重新申请开票了'], 1102);
- }
- $params = array();
- $params['tax_id'] = $request->input('tax_id');
- $params['address_tel'] = $request->input('address_tel');
- $params['bank_account'] = $request->input('bank_account');
- $params['service_type'] = $request->input('service_type');
- $params['consignee'] = $request->input('consignee');//收件人
- $params['contacts'] = $request->input('contacts');//联系人
- $params['contact_number'] = $request->input('contact_number');//联系电话
- $params['mail_address'] = $request->input('mail_address');//联系电话
- $params['note'] = $request->input('note');
- $files = $request->input('files');
- if(!empty($files)){
- $files = array_map(function($val){
- return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
- },$files);
- }
- $params['url_json'] = json_encode($files);
- $params = array_filter($params);
- if(empty($params)){
- return self::returnValue(['未做修改'], 4199);
- }
- list($res, $code) = InvoiceService::editRedInvoiceNew($id, $params);
- return self::returnValue($res, $code);
- }
- /**
- * 红字发票申请导入
- */
- public function redApplyImport(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'file' => 'required|file'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $file = $request->file('file');
- $res = InvoiceService::redApplyImport($file);
- if ($res['code'] == 0) {
- return self::returnValue($res);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- /**
- * 红字发票申请导入文件详情
- */
- public function redApplyOrders(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'filename' => 'required|string'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $filename = $request->input('filename');
- $res = InvoiceService::redApplyOrders($filename);
- if (!empty($res)) {
- return self::returnValue($res);
- } else {
- return self::returnValue($res, 10001);
- }
- }
- /**
- * 红字发票申请导入文件详情
- */
- public function redApplyConfirm(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'filename' => 'required|string',
- 'invoice_type' => 'required|int',
- 'service_type' => 'required|string',
- 'invoice_note' => 'nullable|string',
- 'files' => 'required|array',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $user = \Auth::user();
- $filename = $request->input('filename');
- $params = array();
- $params['handler_id'] = $user->id;
- $params['handler'] = $user->real_name;
- $params['invoice_type'] = $request->input('invoice_type');
- $params['service_type'] = $request->input('service_type');
- $params['invoice_note'] = $request->input('invoice_note');
- $params['consignee'] = $request->input('consignee');//收件人
- $params['contacts'] = $request->input('contacts');//联系人
- $params['contact_number'] = $request->input('contact_number');//联系电话
- $params['mail_address'] = $request->input('mail_address');//联系电话
- $params['note'] = $request->input('note');
- $files = $request->input('files');
- if(!empty($files)){
- $files = array_map(function($val){
- return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
- },$files);
- }
- $params['urls'] = $files;
- list($res, $code) = InvoiceService::setRedInvoice($filename, $params);
- return self::returnValue($res, $code);
- }
- }
|