123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/5/25
- * Time: 17:43
- */
- namespace App\Http\Controllers\Api;
- use App\Services\CustomerInvoicesComplementService;
- use Illuminate\Http\Request;
- class CustomerInvoicesComplementController extends Controller
- {
- public function add(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'statements_id' => 'required|int',
- '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);
- }
- $statements_id = $request->input('statements_id');
- #判断开票资格
- if(!CustomerInvoicesComplementService::verifySetInvoice($statements_id)){
- return self::returnValue(['msg'=>'已经存在对应开票'], 7001);
- }
- $params = array();
- $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['url_json'] = json_encode($files);
- $res = CustomerInvoicesComplementService::add($statements_id, $params);
- return self::returnValue($res);
- }
- public function index(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'customer_name' => 'nullable|string',
- 'status' => 'nullable|int',
- 'page' => 'required|int|min:1',
- 'order_month' => 'nullable|date_format:Y-m',
- 'change_month' => 'nullable|date_format:Y-m',
- '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['applicant_id'] = $user->id;
- }
- $search['status'] = $request->input('status');
- $search['customer_name'] = $request->input('customer_name');
- $search['invoice_month'] = $request->input('invoice_month');
- $search['company'] = $request->input('company');
- $search['order_month'] = $request->input('order_month');
- $search['change_month'] = $request->input('change_month');
- $isExport = $request->input('is_export', 0);
- $search['approved_start_date'] = $request->input('approved_start_date');
- $search['approved_end_date'] = $request->input('approved_end_date');
- $page = (int)$request->input('page', 1);
- $pagesize = (int)$request->input('pagesize', 20);
- if($role_id == 16) {
- $search['status'] = 4;
- }
- list($data, $total) = CustomerInvoicesComplementService::index($search, $page, $pagesize, $isExport);
- return self::returnPageValue($data, $total, $pagesize, $page);
- }
- public function detail(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 = CustomerInvoicesComplementService::detail($id);
- return self::returnValue($res);
- }
- public function update(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);
- }
- $params = array();
- $params['tax_id'] = $request->input('tax_id');
- $params['address_tel'] = $request->input('address_tel');
- $params['bank_account'] = $request->input('bank_account');
- $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);
- }
- $id = (int)$request->input('id');
- $res = CustomerInvoicesComplementService::update($id, $params);
- if($res === 7002){
- return self::returnValue(['msg' => '非法操作'], $res);
- }
- return self::returnValue($res);
- }
- public function verify(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 = CustomerInvoicesComplementService::verify($id, $status, $verify_note);
- if( !$res ){
- return self::returnValue($res, 7003);
- }
- return self::returnValue($res);
- }
- public function actualInvoiced(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'ids' => 'required|array',
- 'date' => 'required|date'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $ids = $request->input('ids');
- $date = $request->input('date');
- $res = CustomerInvoicesComplementService::actualInvoiced($ids, $date);
- return self::returnValue($res);
- }
- public function delActualInvoiced(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- $res = CustomerInvoicesComplementService::delActualInvoiced($id);
- return self::returnValue($res);
- }
- }
|