123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Models\Order;
- use App\Models\MonthOrder;
- use App\Services\ProjectService;
- use App\Services\OrderService;
- use App\Services\OssServices;
- use App\Services\InvoiceService;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- class OrderController extends Controller
- {
- /**
- * 项目订单列表(废弃)
- */
- public function projectOrder(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'project_id' => 'required|int',
- 'internet_celebrity_name' => 'nullable|string',
- 'cost_company_name' => 'nullable|string'
- ], [
- 'project_id.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $project_id = $request->input('project_id');
- $internet_celebrity_name = $request->input('internet_celebrity_name');
- $cost_company_name = $request->input('cost_company_name');
- $page = $request->input('page', 1);
- $pagesize = $request->input('pagesize', 20);
- $data = OrderService::projectIndex($page, $pagesize, $project_id, $internet_celebrity_name,
- $cost_company_name);
- #计算项目订单总计信息
- list($account, $orderTotal) = OrderService::getProjectOrderCount($project_id, $cost_company_name);
- $info = [
- 'account'=>$account,
- 'orderTotal'=>$orderTotal
- ];
- return self::returnValue(['data' => $data, 'info' => $info]);
- }
- /**
- * AE添加订单
- */
- public function add(Request $request)
- {
- $unique = [
- 'task_id' => $request->task_id,
- 'month' => date('Y-m-01', strtotime($request->month)),
- 'enable' => 1
- ];
- $validator = \Validator::make($request->all(), [
- 'project_name' => 'required|string',
- 'salesman' => 'nullable|string',
- 'month' => 'required|date',
- 'task_id' => ['required',Rule::unique('order')->where(function($query) use ($unique) {
- return $query->where($unique);
- })],
- // 'handler' => 'required|string',
- 'advertiser_account' => 'required|string',
- 'advertiser_id' => 'required|string',
- 'company' => 'required|string',
- 'customer_name' => 'required|string',
- 'launch_platform' => 'required|string',
- 'media_name' => 'required|string',
- 'internet_celebrity_name' => 'nullable|string',
- 'internet_celebrity_id' => 'nullable|string',
- 'amount' => 'required|numeric',
- 'final_amount' => 'required|numeric',
- 'launch_start_date' => 'required|date',
- 'launch_end_date' => 'required|date',
- 'billing_date' => 'nullable|date',
- 'payment_date' => 'nullable|date',
- 'uninvoiced_amount' => 'nullable|numeric',
- 'invoice_amount' => 'nullable|numeric',
- 'saler_note' => 'nullable|string',
- 'if_public' => 'nullable|int',
- 'cost' => 'nullable|numeric',
- 'traffic_boost_sum' => 'nullable|numeric',
- 'top_fee' => 'nullable|numeric',
- ], [
- 'project_id.required' => '参数有误',
- 'salesman.required' => '销售人员必填',
- 'customer_name.required' => '客户全称必填',
- 'launch_platform.required' => '投放平台必填',
- 'media_name.required' => '媒体名称必填',
- 'launch_start_date.required' => '投放起始日期必填',
- 'launch_end_date.required' => '投放截止日期必填',
- 'amount.required' => '订单金额必填',
- 'final_amount.required' => '订单最终收入金额必填',
- 'advertiser_id.required' => '账户id必填',
- 'advertiser_account.required' => '账户名称必填',
- 'company.required' => '签约公司名称必填',
- 'month.required' => '所属月份必填',
- 'task_id.required' => '任务id必填',
- 'project_name.required' => '项目名称必填'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = array();
- $user = \Auth::user();
- #获取所有锁单的月份
- $lock_months = MonthOrder::where('enable', 1)->pluck('month')->toArray();
- // $project_id = $request->input('project_id');
- // $project = ProjectService::detail($project_id);
- // $params['project_id'] = $project_id;
- $params['project_name'] = $request->input('project_name');
- $project = ProjectService::getProject($params['project_name']);
- $params['project_id'] = $project->id;
- $params['company'] = $request->input('company');
- $month = $request->input('month');
- $params['month'] = date('Y-m-01', strtotime($month));
- #销售不能添加锁单订单
- if( in_array($params['month'], $lock_months) && $user->role_id==11){
- return self::returnValue([], 4202);
- }
- $params['advertiser_account'] = $request->input('advertiser_account');
- $params['advertiser_id'] = $request->input('advertiser_id');
- #项目带入-可编辑参数
- $params['salesman'] = $request->input('salesman', $user->real_name);
- $params['handler'] = $user->real_name;
- $params['customer_name'] = $request->input('customer_name');
- $params['origin_customer_name'] = $params['customer_name'];
- $params['launch_platform'] = $request->input('launch_platform');
- $params['media_name'] = $request->input('media_name');
- $params['handlers_id'] = $user->id;
- // $orderMd5 = md5($params['salesman'].$params['handler'].$params['customer_name'].$params['launch_platform'].$params['media_name'].$project_id.time());
- // $oldMd5 = $request->input('order_md5', null);
- // $params['order_md5'] = $oldMd5 ? $oldMd5 : $orderMd5;
- #媒体名称连带
- $media = OrderService::getMedia( $params['media_name'] );
- $params['cost_company_name'] = $request->input('cost_company_name',$media->company); //成本公司全称 媒体表media_config带入company
- $params['cost_owner'] = $media->cost_owner; //成本负责人 媒体表media_config带入cost_owner
- //$params['saler_id'] = $request->input('saler_id', $user->id);
- $params['task_id'] = $request->input('task_id');
- //填写参数
- $params['internet_celebrity_name'] = $request->input('internet_celebrity_name');
- $params['internet_celebrity_id'] = $request->input('internet_celebrity_id');
- $params['amount'] = $request->input('amount');
- $params['final_amount'] = $request->input('final_amount');
- $params['origin_amount'] = $params['final_amount'];
- $params['launch_start_date'] = $request->input('launch_start_date');
- $params['launch_end_date'] = $request->input('launch_end_date');
- $params['billing_date'] = $request->input('billing_date');
- $params['payment_date'] = $request->input('payment_date');
- $params['uninvoiced_amount'] = $request->input('uninvoiced_amount');
- //$params['unbilled_voucher'] = $request->input('unbilled_voucher');
- #新加填写参数
- $params['invoice_amount'] = $request->input('invoice_amount'); //开票金额
- $params['saler_note'] = $request->input('saler_note'); //(备注)利润异常原因
- $params['if_public'] = $request->input('if_public');
- $params['cost'] = $request->input('cost'); //成本消耗
- $params['traffic_boost_sum'] = $request->input('traffic_boost_sum'); //流量助推合计
- #$params['top_fee'] = $request->input('top_fee'); //置顶费
- $params['rebate_spending_ratio'] = $request->input('rebate_spending_ratio'); //返点支出比例
- $params['rebate_expense_receiving_unit'] = $request->input('rebate_expense_receiving_unit'); //返点支出收款单位
- if($params['launch_start_date'] > $params['launch_end_date']){
- return self::returnValue(['msg' => '参数有误'], 1201);
- }
- //全局带入参数
- $global_config = OrderService::getRateConf($params['month'], $params['media_name'], $params['if_public'], $params['company']);
- $params['ratio_of_consumption_to_top_rebate'] = $global_config->ratio_of_consumption_to_top_rebate ;//消耗与置顶返点比例
- $params['flow_boost_rebate_ratio'] = $global_config->flow_boost_rebate_ratio; //流量助推返点比例
-
- $params['status'] = 1; //AE填写完成
- $res = OrderService::add($params);
- return self::returnValue($res);
- }
- /**
- * 订单编辑
- */
- public static function update(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'salesman' => 'nullable|string',
- // 'handler' => 'nullable|string',
- 'customer_name' => 'nullable|string',
- 'launch_platform' => 'nullable|string',
- 'media_name' => 'nullable|string',
- 'internet_celebrity_name' => 'nullable|string',
- 'internet_celebrity_id' => 'nullable|string',
- 'amount' => 'nullable|numeric',
- 'final_amount' => 'nullable|numeric',
- 'launch_start_date' => 'nullable|date',
- 'launch_end_date' => 'nullable|date',
- 'billing_date' => 'nullable|date',
- 'project_name_second' => 'nullable|string',
- 'if_public' => 'nullable|int',
- 'cost' => 'nullable|numeric',
- 'traffic_boost_sum' => 'nullable|numeric',
- 'traffic_boost_refund' => 'nullable|numeric',
- 'traffic_boost_money' => 'nullable|numeric',
- 'top_fee' => 'nullable|numeric',
- 'offline_subsidy_amount' => 'nullable|numeric',
- 'cost_invoice_status' => 'nullable|string',
- 'rebate_spending_ratio' => 'nullable|numeric',
- 'rebate_expense_receiving_unit' => 'nullable|string',
- 'note' => 'nullable|string',
- 'payment_date' => 'nullable|date',
- 'document_number_first' => 'nullable|string',
- 'document_number_second' => 'nullable|string',
- 'document_number_third' => 'nullable|string',
- 'document_number_four' => 'nullable|string',
- 'document_number_five' => 'nullable|string',
- 'document_number_six' => 'nullable|string',
- 'offline_subsidy_company' => 'nullable|string',
- 'payes' => 'nullable|string',
- 'payment_time' => 'nullable|date',
- 'uninvoiced_amount' => 'nullable|numeric',
- 'unbilled_voucher' => 'nullable|string',
- 'invoice_amount' => 'nullable|numeric',
- 'confirmation_certificate' => 'nullable|string',
- 'confirmed_cost_includes_tax' => 'nullable|numeric',
- 'confirmed_cost' => 'nullable|numeric',
- 'document_number_seven' => 'nullable|string',
- 'verify_edit' => 'nullable|int',
- 'op_reason' => 'nullable|string',
- 'saler_note' => 'nullable|string',
- 'confirmation_certificate_first' => 'nullable|string',
- 'confirmation_certificate_third' => 'nullable|string',
- 'confirmation_certificate_four' => 'nullable|string',
- 'confirmation_certificate_five' => 'nullable|string',
- 'confirmation_certificate_six' => 'nullable|string',
- 'confirmation_certificate_seven' => 'nullable|string',
- 'mcn_name' => 'nullable|string',
- 'mcn_rebate' => 'nullable|numeric',
- 'mcn_handler' => 'nullable|string',
- 'mcn_handler_id' => 'nullable|int',
- 'mcn_user_id' => 'nullable|int',
- 'mcn_document_number' => 'nullable|string',
- 'mcn_confirmation_certificate' => 'nullable|string',
- ], [
- 'id.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- $params = array();
- #项目带入-可编辑参数
- // $params['handler'] = $request->input('handler');
- $params['customer_name'] = trim($request->input('customer_name'));
- $params['origin_customer_name'] = $params['customer_name'];
- $params['launch_platform'] = trim($request->input('launch_platform'));
- $params['media_name'] = trim($request->input('media_name'));
- $params['cost_company_name'] = $request->input('cost_company_name');
- //AE填写参数
- $params['internet_celebrity_name'] = trim($request->input('internet_celebrity_name'));
- $params['internet_celebrity_id'] = trim($request->input('internet_celebrity_id'));
- $params['amount'] = trim($request->input('amount'));
- $params['final_amount'] = trim($request->input('final_amount'));
- $params['origin_amount'] = $params['final_amount'];
- $params['launch_start_date'] = trim($request->input('launch_start_date'));
- $params['launch_end_date'] = trim($request->input('launch_end_date'));
- $params['billing_date'] = trim($request->input('billing_date'));
- $params['payment_date'] = trim($request->input('payment_date')); //回款日期
- $params['uninvoiced_amount'] = trim($request->input('uninvoiced_amount')); //未开票金额
- //$params['invoice_amount'] = $request->input('invoice_amount'); //开票金额
- $params['saler_note'] = trim($request->input('saler_note')); //(备注)利润异常原因
-
- #媒介参数(销售可填的)
- $params['if_public'] = (int)$request->input('if_public');
- //$params['cost'] = $request->input('cost'); //成本消耗 3.3 不再允许销售修改
- //$params['traffic_boost_sum'] = $request->input('traffic_boost_sum'); //流量助推合计
-
- $params['rebate_spending_ratio'] = trim($request->input('rebate_spending_ratio')); //返点支出比例
- $params['rebate_expense_receiving_unit'] = trim($request->input('rebate_expense_receiving_unit')); //返点支出收款单位
-
- #媒介或媒介审核单独填写
- if( in_array($role_id, [1, 9, 13]) ){
- $params['salesman'] = trim($request->input('salesman'));
- #$params['project_name_second'] = $request->input('project_name_second');
- $params['offline_subsidy_amount'] = trim($request->input('offline_subsidy_amount')); //线下补款金额
- $params['note'] = trim($request->input('note')); //备注
- $params['offline_subsidy_company'] = trim($request->input('offline_subsidy_company')); //付款公司名称
- $company = OrderService::getCompany($params['offline_subsidy_company']);
- if(isset($company->rebate)) $params['sr_rate'] = $company->rebate;
- $params['payes'] = trim($request->input('payes')); //收款人
- $params['cost'] = trim($request->input('cost')); //成本消耗
- $params['top_fee'] = trim($request->input('top_fee')); //置顶费
- $params['traffic_boost_sum'] = trim($request->input('traffic_boost_sum')); //流量助推合计
- $params['traffic_boost_refund'] = trim($request->input('traffic_boost_refund')); //流量助推合计
- $params['traffic_boost_money'] = trim($request->input('traffic_boost_money')); //流量助推合计
- #多加mcn信息
- $params['mcn_name'] = trim($request->input('mcn_name'));
- $params['mcn_rebate'] = trim($request->input('mcn_rebate'));
- $params['origin_mcn_rebate'] = $params['mcn_rebate'];
- $params['mcn_handler'] = trim($request->input('mcn_handler'));
- $params['mcn_handler_id'] = trim($request->input('mcn_handler_id'));
- /*if(!empty($params['mcn_name'])){
- $params['mcn_user_id'] = $user->id;
- $params['mcn_user'] = $user->real_name;
- } */
- }
- #财务填写
- if( in_array($role_id, [1, 10]) ){
- $params['document_number_first'] = trim($request->input('document_number_first')); //凭证号
- $params['document_number_second'] = trim($request->input('document_number_second')); //凭证号
- $params['document_number_third'] = trim($request->input('document_number_third')); //凭证号
- $params['document_number_four'] = trim($request->input('document_number_four')); //凭证号
- $params['document_number_five'] = trim($request->input('document_number_five')); //凭证号
- $params['document_number_six'] = trim($request->input('document_number_six')); //凭证号
- $params['document_number_seven'] = trim($request->input('document_number_seven'));//凭证号
- $params['confirmation_certificate_first'] = trim($request->input('confirmation_certificate_first'));//凭证确认
- $params['confirmation_certificate_third'] = trim($request->input('confirmation_certificate_third'));//凭证确认
- $params['confirmation_certificate_four'] = trim($request->input('confirmation_certificate_four'));//凭证确认
- $params['confirmation_certificate_five'] = trim($request->input('confirmation_certificate_five'));//凭证确认
- $params['confirmation_certificate_six'] = trim($request->input('confirmation_certificate_six'));//凭证确认
- $params['confirmation_certificate_seven'] = trim($request->input('confirmation_certificate_seven'));//凭证确认
-
- $params['unbilled_voucher'] = trim($request->input('unbilled_voucher')); //未开票凭证
- $params['confirmation_certificate'] = trim($request->input('confirmation_certificate')); //确认凭证
- $params['confirmed_cost_includes_tax'] = trim($request->input('confirmed_cost_includes_tax')); //确认成本含税
- $params['confirmed_cost'] = trim($request->input('confirmed_cost')); //确认成本不含税
- $params['cost_invoice_status'] = trim($request->input('cost_invoice_status')); //成本发票情况
- $params['mcn_document_number'] = trim($request->input('mcn_document_number'));
- $params['mcn_confirmation_certificate'] = trim($request->input('mcn_confirmation_certificate'));
- }
- if( empty($params) ){
- return self::returnValue(['msg' => '未做任何修改'], 4199);
- }
- $id = (int)$request->input('id');
- $verify_edit = (int)$request->input('verify_edit');
- //锁单修改提交审核
- if($verify_edit){
- $op_reason = $request->input('op_reason');
- $res = OrderService::orderVerifyAdd($id, $params, $op_reason, $role_id);
- } else {
- //正常修改
- $res = OrderService::update($id, $params, 2, $role_id);
- }
- if( is_numeric($res) && in_array($res, [4199, 4200, 4201]) ){
- return self::returnValue(['msg' => '操作有误'], $res);
- }
- return self::returnValue($res);
- }
- /**
- * 删除订单
- */
- public static function batchDel(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'ids' => 'required|array',
- ], [
- 'ids.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $ids = $request->input('ids');
- $res = OrderService::batchDel($ids);
- if(!$res){
- return self::returnValue($res, 7004);
- }
- return self::returnValue($res);
- }
- /**
- * 查看订单修改记录
- */
- public static function getEditInfo(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- ], [
- 'id.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $id = $request->input('id');
- $res = OrderService::getEditInfo($id);
- return self::returnValue($res);
- }
- /**
- * 锁单
- */
- public static function lockOrder(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- ], [
- 'id.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $id = $request->input('id');
- $res = OrderService::lockOrder($id);
- return self::returnValue($res);
- }
- /**
- * 订单列表
- */
- public function index(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'page' => 'required|int',
- 'pagesize' => 'nullable|int',
- 'internet_celebrity_name' => 'nullable|string',
- 'salesman' => 'nullable|string',
- 'handler' => 'nullable|string',
- 'customer_name' => 'nullable|string',
- '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',
- 'billing_date_start' => 'nullable|date',
- 'billing_date_end' => 'nullable|date',
- 'project_name_second' => 'nullable|string',
- 'if_public' => 'nullable|int',
- 'cost_min' => 'nullable|numeric',
- 'cost_max' => 'nullable|numeric',
- 'rebate_spending_ratio' => 'nullable|numeric',
- 'rebate_expense_receiving_unit' => 'nullable|string',
- 'payment_date_start' => 'nullable|date',
- 'payment_date_end' => 'nullable|date',
- 'advertiser_account' => 'nullable|string',
- 'advertiser_id' => 'nullable|string',
- 'verify_status' => 'nullable|int',
- 'statements_status' => 'nullable|numeric',
- 'media_name' => 'nullable|string',
- 'task_id' => 'nullable|string',
- 'mcn_name' => 'nullable|string',
- 'is_refund' => 'nullable|int',
- // 'traffic_boost_money_min' => 'nullable|numeric',
- // 'traffic_boost_money_max' => 'nullable|numeric',
- // 'traffic_boost_refund_min' => 'nullable|numeric',
- // 'traffic_boost_refund_max' => 'nullable|numeric',
- // 'top_fee_min' => 'nullable|numeric',
- // 'top_fee_max' => 'nullable|numeric',
- // 'offline_subsidy_amount_min' => 'nullable|numeric',
- // 'offline_subsidy_amount_max' => 'nullable|numeric',
- ], [
- 'page.required' => '页码必传',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $search = $request->all();
- $page = $request->input('page', 1);
- $pagesize = $request->input('pagesize', 20);
- $is_export = (int)$request->input('is_export');
- list($data, $total, $info) = OrderService::index($page, $pagesize, $search, $is_export);
- return self::returnPageValue($data, $total, $pagesize, $page, $info);
- }
- /**
- * 订单搜索条件下拉项搜索
- */
- public function columnSearch(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'column' => 'required|string',
- 'keyword' => 'nullable|string',
- ], [
- 'column.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $column = $request->input('column');
- $keyword = $request->input('keyword');
- $res = OrderService::columnSearch($column, $keyword);
- return self::returnValue($res);
- }
- /**
- * 月度消耗表
- */
- public function orderMonthList(Request $request)
- {
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- $status = $request->input('status');
- $page = (int)$request->input('page', 1);
- $pagesize = (int)$request->input('pagesize', 20);
- list($data, $total) = OrderService::orderMonthList($role_id, $page, $pagesize, $status);
- return self::returnPageValue($data, $total, $pagesize, $page);
- }
- /**
- * 月度订单提交财务
- */
- public static function lockMonthOrder(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) );
- $res = OrderService::lockMonthOrder($month);
- return self::returnValue($res);
- }
- /**
- * 获取修改审核订单
- */
- public function getOrderEditing(Request $request)
- {
- $page = (int)$request->input('page', 1);
- $pagesize = (int)$request->input('pagesize', 20);
- $search['month'] = $request->input('month');
- if($search['month']) {
- $search['month'] = date('Y-m-01', strtotime($search['month']) );
- }
- $search['status'] = $request->input('verify_status');
- $search['customer_name'] = $request->input('customer_name');
- $search['approved_start_date'] = $request->input('approved_start_date');
- $search['approved_end_date'] = $request->input('approved_end_date');
- $search['task_id'] = $request->input('task_id');
- $search['company'] = $request->input('company');
- $search['cost_company_name'] = $request->input('cost_company_name');
- $search['mcn_name'] = $request->input('mcn_name');
- $search['pre_audit_status'] = $request->input('pre_audit_status');
- list($data, $total) = OrderService::getOrderEditing($page, $pagesize, $search);
- return self::returnPageValue($data, $total, $pagesize, $page);
- }
- /**
- * 审核订单
- */
- public static function verifyOrderEdit(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int',
- 'verify_status' => 'required|int',
- 'verify_note' => 'nullable|string',
- ], [
- 'id.required' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $id = $request->input('id');
- $status = $request->input('verify_status');
- $verify_note = $request->input('verify_note');
- $res = OrderService::verifyOrder($id, $status, $verify_note);
- if( !$res ){
- return self::returnValue($res, 4401);
- }
- return self::returnValue($res);
- }
- /**
- * 撤销审核订单
- */
- public static function delVerifyOrder(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'id' => 'nullable|int',
- 'order_id' => 'nullable|int'
- ], [
- 'id.int' => '参数有误',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $id = $request->input('id');
- $order_id = $request->input('order_id');
- if(!$id && !$order_id){
- return self::returnValue(null, 1102);
- }
- $res = OrderService::delVerifyOrder($id, $order_id);
- if( !$res ){
- return self::returnValue($res, 4401);
- }
- return self::returnValue($res);
- }
- /**
- * 查看订单修改审核记录
- */
- public static function getOrderVeifyRecords(Request $request)
- {
- $order_id = $request->input('order_id', null);
- $id = $request->input('id', null);
- list($res, $project) = OrderService::getOrderVeifyRecords($order_id, $id);
- return self::returnValue(['project'=>$project, 'order'=>$res]);
- }
- /**
- * 月度审核表
- */
- public function orderMonthVerifys(Request $request)
- {
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- $page = (int)$request->input('page', 1);
- $pagesize = (int)$request->input('pagesize', 20);
- list($data, $total) = OrderService::orderMonthList($role_id, $page, $pagesize, 0, 1);
- return self::returnPageValue($data, $total, $pagesize, $page);
- }
- /**
- * 订单模板导出
- */
- public function orderTemplateExport(Request $request)
- {
- $type = $request->input('type');
- //销售
- if($type == 1){
- $url = 'https://order-consumption-system.oss-cn-beijing.aliyuncs.com/templates/saler_template.xlsx';
- } else {
- //媒介
- $url = 'https://order-consumption-system.oss-cn-beijing.aliyuncs.com/templates/meijie_template.xlsx';
- }
- return self::returnValue(['url' => $url]);
- }
- /**
- * 订单导入
- */
- public function orderImport(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( $type==1 ){
- $res = OrderService::salerOrderImport($file);
- } elseif($type==2) {
- $res = OrderService::mJOrderImport($file);
- if ($res['code'] == 0) {
- $not_exists = $res['not_exists'];
- return self::returnValue(['info'=>$res['info'], 'not_exists'=>$not_exists]);
- }
- } elseif($type==3) {
- $res = OrderService::mcnOrderImport($file);
- } elseif($type==4) {
- $res = OrderService::cwOrderImport($file);
- } elseif($type==5) {
- $res = OrderService::mjRefundOrderImport($file);
- } else {
- return self::returnValue([], 1102);
- }
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- /**
- * 开票申请
- */
- public function setInvoice(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);
- }
- $user = \Auth::user();
- $statements_id = $request->input('statements_id');
- # 判断开票资格
- if(!InvoiceService::verifySetInvoice($statements_id)){
- return self::returnValue(['msg'=>'已经存在对应开票'], 7001);
- }
- $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['url_json'] = json_encode($files);
- list($res, $code) = InvoiceService::setInvoice($statements_id, $params);
- return self::returnValue($res, $code);
- }
- /**
- * 审核失败后修改发票申请(作废,不用了)
- */
- public function editInvoice(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 = InvoiceService::editInvoice($id, $params);
- if($res === 7002){
- return self::returnValue(['msg' => '非法操作'], $res);
- }
-
- 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);
- }
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- #销售媒介只能看自己提的
- if(!in_array($role_id, [10,16,17,21])){
- return self::returnValue(['error' => '该角色无权限操作'], 1102);
- }
- $ids = $request->input('ids');
- $date = $request->input('date');
- list($res, $code) = InvoiceService::actualInvoiced($ids, $date);
-
- return self::returnValue($res, $code);
- }
- /**
- * 出纳取消标记开票
- */
- public function delActualInvoiced(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- //获取当前角色
- $user = \Auth::user();
- $role_id = $user->role_id;
- #销售媒介只能看自己提的
- if(!in_array($role_id, [10,16,17,21])){
- return self::returnValue(['error' => '该角色无权限操作'], 1102);
- }
- $id = $request->input('id');
- list($res, $code) = InvoiceService::delActualInvoiced($id);
-
- return self::returnValue($res, $code);
- }
- /**
- * 发票申请列表
- */
- public function invoiceList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'customer_name' => 'nullable|string',
- 'status' => 'nullable|int',
- 'cdate' => 'nullable|date',
- 'page' => 'required|int|min:1',
- 'voided_status' => 'nullable|int',
- '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);
- }
- $search = array();
- $search['is_my'] = $request->input('is_my', 0);
- $search['status'] = $request->input('status');
- $search['customer_name'] = $request->input('customer_name');
- $search['cdate'] = $request->input('cdate');
- $search['company'] = $request->input('company');
- $search['voided_status'] = $request->input('voided_status');
- $search['approved_start_date'] = $request->input('approved_start_date');
- $search['approved_end_date'] = $request->input('approved_end_date');
- $search['id'] = $request->input('id');
- $search['statements_id'] = $request->input('statements_id');
- $search['pre_audit_status'] = $request->input('pre_audit_status');
- $search['voided_pre_audit_status'] = $request->input('voided_pre_audit_status');
- $search['collection_date_start'] = $request->input('collection_date_start');
- $search['collection_date_end'] = $request->input('collection_date_end');
- $page = (int)$request->input('page', 1);
- $pageSize = (int)$request->input('pagesize', 20);
- list($data, $total) = InvoiceService::invoiceList($search, $page, $pageSize);
- return self::returnPageValue($data, $total, $pageSize, $page);
- }
- public function reminder(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'ids' => 'required|array',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $ids = $request->input('ids');
- list($res, $code) = InvoiceService::reminder($ids);
- return self::returnValue($res, $code);
- }
- /**
- * 发票详情
- */
- public function invoiceDetail(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::invoiceDetail($id);
-
- return self::returnValue($res);
- }
- /**
- * 发票审核
- * 待审核状态
- * 不会更新发票enable状态
- */
- public function verifyInvoice(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::verifyInvoice($id, $status, $verify_note);
- if($res) {
- return self::returnValue($res, 0);
- } else {
- return self::returnValue($res, 7003);
- }
- }
- /**
- * 批量修改
- */
- public function batchUpdate(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 = OrderService::batchUpdate($file, $reason);
- if ($res['code'] == 0) {
- return self::returnValue(['info'=>'导入成功']);
- } else {
- return self::returnValue(['error'=>$res['info']], $res['code']);
- }
- }
- /**
- * 批量修改订单详细信息
- */
- public function getOrderEditingDetail(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'edit_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('edit_id');
- $detail = OrderService::getOrderEditingDetail($id);
- return self::returnValue($detail);
- }
- /**
- * 导出修改记录
- */
- public function orderEditingExport(Request $request)
- {
- $search['status'] = $request->input('verify_status');
- $search['month'] = $request->input('month');
- if($search['month']) $search['month'] = date('Y-m-01', strtotime($search['month']) );
- $search['approved_start_date'] = $request->input('approved_start_date');
- $search['approved_end_date'] = $request->input('approved_end_date');
- $search['customer_name'] = $request->input('customer_name');
- $search['task_id'] = $request->input('task_id');
- $search['company'] = $request->input('company');
- return OrderService::orderEditingExport($search);
- }
- /**
- * 导出某个时间点的所有订单
- */
- public function orderHistoryExport(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'month' => 'required',
- 'etime' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $month = $request->input('month');
- $etime = $request->input('etime');
- if($month) $month = date('Y-m-01', strtotime($month) );
- return OrderService::orderHistoryExport($month, $etime);
- }
- /**
- * 上传附件
- */
- public function fileUpload(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'file' => 'required|file',
- 'type' => 'int'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $type = (int)$request->input('type');
- if($type == 0){
- $dir_path = 'invoice';
- } else {
- $dir_path = 'other';
- }
- if( $request->hasFile('file') && $request->file('file')->isValid() ){
- $file = $request->file('file');
- #文件上传处理
- $ext = $file->getClientOriginalExtension();
- $file_size = filesize($file->getRealPath());
- $filename = $file->getClientOriginalName();
- if ($file_size >= 1024*1024*50) {
- return self::returnValue(['msg' => '文件过大'], 6005);
- }
- //文件上传
- $ossClient = new OssServices();
- $filename = str_replace('.'.$ext, '', $filename);
- //文件名过滤特殊字符
- $regex = "/\/|\~|\!|\@|\#|\$|\%|\&|\*|\+|\:|\<|\>|\?|\,|\/|\;|\'|\`|\=|\\|\"| |\|/";
- // $regex = "/\/|\~|\!|\@|\#|\$|\%|\&|\*|\+|\:|\<|\>|\?|\,|\.|\/|\;|\'|\`|\=|\\|\"| |\|/";
- $filename = preg_replace($regex,"",$filename);
- // 上传阿里云
- $dir = $dir_path.'/'.date("Y-m-d").'/';
- $filename = $filename.'_'. date('His') .'.' . $ext;
- $file = $ossClient->upload($ext, $file->getRealPath(), $dir, $filename);
- $img_url = urldecode($file['oss-request-url']);
- } else {
- return self::returnValue([], 6006);
- }
- return self::returnValue(['url' => $img_url]);
- }
- }
|