123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/4/6
- * Time: 17:49
- */
- namespace App\Http\Controllers\Api;
- use App\Services\NewOrderService;
- use App\Services\NewStatementsService;
- use App\Services\SpecialColumnEditService;
- use Illuminate\Http\Request;
- use App\Services\OrderIncomeService;
- use App\Services\OrderMcnService;
- class NewOrderController extends Controller
- {
- /**
- * 模板导入数据
- */
- public function orderImportSecond(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'file' => 'required|file',
- 'type' => 'required|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $type = (int)$request->input('type');
- $file = $request->file('file');
- if( 1 == $type ) {
- // 2022年起作废
- $res = OrderIncomeService::salerOrderImport($file);
- } else if ( 2 == $type ) {
- $res = OrderMcnService::mcnOrderImport($file);
- } else if ( 3 == $type ) {
- $res = OrderMcnService::caOrderImport($file);
- } else if ( 4 == $type) {
- $res = OrderIncomeService::redInvoiceImport($file);
- }
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- public function salerOrderImportValidate(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'file' => 'required|file',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $userId = \Auth::id();
- $extArr = ['xlsx', 'xls', 'csv'];
- // 验证文件后缀是否合法
- $ext = strtolower($request->file('file')->getClientOriginalExtension());
- if(!in_array($ext, $extArr)) {
- return self::returnValue(['error' => '文件格式不合法'], 1102);
- }
- // 将文件保存到服务器
- $newFileName = $userId.'.'.$ext;// 新文件名,便于二次确认接口查找文件
- $fileName = $request->file('file')->storeAs('', $newFileName, 'uploads');
- $filePath = public_path('uploads').'/'.$fileName;// 拼接完整文件路径,因为读取文件时需要
- // 读取文件内容并验证
- $res = OrderIncomeService::salerOrderImportValidate($filePath);
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- public function salerOrderImportConfirm(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'confirm' => 'required|in:1,0',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $confirm = $request->input('confirm');
- $res = OrderIncomeService::salerOrderImportConfirm($confirm);
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- /**
- * 订单收入数据列表
- */
- public function orderIncomeList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'page' => 'required|int',
- 'pagesize' => 'nullable|int',
- 'amount_min' => 'nullable|numeric',
- 'amount_max' => 'nullable|numeric',
- 'final_amount_min' => 'nullable|numeric',
- 'final_amount_max' => 'nullable|numeric',
- 'launch_end_date_start' => 'nullable|date',
- 'launch_end_date_end' => 'nullable|date',
- 'if_public' => 'nullable|int',
- 'verify_status' => 'nullable|int',
- 'statements_status' => 'nullable|numeric',
- 'task_id' => 'nullable|string',
- ], [
- 'page.required' => '页码必传',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $search = $request->all();
- $page = $request->input('page', 1);
- $pageSize = $request->input('pagesize', 20);
- list($data, $total) = OrderIncomeService::orderIncomeList($page, $pageSize, $search);
- return self::returnPageValue($data, $total, $pageSize, $page);
- }
- /**
- * 单条编辑收入数据
- */
- public function orderIncomeUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'company' => 'nullable|string',
- 'salesman' => 'nullable|string',
- 'customer_name' => 'nullable|string',
- 'final_customer_name' => 'nullable|string',
- 'launch_start_date' => 'nullable|date',
- 'launch_end_date' => 'nullable|date',
- 'launch_platform' => 'nullable|string',
- 'amount' => 'nullable|numeric',
- 'internet_celebrity_name' => 'nullable|string',
- 'internet_celebrity_id' => 'nullable|string',
- 'final_amount' => 'nullable|numeric',
- 'actual_consumption_before' => 'nullable|numeric',
- 'link_fee_before' => 'nullable|numeric',
- 'flow_boost_back_point_before' => 'nullable|numeric',
- 'top_fee_before' => 'nullable|numeric',
- 'actual_consumption_after' => 'nullable|numeric',
- 'link_fee_after' => 'nullable|numeric',
- 'flow_boost_back_point_after' => 'nullable|numeric',
- 'top_fee_after' => 'nullable|numeric',
- 'customer_rebate_amount' => 'nullable|numeric',
- 'rebate_expense_receiving_unit' => 'nullable|string',
- 'income_red_invoice_date' => 'nullable|date',
- 'income_red_invoice_amount' => 'nullable|numeric',
- 'saler_note' => 'nullable|string',
- 'is_pdd_refund' => 'nullable|numeric',
- 'payment_date' => 'nullable|date',
- 'verify_edit' => 'nullable|int',
- ], [
- 'id.required' => '需选择订单',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- //获取当前角色
- $user = \Auth::user();
- $roleId = $user->role_id;
- $params = array();
- $params['company'] = trim($request->input('company', null));
- $params['customer_name'] = trim($request->input('customer_name', null));//客户全称
- $params['final_customer_name'] = trim($request->input('final_customer_name', null));
- $params['launch_platform'] = trim($request->input('launch_platform', null));
- // $params['media_name'] = trim($request->input('media_name', null));
- $params['internet_celebrity_name'] = trim($request->input('internet_celebrity_name', null));
- $params['internet_celebrity_id'] = trim($request->input('internet_celebrity_id', null));
- $params['launch_start_date'] = trim($request->input('launch_start_date', null));
- $params['launch_end_date'] = trim($request->input('launch_end_date', null));
- $params['payment_date'] = trim($request->input('payment_date', null)); //回款日期
- $params['salesman'] = trim($request->input('salesman', null));
- $params['project_name'] = trim($request->input('project_name', null));
- $params['amount'] = trim($request->input('amount', null));
- $params['final_amount'] = trim($request->input('final_amount', null));
- $params['actual_consumption_before'] = trim($request->input('actual_consumption_before', null)); //实际消耗
- $params['link_fee_before'] = trim($request->input('link_fee_before', null)); //链接费
- $params['flow_boost_back_point_before'] = trim($request->input('flow_boost_back_point_before', null)); //流量助推
- $params['top_fee_before'] = trim($request->input('top_fee_before', null)); //置顶费
- $params['actual_consumption_after'] = trim($request->input('actual_consumption_after', null)); //实际消耗
- $params['link_fee_after'] = trim($request->input('link_fee_after', null)); //链接费
- $params['flow_boost_back_point_after'] = trim($request->input('flow_boost_back_point_after', null)); //流量助推
- $params['top_fee_after'] = trim($request->input('top_fee_after', null)); //置顶费
- $params['customer_rebate_amount'] = trim($request->input('customer_rebate_amount', null));
- $params['rebate_expense_receiving_unit'] = trim($request->input('rebate_expense_receiving_unit', null)); //暂估返点支出收款单位
- $params['income_red_invoice_date'] = trim($request->input('income_red_invoice_date', null)); //开具红字发票日期
- $params['income_red_invoice_amount'] = trim($request->input('income_red_invoice_amount', null)); //开具红字发票金额
- $params['cpa_single_quantity'] = trim($request->input('cpa_single_quantity', null)); //cpa单量
- $params['saler_note'] = trim($request->input('saler_note', null)); //(备注)利润异常原因
- // $params['if_public'] = $request->input('if_public');
- $id = (int)$request->input('id');
- $verifyEdit = (int)$request->input('verify_edit');
- //锁单修改提交审核
- if($verifyEdit){
- $opReason = $request->input('op_reason');
- if(12 == $roleId) {
- $res = SpecialColumnEditService::orderIncomeVerifyAdd($id, $params, $opReason, $roleId);
- } else {
- $res = OrderIncomeService::orderIncomeVerifyAdd($id, $params, $opReason, $roleId);
- }
- } else {
- //正常修改
- $res = OrderIncomeService::orderIncomeUpdate($id, $params, $roleId);
- }
- if( is_numeric($res) && in_array($res, [
- 1216, 1217, 1223, 1224, 1225, 1228, 1232,
- 2002,
- 3015, 3016, 3017,
- 4199, 4200, 4201, 4205,
- 5005,
- 6003 ]) ){
- return self::returnValue(['msg' => '操作有误'], $res);
- }
- return self::returnValue($res);
- }
- /**
- * 批量删除订单
- */
- public function orderIncomeBatchDel(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id_list' => 'required',
- ], [
- 'id_list.required' => '需选择订单',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $idList = $request->input('id_list');
- list($res, $code) = OrderIncomeService::orderIncomeBatchDel($idList);
- return self::returnValue($res, $code);
- }
- /*
- * 单条编辑mcn数据
- */
- public function orderMcnUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'mcn_name' => 'nullable|string',
- 'mcn_rebate' => 'nullable|string',
- 'mcn_handler' => 'nullable|string',
- 'mcn_user' => 'nullable|string',
- 'organization_amount' => 'nullable|string',
- 'mcn_final_amount' => 'nullable|string',
- ], [
- 'id.required' => '需选择订单',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- //获取当前角色
- $user = \Auth::user();
- $roleId = $user->role_id;
- $params = array();
- $params['mcn_name'] = trim($request->input('mcn_name'));//客户全称
- $params['mcn_handler'] = trim($request->input('mcn_handler'));
- $params['mcn_user'] = trim($request->input('mcn_user'));
- $params['organization_amount'] = trim($request->input('organization_amount'));
- $params['mcn_final_amount'] = trim($request->input('mcn_final_amount'));
- $id = (int)$request->input('id');
- $verifyEdit = (int)$request->input('verify_edit');
- //锁单修改提交审核
- if($verifyEdit){
- $opReason = $request->input('op_reason');
- if(12 == $roleId) {
- $res = SpecialColumnEditService::orderMcnVerifyAdd($id, $params, $opReason, $roleId);
- } else {
- $res = OrderMcnService::orderMcnVerifyAdd($id, $params, $opReason, $roleId);
- }
- } else {
- $res = OrderMcnService::orderMcnUpdate($id, $params, $roleId);
- }
- if( is_numeric($res) && in_array($res, [
- 1216,
- 2002,
- 4199, 4200, 4201, 4205,
- 6003, 6007, 6008
- ]) ){
- return self::returnValue(['msg' => '操作有误'], $res);
- }
- return self::returnValue($res);
- }
- public function orderMcnList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'page' => 'required|int',
- 'page_size' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $search = $request->all();
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $isExport = (int)$request->input('is_export');
- list($data, $total) = OrderMcnService::orderMcnList($page, $pageSize, $search, $isExport);
- return self::returnPageValue($data, $total, $pageSize, $page);
- }
- public function orderMcnBatchDel(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id_list' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $idList = $request->input('id_list');
- list($res, $code) = OrderMcnService::orderMcnBatchDel($idList);
- return self::returnValue($res, $code);
- }
- public function batchSetRedInvoice(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id_list' => 'required',
- 'red_invoice_date' => 'nullable|date',
- 'refund_invoice_date' => 'nullable|date',
- ], [
- 'id_list.required' => '需选择订单',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $idList = $request->input('id_list');
- $redInvoiceDate = $request->input('red_invoice_date');
- $refundInvoiceDate = $request->input('refund_invoice_date');
- $res = NewOrderService::batchSetRedInvoice($idList, $redInvoiceDate, $refundInvoiceDate);
- return self::returnValue($res);
- }
- public function lockMonthOrderSecond(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required|string',
- 'type' => 'required|int',
- ], [
- 'month.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $month = $request->input('month');
- $month = date('Y-m-01', strtotime($month) );
- $type = (int)$request->input('type');
- if( !NewOrderService::note($month, $type)) {
- return self::returnValue([], 8002);
- }
- if( !NewOrderService::enableLock($month, $type) ){
- return self::returnValue([], 8001);
- }
- list($res, $code) = NewOrderService::lockMonthOrder($month, $type);
- return self::returnValue($res, $code);
- }
- /**
- * 解锁-财务退回
- */
- public function unlockOrder(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required|string',
- ], [
- 'month.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $month = $request->input('month');
- $month = date('Y-m-01', strtotime($month) );
- list($res, $code) = NewOrderService::unlockOrder($month);
- return self::returnValue($res, $code);
- }
- public function batchVerifyDetail(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'edit_ids' => 'required',
- ], [
- 'edit_ids.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $editIdList = $request->input('edit_ids');
- list($code, $list) = NewOrderService::batchVerifyDetail($editIdList);
- return self::returnValue($list, $code);
- }
- public function batchVerify(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'edit_ids' => 'required',
- 'verify_status' => 'required|int',
- 'reason' => 'nullable|string'
- ], [
- 'edit_ids.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $editIdList = $request->input('edit_ids');
- $verifyStatus = $request->input('verify_status');
- $reason = $request->input('reason');
- list($code, $res) = NewOrderService::batchVerify($editIdList, $verifyStatus, $reason);
- return self::returnValue($res, $code);
- }
- public function getAllMonthList()
- {
- $list = NewOrderService::getAllMonthList();
- return self::returnValue($list);
- }
- /**
- * 撤销审核订单
- */
- public static function delVerifyOrderSecond(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'nullable|int',
- 'order_id' => 'nullable|int',
- 'type' => 'required|in:1,2'
- ], [
- 'id.int' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $id = $request->input('id');
- $order_id = $request->input('order_id');
- $type = $request->input('type');
- if(!$id && !$order_id){
- return self::returnValue(null, 1102);
- }
- $res = NewOrderService::delVerifyOrderSecond($id, $order_id, $type);
- if( !$res ){
- return self::returnValue($res, 4401);
- }
- return self::returnValue($res);
- }
- /*
- * 批量修改
- */
- public function importUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'file' => 'required|file',
- 'reason' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $file = $request->file('file');
- $reason = $request->input('reason');
- $res = NewOrderService::importUpdate($file, $reason);
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- public function enableBatchUpdateField()
- {
- $list = config('batch_update');
- //获取当前角色
- $user = \Auth::user();
- $roleId = $user->role_id;
- if($roleId != 12) {
- unset($list['customer_rebate_amount']);
- unset($list['rebate_expense_receiving_unit']);
- }
- return self::returnValue(array_values($list));
- }
- public function verifyZeroOrder(Request $request) {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required|string',
- 'type' => 'required|int',
- ], [
- 'month.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $month = $request->input('month');
- $month = date('Y-m-01', strtotime($month) );
- $type = (int)$request->input('type');
- // if(2 == $type) {
- // return self::returnValue([]);
- // }
- $data = NewOrderService::verifyZeroOrder($month);
- return self::returnValue($data);
- }
- public function deleteZeroOrder(Request $request) {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required|string',
- ], [
- 'month.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $month = $request->input('month');
- $month = date('Y-m-01', strtotime($month) );
- $code = 0;
- $data = NewOrderService::deleteZeroOrder($month, $code);
- return self::returnValue($data, $code);
- }
- public function zeroOrderList(Request $request) {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required|string',
- ], [
- 'month.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $month = $request->input('month');
- $month = date('Y-m-01', strtotime($month) );
- $data = NewOrderService::zeroOrderList($month);
- return self::returnValue($data);
- }
- }
|