新版订单消耗系统

OrderController.php 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\Order;
  4. use App\Models\MonthOrder;
  5. use App\Services\ProjectService;
  6. use App\Services\OrderService;
  7. use App\Services\OssServices;
  8. use App\Services\InvoiceService;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Validation\Rule;
  11. class OrderController extends Controller
  12. {
  13. /**
  14. * 项目订单列表(废弃)
  15. */
  16. public function projectOrder(Request $request)
  17. {
  18. $validator = \Validator::make($request->all(), [
  19. 'project_id' => 'required|int',
  20. 'internet_celebrity_name' => 'nullable|string',
  21. 'cost_company_name' => 'nullable|string'
  22. ], [
  23. 'project_id.required' => '参数有误',
  24. ]);
  25. if ($validator->fails()) {
  26. return self::returnValue($validator->getMessageBag(), 1102);
  27. }
  28. $project_id = $request->input('project_id');
  29. $internet_celebrity_name = $request->input('internet_celebrity_name');
  30. $cost_company_name = $request->input('cost_company_name');
  31. $page = $request->input('page', 1);
  32. $pagesize = $request->input('pagesize', 20);
  33. $data = OrderService::projectIndex($page, $pagesize, $project_id, $internet_celebrity_name,
  34. $cost_company_name);
  35. #计算项目订单总计信息
  36. list($account, $orderTotal) = OrderService::getProjectOrderCount($project_id, $cost_company_name);
  37. $info = [
  38. 'account'=>$account,
  39. 'orderTotal'=>$orderTotal
  40. ];
  41. return self::returnValue(['data' => $data, 'info' => $info]);
  42. }
  43. /**
  44. * AE添加订单
  45. */
  46. public function add(Request $request)
  47. {
  48. $unique = [
  49. 'task_id' => $request->task_id,
  50. 'month' => date('Y-m-01', strtotime($request->month)),
  51. 'enable' => 1
  52. ];
  53. $validator = \Validator::make($request->all(), [
  54. 'project_name' => 'required|string',
  55. 'salesman' => 'nullable|string',
  56. 'month' => 'required|date',
  57. 'task_id' => ['required',Rule::unique('order')->where(function($query) use ($unique) {
  58. return $query->where($unique);
  59. })],
  60. // 'handler' => 'required|string',
  61. 'advertiser_account' => 'required|string',
  62. 'advertiser_id' => 'required|string',
  63. 'company' => 'required|string',
  64. 'customer_name' => 'required|string',
  65. 'launch_platform' => 'required|string',
  66. 'media_name' => 'required|string',
  67. 'internet_celebrity_name' => 'nullable|string',
  68. 'internet_celebrity_id' => 'nullable|string',
  69. 'amount' => 'required|numeric',
  70. 'final_amount' => 'required|numeric',
  71. 'launch_start_date' => 'required|date',
  72. 'launch_end_date' => 'required|date',
  73. 'billing_date' => 'nullable|date',
  74. 'payment_date' => 'nullable|date',
  75. 'uninvoiced_amount' => 'nullable|numeric',
  76. 'invoice_amount' => 'nullable|numeric',
  77. 'saler_note' => 'nullable|string',
  78. 'if_public' => 'nullable|int',
  79. 'cost' => 'nullable|numeric',
  80. 'traffic_boost_sum' => 'nullable|numeric',
  81. 'top_fee' => 'nullable|numeric',
  82. ], [
  83. 'project_id.required' => '参数有误',
  84. 'salesman.required' => '销售人员必填',
  85. 'customer_name.required' => '客户全称必填',
  86. 'launch_platform.required' => '投放平台必填',
  87. 'media_name.required' => '媒体名称必填',
  88. 'launch_start_date.required' => '投放起始日期必填',
  89. 'launch_end_date.required' => '投放截止日期必填',
  90. 'amount.required' => '订单金额必填',
  91. 'final_amount.required' => '订单最终收入金额必填',
  92. 'advertiser_id.required' => '账户id必填',
  93. 'advertiser_account.required' => '账户名称必填',
  94. 'company.required' => '签约公司名称必填',
  95. 'month.required' => '所属月份必填',
  96. 'task_id.required' => '任务id必填',
  97. 'project_name.required' => '项目名称必填'
  98. ]);
  99. if ($validator->fails()) {
  100. return self::returnValue($validator->getMessageBag(), 1102);
  101. }
  102. $params = array();
  103. $user = \Auth::user();
  104. #获取所有锁单的月份
  105. $lock_months = MonthOrder::where('enable', 1)->pluck('month')->toArray();
  106. // $project_id = $request->input('project_id');
  107. // $project = ProjectService::detail($project_id);
  108. // $params['project_id'] = $project_id;
  109. $params['project_name'] = $request->input('project_name');
  110. $project = ProjectService::getProject($params['project_name']);
  111. $params['project_id'] = $project->id;
  112. $params['company'] = $request->input('company');
  113. $month = $request->input('month');
  114. $params['month'] = date('Y-m-01', strtotime($month));
  115. #销售不能添加锁单订单
  116. if( in_array($params['month'], $lock_months) && $user->role_id==11){
  117. return self::returnValue([], 4202);
  118. }
  119. $params['advertiser_account'] = $request->input('advertiser_account');
  120. $params['advertiser_id'] = $request->input('advertiser_id');
  121. #项目带入-可编辑参数
  122. $params['salesman'] = $request->input('salesman', $user->real_name);
  123. $params['handler'] = $user->real_name;
  124. $params['customer_name'] = $request->input('customer_name');
  125. $params['origin_customer_name'] = $params['customer_name'];
  126. $params['launch_platform'] = $request->input('launch_platform');
  127. $params['media_name'] = $request->input('media_name');
  128. $params['handlers_id'] = $user->id;
  129. // $orderMd5 = md5($params['salesman'].$params['handler'].$params['customer_name'].$params['launch_platform'].$params['media_name'].$project_id.time());
  130. // $oldMd5 = $request->input('order_md5', null);
  131. // $params['order_md5'] = $oldMd5 ? $oldMd5 : $orderMd5;
  132. #媒体名称连带
  133. $media = OrderService::getMedia( $params['media_name'] );
  134. $params['cost_company_name'] = $request->input('cost_company_name',$media->company); //成本公司全称 媒体表media_config带入company
  135. $params['cost_owner'] = $media->cost_owner; //成本负责人 媒体表media_config带入cost_owner
  136. //$params['saler_id'] = $request->input('saler_id', $user->id);
  137. $params['task_id'] = $request->input('task_id');
  138. //填写参数
  139. $params['internet_celebrity_name'] = $request->input('internet_celebrity_name');
  140. $params['internet_celebrity_id'] = $request->input('internet_celebrity_id');
  141. $params['amount'] = $request->input('amount');
  142. $params['final_amount'] = $request->input('final_amount');
  143. $params['origin_amount'] = $params['final_amount'];
  144. $params['launch_start_date'] = $request->input('launch_start_date');
  145. $params['launch_end_date'] = $request->input('launch_end_date');
  146. $params['billing_date'] = $request->input('billing_date');
  147. $params['payment_date'] = $request->input('payment_date');
  148. $params['uninvoiced_amount'] = $request->input('uninvoiced_amount');
  149. //$params['unbilled_voucher'] = $request->input('unbilled_voucher');
  150. #新加填写参数
  151. $params['invoice_amount'] = $request->input('invoice_amount'); //开票金额
  152. $params['saler_note'] = $request->input('saler_note'); //(备注)利润异常原因
  153. $params['if_public'] = $request->input('if_public');
  154. $params['cost'] = $request->input('cost'); //成本消耗
  155. $params['traffic_boost_sum'] = $request->input('traffic_boost_sum'); //流量助推合计
  156. #$params['top_fee'] = $request->input('top_fee'); //置顶费
  157. $params['rebate_spending_ratio'] = $request->input('rebate_spending_ratio'); //返点支出比例
  158. $params['rebate_expense_receiving_unit'] = $request->input('rebate_expense_receiving_unit'); //返点支出收款单位
  159. if($params['launch_start_date'] > $params['launch_end_date']){
  160. return self::returnValue(['msg' => '参数有误'], 1201);
  161. }
  162. //全局带入参数
  163. $global_config = OrderService::getRateConf($params['month'], $params['media_name'], $params['if_public'], $params['company']);
  164. $params['ratio_of_consumption_to_top_rebate'] = $global_config->ratio_of_consumption_to_top_rebate ;//消耗与置顶返点比例
  165. $params['flow_boost_rebate_ratio'] = $global_config->flow_boost_rebate_ratio; //流量助推返点比例
  166. $params['status'] = 1; //AE填写完成
  167. $res = OrderService::add($params);
  168. return self::returnValue($res);
  169. }
  170. /**
  171. * 订单编辑
  172. */
  173. public static function update(Request $request)
  174. {
  175. $validator = \Validator::make($request->all(), [
  176. 'id' => 'required|int',
  177. 'salesman' => 'nullable|string',
  178. // 'handler' => 'nullable|string',
  179. 'customer_name' => 'nullable|string',
  180. 'launch_platform' => 'nullable|string',
  181. 'media_name' => 'nullable|string',
  182. 'internet_celebrity_name' => 'nullable|string',
  183. 'internet_celebrity_id' => 'nullable|string',
  184. 'amount' => 'nullable|numeric',
  185. 'final_amount' => 'nullable|numeric',
  186. 'launch_start_date' => 'nullable|date',
  187. 'launch_end_date' => 'nullable|date',
  188. 'billing_date' => 'nullable|date',
  189. 'project_name_second' => 'nullable|string',
  190. 'if_public' => 'nullable|int',
  191. 'cost' => 'nullable|numeric',
  192. 'traffic_boost_sum' => 'nullable|numeric',
  193. 'traffic_boost_refund' => 'nullable|numeric',
  194. 'traffic_boost_money' => 'nullable|numeric',
  195. 'top_fee' => 'nullable|numeric',
  196. 'offline_subsidy_amount' => 'nullable|numeric',
  197. 'cost_invoice_status' => 'nullable|string',
  198. 'rebate_spending_ratio' => 'nullable|numeric',
  199. 'rebate_expense_receiving_unit' => 'nullable|string',
  200. 'note' => 'nullable|string',
  201. 'payment_date' => 'nullable|date',
  202. 'document_number_first' => 'nullable|string',
  203. 'document_number_second' => 'nullable|string',
  204. 'document_number_third' => 'nullable|string',
  205. 'document_number_four' => 'nullable|string',
  206. 'document_number_five' => 'nullable|string',
  207. 'document_number_six' => 'nullable|string',
  208. 'offline_subsidy_company' => 'nullable|string',
  209. 'payes' => 'nullable|string',
  210. 'payment_time' => 'nullable|date',
  211. 'uninvoiced_amount' => 'nullable|numeric',
  212. 'unbilled_voucher' => 'nullable|string',
  213. 'invoice_amount' => 'nullable|numeric',
  214. 'confirmation_certificate' => 'nullable|string',
  215. 'confirmed_cost_includes_tax' => 'nullable|numeric',
  216. 'confirmed_cost' => 'nullable|numeric',
  217. 'document_number_seven' => 'nullable|string',
  218. 'verify_edit' => 'nullable|int',
  219. 'op_reason' => 'nullable|string',
  220. 'saler_note' => 'nullable|string',
  221. 'confirmation_certificate_first' => 'nullable|string',
  222. 'confirmation_certificate_third' => 'nullable|string',
  223. 'confirmation_certificate_four' => 'nullable|string',
  224. 'confirmation_certificate_five' => 'nullable|string',
  225. 'confirmation_certificate_six' => 'nullable|string',
  226. 'confirmation_certificate_seven' => 'nullable|string',
  227. 'mcn_name' => 'nullable|string',
  228. 'mcn_rebate' => 'nullable|numeric',
  229. 'mcn_handler' => 'nullable|string',
  230. 'mcn_handler_id' => 'nullable|int',
  231. 'mcn_user_id' => 'nullable|int',
  232. 'mcn_document_number' => 'nullable|string',
  233. 'mcn_confirmation_certificate' => 'nullable|string',
  234. ], [
  235. 'id.required' => '参数有误',
  236. ]);
  237. if ($validator->fails()) {
  238. return self::returnValue($validator->getMessageBag(), 1102);
  239. }
  240. //获取当前角色
  241. $user = \Auth::user();
  242. $role_id = $user->role_id;
  243. $params = array();
  244. #项目带入-可编辑参数
  245. // $params['handler'] = $request->input('handler');
  246. $params['customer_name'] = trim($request->input('customer_name'));
  247. $params['origin_customer_name'] = $params['customer_name'];
  248. $params['launch_platform'] = trim($request->input('launch_platform'));
  249. $params['media_name'] = trim($request->input('media_name'));
  250. $params['cost_company_name'] = $request->input('cost_company_name');
  251. //AE填写参数
  252. $params['internet_celebrity_name'] = trim($request->input('internet_celebrity_name'));
  253. $params['internet_celebrity_id'] = trim($request->input('internet_celebrity_id'));
  254. $params['amount'] = trim($request->input('amount'));
  255. $params['final_amount'] = trim($request->input('final_amount'));
  256. $params['origin_amount'] = $params['final_amount'];
  257. $params['launch_start_date'] = trim($request->input('launch_start_date'));
  258. $params['launch_end_date'] = trim($request->input('launch_end_date'));
  259. $params['billing_date'] = trim($request->input('billing_date'));
  260. $params['payment_date'] = trim($request->input('payment_date')); //回款日期
  261. $params['uninvoiced_amount'] = trim($request->input('uninvoiced_amount')); //未开票金额
  262. //$params['invoice_amount'] = $request->input('invoice_amount'); //开票金额
  263. $params['saler_note'] = trim($request->input('saler_note')); //(备注)利润异常原因
  264. #媒介参数(销售可填的)
  265. $params['if_public'] = (int)$request->input('if_public');
  266. //$params['cost'] = $request->input('cost'); //成本消耗 3.3 不再允许销售修改
  267. //$params['traffic_boost_sum'] = $request->input('traffic_boost_sum'); //流量助推合计
  268. $params['rebate_spending_ratio'] = trim($request->input('rebate_spending_ratio')); //返点支出比例
  269. $params['rebate_expense_receiving_unit'] = trim($request->input('rebate_expense_receiving_unit')); //返点支出收款单位
  270. #媒介或媒介审核单独填写
  271. if( in_array($role_id, [1, 9, 13]) ){
  272. $params['salesman'] = trim($request->input('salesman'));
  273. #$params['project_name_second'] = $request->input('project_name_second');
  274. $params['offline_subsidy_amount'] = trim($request->input('offline_subsidy_amount')); //线下补款金额
  275. $params['note'] = trim($request->input('note')); //备注
  276. $params['offline_subsidy_company'] = trim($request->input('offline_subsidy_company')); //付款公司名称
  277. $company = OrderService::getCompany($params['offline_subsidy_company']);
  278. if(isset($company->rebate)) $params['sr_rate'] = $company->rebate;
  279. $params['payes'] = trim($request->input('payes')); //收款人
  280. $params['cost'] = trim($request->input('cost')); //成本消耗
  281. $params['top_fee'] = trim($request->input('top_fee')); //置顶费
  282. $params['traffic_boost_sum'] = trim($request->input('traffic_boost_sum')); //流量助推合计
  283. $params['traffic_boost_refund'] = trim($request->input('traffic_boost_refund')); //流量助推合计
  284. $params['traffic_boost_money'] = trim($request->input('traffic_boost_money')); //流量助推合计
  285. #多加mcn信息
  286. $params['mcn_name'] = trim($request->input('mcn_name'));
  287. $params['mcn_rebate'] = trim($request->input('mcn_rebate'));
  288. $params['origin_mcn_rebate'] = $params['mcn_rebate'];
  289. $params['mcn_handler'] = trim($request->input('mcn_handler'));
  290. $params['mcn_handler_id'] = trim($request->input('mcn_handler_id'));
  291. /*if(!empty($params['mcn_name'])){
  292. $params['mcn_user_id'] = $user->id;
  293. $params['mcn_user'] = $user->real_name;
  294. } */
  295. }
  296. #财务填写
  297. if( in_array($role_id, [1, 10]) ){
  298. $params['document_number_first'] = trim($request->input('document_number_first')); //凭证号
  299. $params['document_number_second'] = trim($request->input('document_number_second')); //凭证号
  300. $params['document_number_third'] = trim($request->input('document_number_third')); //凭证号
  301. $params['document_number_four'] = trim($request->input('document_number_four')); //凭证号
  302. $params['document_number_five'] = trim($request->input('document_number_five')); //凭证号
  303. $params['document_number_six'] = trim($request->input('document_number_six')); //凭证号
  304. $params['document_number_seven'] = trim($request->input('document_number_seven'));//凭证号
  305. $params['confirmation_certificate_first'] = trim($request->input('confirmation_certificate_first'));//凭证确认
  306. $params['confirmation_certificate_third'] = trim($request->input('confirmation_certificate_third'));//凭证确认
  307. $params['confirmation_certificate_four'] = trim($request->input('confirmation_certificate_four'));//凭证确认
  308. $params['confirmation_certificate_five'] = trim($request->input('confirmation_certificate_five'));//凭证确认
  309. $params['confirmation_certificate_six'] = trim($request->input('confirmation_certificate_six'));//凭证确认
  310. $params['confirmation_certificate_seven'] = trim($request->input('confirmation_certificate_seven'));//凭证确认
  311. $params['unbilled_voucher'] = trim($request->input('unbilled_voucher')); //未开票凭证
  312. $params['confirmation_certificate'] = trim($request->input('confirmation_certificate')); //确认凭证
  313. $params['confirmed_cost_includes_tax'] = trim($request->input('confirmed_cost_includes_tax')); //确认成本含税
  314. $params['confirmed_cost'] = trim($request->input('confirmed_cost')); //确认成本不含税
  315. $params['cost_invoice_status'] = trim($request->input('cost_invoice_status')); //成本发票情况
  316. $params['mcn_document_number'] = trim($request->input('mcn_document_number'));
  317. $params['mcn_confirmation_certificate'] = trim($request->input('mcn_confirmation_certificate'));
  318. }
  319. if( empty($params) ){
  320. return self::returnValue(['msg' => '未做任何修改'], 4199);
  321. }
  322. $id = (int)$request->input('id');
  323. $verify_edit = (int)$request->input('verify_edit');
  324. //锁单修改提交审核
  325. if($verify_edit){
  326. $op_reason = $request->input('op_reason');
  327. $res = OrderService::orderVerifyAdd($id, $params, $op_reason, $role_id);
  328. } else {
  329. //正常修改
  330. $res = OrderService::update($id, $params, 2, $role_id);
  331. }
  332. if( is_numeric($res) && in_array($res, [4199, 4200, 4201]) ){
  333. return self::returnValue(['msg' => '操作有误'], $res);
  334. }
  335. return self::returnValue($res);
  336. }
  337. /**
  338. * 删除订单
  339. */
  340. public static function batchDel(Request $request)
  341. {
  342. $validator = \Validator::make($request->all(), [
  343. 'ids' => 'required|array',
  344. ], [
  345. 'ids.required' => '参数有误',
  346. ]);
  347. if ($validator->fails()) {
  348. return self::returnValue($validator->getMessageBag(), 1102);
  349. }
  350. $ids = $request->input('ids');
  351. $res = OrderService::batchDel($ids);
  352. if(!$res){
  353. return self::returnValue($res, 7004);
  354. }
  355. return self::returnValue($res);
  356. }
  357. /**
  358. * 查看订单修改记录
  359. */
  360. public static function getEditInfo(Request $request)
  361. {
  362. $validator = \Validator::make($request->all(), [
  363. 'id' => 'required|int',
  364. ], [
  365. 'id.required' => '参数有误',
  366. ]);
  367. if ($validator->fails()) {
  368. return self::returnValue($validator->getMessageBag(), 1102);
  369. }
  370. $id = $request->input('id');
  371. $res = OrderService::getEditInfo($id);
  372. return self::returnValue($res);
  373. }
  374. /**
  375. * 锁单
  376. */
  377. public static function lockOrder(Request $request)
  378. {
  379. $validator = \Validator::make($request->all(), [
  380. 'id' => 'required|int',
  381. ], [
  382. 'id.required' => '参数有误',
  383. ]);
  384. if ($validator->fails()) {
  385. return self::returnValue($validator->getMessageBag(), 1102);
  386. }
  387. $id = $request->input('id');
  388. $res = OrderService::lockOrder($id);
  389. return self::returnValue($res);
  390. }
  391. /**
  392. * 订单列表
  393. */
  394. public function index(Request $request)
  395. {
  396. $validator = \Validator::make($request->all(), [
  397. 'page' => 'required|int',
  398. 'pagesize' => 'nullable|int',
  399. 'internet_celebrity_name' => 'nullable|string',
  400. 'salesman' => 'nullable|string',
  401. 'handler' => 'nullable|string',
  402. 'customer_name' => 'nullable|string',
  403. 'amount_min' => 'nullable|numeric',
  404. 'amount_max' => 'nullable|numeric',
  405. 'final_amount_min' => 'nullable|numeric',
  406. 'final_amount_max' => 'nullable|numeric',
  407. 'launch_end_date_start' => 'nullable|date',
  408. 'launch_end_date_end' => 'nullable|date',
  409. 'billing_date_start' => 'nullable|date',
  410. 'billing_date_end' => 'nullable|date',
  411. 'project_name_second' => 'nullable|string',
  412. 'if_public' => 'nullable|int',
  413. 'cost_min' => 'nullable|numeric',
  414. 'cost_max' => 'nullable|numeric',
  415. 'rebate_spending_ratio' => 'nullable|numeric',
  416. 'rebate_expense_receiving_unit' => 'nullable|string',
  417. 'payment_date_start' => 'nullable|date',
  418. 'payment_date_end' => 'nullable|date',
  419. 'advertiser_account' => 'nullable|string',
  420. 'advertiser_id' => 'nullable|string',
  421. 'verify_status' => 'nullable|int',
  422. 'statements_status' => 'nullable|numeric',
  423. 'media_name' => 'nullable|string',
  424. 'task_id' => 'nullable|string',
  425. 'mcn_name' => 'nullable|string',
  426. 'is_refund' => 'nullable|int',
  427. // 'traffic_boost_money_min' => 'nullable|numeric',
  428. // 'traffic_boost_money_max' => 'nullable|numeric',
  429. // 'traffic_boost_refund_min' => 'nullable|numeric',
  430. // 'traffic_boost_refund_max' => 'nullable|numeric',
  431. // 'top_fee_min' => 'nullable|numeric',
  432. // 'top_fee_max' => 'nullable|numeric',
  433. // 'offline_subsidy_amount_min' => 'nullable|numeric',
  434. // 'offline_subsidy_amount_max' => 'nullable|numeric',
  435. ], [
  436. 'page.required' => '页码必传',
  437. ]);
  438. if ($validator->fails()) {
  439. return self::returnValue($validator->getMessageBag(), 1102);
  440. }
  441. $search = $request->all();
  442. $page = $request->input('page', 1);
  443. $pagesize = $request->input('pagesize', 20);
  444. $is_export = (int)$request->input('is_export');
  445. list($data, $total, $info) = OrderService::index($page, $pagesize, $search, $is_export);
  446. return self::returnPageValue($data, $total, $pagesize, $page, $info);
  447. }
  448. /**
  449. * 订单搜索条件下拉项搜索
  450. */
  451. public function columnSearch(Request $request)
  452. {
  453. $validator = \Validator::make($request->all(), [
  454. 'column' => 'required|string',
  455. 'keyword' => 'nullable|string',
  456. ], [
  457. 'column.required' => '参数有误',
  458. ]);
  459. if ($validator->fails()) {
  460. return self::returnValue($validator->getMessageBag(), 1102);
  461. }
  462. $column = $request->input('column');
  463. $keyword = $request->input('keyword');
  464. $res = OrderService::columnSearch($column, $keyword);
  465. return self::returnValue($res);
  466. }
  467. /**
  468. * 月度消耗表
  469. */
  470. public function orderMonthList(Request $request)
  471. {
  472. //获取当前角色
  473. $user = \Auth::user();
  474. $role_id = $user->role_id;
  475. $status = $request->input('status');
  476. $page = (int)$request->input('page', 1);
  477. $pagesize = (int)$request->input('pagesize', 20);
  478. list($data, $total) = OrderService::orderMonthList($role_id, $page, $pagesize, $status);
  479. return self::returnPageValue($data, $total, $pagesize, $page);
  480. }
  481. /**
  482. * 月度订单提交财务
  483. */
  484. public static function lockMonthOrder(Request $request)
  485. {
  486. $validator = \Validator::make($request->all(), [
  487. 'month' => 'required|string',
  488. ], [
  489. 'month.required' => '参数有误',
  490. ]);
  491. if ($validator->fails()) {
  492. return self::returnValue($validator->getMessageBag(), 1102);
  493. }
  494. $month = $request->input('month');
  495. $month = date('Y-m-01', strtotime($month) );
  496. $res = OrderService::lockMonthOrder($month);
  497. return self::returnValue($res);
  498. }
  499. /**
  500. * 获取修改审核订单
  501. */
  502. public function getOrderEditing(Request $request)
  503. {
  504. $page = (int)$request->input('page', 1);
  505. $pagesize = (int)$request->input('pagesize', 20);
  506. $search['month'] = $request->input('month');
  507. if($search['month']) {
  508. $search['month'] = date('Y-m-01', strtotime($search['month']) );
  509. }
  510. $search['status'] = $request->input('verify_status');
  511. $search['customer_name'] = $request->input('customer_name');
  512. $search['approved_start_date'] = $request->input('approved_start_date');
  513. $search['approved_end_date'] = $request->input('approved_end_date');
  514. $search['task_id'] = $request->input('task_id');
  515. $search['company'] = $request->input('company');
  516. $search['cost_company_name'] = $request->input('cost_company_name');
  517. $search['mcn_name'] = $request->input('mcn_name');
  518. $search['pre_audit_status'] = $request->input('pre_audit_status');
  519. list($data, $total) = OrderService::getOrderEditing($page, $pagesize, $search);
  520. return self::returnPageValue($data, $total, $pagesize, $page);
  521. }
  522. /**
  523. * 审核订单
  524. */
  525. public static function verifyOrderEdit(Request $request)
  526. {
  527. $validator = \Validator::make($request->all(), [
  528. 'id' => 'required|int',
  529. 'verify_status' => 'required|int',
  530. 'verify_note' => 'nullable|string',
  531. ], [
  532. 'id.required' => '参数有误',
  533. ]);
  534. if ($validator->fails()) {
  535. return self::returnValue($validator->getMessageBag(), 1102);
  536. }
  537. $id = $request->input('id');
  538. $status = $request->input('verify_status');
  539. $verify_note = $request->input('verify_note');
  540. $res = OrderService::verifyOrder($id, $status, $verify_note);
  541. if( !$res ){
  542. return self::returnValue($res, 4401);
  543. }
  544. return self::returnValue($res);
  545. }
  546. /**
  547. * 撤销审核订单
  548. */
  549. public static function delVerifyOrder(Request $request)
  550. {
  551. $validator = \Validator::make($request->all(), [
  552. 'id' => 'nullable|int',
  553. 'order_id' => 'nullable|int'
  554. ], [
  555. 'id.int' => '参数有误',
  556. ]);
  557. if ($validator->fails()) {
  558. return self::returnValue($validator->getMessageBag(), 1102);
  559. }
  560. $id = $request->input('id');
  561. $order_id = $request->input('order_id');
  562. if(!$id && !$order_id){
  563. return self::returnValue(null, 1102);
  564. }
  565. $res = OrderService::delVerifyOrder($id, $order_id);
  566. if( !$res ){
  567. return self::returnValue($res, 4401);
  568. }
  569. return self::returnValue($res);
  570. }
  571. /**
  572. * 查看订单修改审核记录
  573. */
  574. public static function getOrderVeifyRecords(Request $request)
  575. {
  576. $order_id = $request->input('order_id', null);
  577. $id = $request->input('id', null);
  578. list($res, $project) = OrderService::getOrderVeifyRecords($order_id, $id);
  579. return self::returnValue(['project'=>$project, 'order'=>$res]);
  580. }
  581. /**
  582. * 月度审核表
  583. */
  584. public function orderMonthVerifys(Request $request)
  585. {
  586. //获取当前角色
  587. $user = \Auth::user();
  588. $role_id = $user->role_id;
  589. $page = (int)$request->input('page', 1);
  590. $pagesize = (int)$request->input('pagesize', 20);
  591. list($data, $total) = OrderService::orderMonthList($role_id, $page, $pagesize, 0, 1);
  592. return self::returnPageValue($data, $total, $pagesize, $page);
  593. }
  594. /**
  595. * 订单模板导出
  596. */
  597. public function orderTemplateExport(Request $request)
  598. {
  599. $type = $request->input('type');
  600. //销售
  601. if($type == 1){
  602. $url = 'https://order-consumption-system.oss-cn-beijing.aliyuncs.com/templates/saler_template.xlsx';
  603. } else {
  604. //媒介
  605. $url = 'https://order-consumption-system.oss-cn-beijing.aliyuncs.com/templates/meijie_template.xlsx';
  606. }
  607. return self::returnValue(['url' => $url]);
  608. }
  609. /**
  610. * 订单导入
  611. */
  612. public function orderImport(Request $request)
  613. {
  614. // 处理验证失败信息,不要直接抛异常
  615. $validator = \Validator::make($request->all(), [
  616. 'file' => 'required|file',
  617. 'type' => 'required|int'
  618. ]);
  619. if ($validator->fails()) {
  620. return self::returnValue(['error' => $validator->errors()], 1102);
  621. }
  622. $type = (int)$request->input('type');
  623. $file = $request->file('file');
  624. if( $type==1 ){
  625. $res = OrderService::salerOrderImport($file);
  626. } elseif($type==2) {
  627. $res = OrderService::mJOrderImport($file);
  628. if ($res['code'] == 0) {
  629. $not_exists = $res['not_exists'];
  630. return self::returnValue(['info'=>$res['info'], 'not_exists'=>$not_exists]);
  631. }
  632. } elseif($type==3) {
  633. $res = OrderService::mcnOrderImport($file);
  634. } elseif($type==4) {
  635. $res = OrderService::cwOrderImport($file);
  636. } elseif($type==5) {
  637. $res = OrderService::mjRefundOrderImport($file);
  638. } else {
  639. return self::returnValue([], 1102);
  640. }
  641. if ($res['code'] == 0) {
  642. return self::returnValue(['info'=>'导入成功']);
  643. } else {
  644. return self::returnValue(['error'=>$res['info']], $res['code']);
  645. }
  646. }
  647. /**
  648. * 开票申请
  649. */
  650. public function setInvoice(Request $request)
  651. {
  652. $validator = \Validator::make($request->all(), [
  653. 'statements_id' => 'required|int',
  654. 'invoice_type' => 'required|int',
  655. 'service_type' => 'required|string',
  656. 'invoice_note' => 'nullable|string',
  657. 'files' => 'required|array',
  658. ]);
  659. if ($validator->fails()) {
  660. return self::returnValue(['error' => $validator->errors()], 1102);
  661. }
  662. $user = \Auth::user();
  663. $statements_id = $request->input('statements_id');
  664. # 判断开票资格
  665. if(!InvoiceService::verifySetInvoice($statements_id)){
  666. return self::returnValue(['msg'=>'已经存在对应开票'], 7001);
  667. }
  668. $params = array();
  669. $params['handler_id'] = $user->id;
  670. $params['handler'] = $user->real_name;
  671. $params['invoice_type'] = $request->input('invoice_type');
  672. $params['service_type'] = $request->input('service_type');
  673. $params['invoice_note'] = $request->input('invoice_note');
  674. $params['consignee'] = $request->input('consignee');//收件人
  675. $params['contacts'] = $request->input('contacts');//联系人
  676. $params['contact_number'] = $request->input('contact_number');//联系电话
  677. $params['mail_address'] = $request->input('mail_address');//联系电话
  678. $params['note'] = $request->input('note');//联系电话
  679. $files = $request->input('files');
  680. if(!empty($files)){
  681. $files = array_map(function($val){
  682. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  683. },$files);
  684. }
  685. $params['url_json'] = json_encode($files);
  686. list($res, $code) = InvoiceService::setInvoice($statements_id, $params);
  687. return self::returnValue($res, $code);
  688. }
  689. /**
  690. * 审核失败后修改发票申请(作废,不用了)
  691. */
  692. public function editInvoice(Request $request)
  693. {
  694. // 处理验证失败信息,不要直接抛异常
  695. $validator = \Validator::make($request->all(), [
  696. 'id' => 'required|int',
  697. 'tax_id' => 'nullable|string',
  698. 'address_tel' => 'nullable|string',
  699. 'bank_account' => 'nullable|string',
  700. ]);
  701. if ($validator->fails()) {
  702. return self::returnValue(['error' => $validator->errors()], 1102);
  703. }
  704. $params = array();
  705. $params['tax_id'] = $request->input('tax_id');
  706. $params['address_tel'] = $request->input('address_tel');
  707. $params['bank_account'] = $request->input('bank_account');
  708. $params['consignee'] = $request->input('consignee');//收件人
  709. $params['contacts'] = $request->input('contacts');//联系人
  710. $params['contact_number'] = $request->input('contact_number');//联系电话
  711. $params['mail_address'] = $request->input('mail_address');//联系电话
  712. $params['note'] = $request->input('note');
  713. $files = $request->input('files');
  714. if(!empty($files)){
  715. $files = array_map(function($val){
  716. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  717. },$files);
  718. }
  719. $params['url_json'] = json_encode($files);
  720. $params = array_filter($params);
  721. if(empty($params)){
  722. return self::returnValue(['未做修改'], 4199);
  723. }
  724. $id = (int)$request->input('id');
  725. $res = InvoiceService::editInvoice($id, $params);
  726. if($res === 7002){
  727. return self::returnValue(['msg' => '非法操作'], $res);
  728. }
  729. return self::returnValue($res);
  730. }
  731. /**
  732. * 出纳批量标记开票
  733. */
  734. public function actualInvoiced(Request $request)
  735. {
  736. // 处理验证失败信息,不要直接抛异常
  737. $validator = \Validator::make($request->all(), [
  738. 'ids' => 'required|array',
  739. 'date' => 'required|date'
  740. ]);
  741. if ($validator->fails()) {
  742. return self::returnValue(['error' => $validator->errors()], 1102);
  743. }
  744. //获取当前角色
  745. $user = \Auth::user();
  746. $role_id = $user->role_id;
  747. #销售媒介只能看自己提的
  748. if(!in_array($role_id, [10,16,17,21])){
  749. return self::returnValue(['error' => '该角色无权限操作'], 1102);
  750. }
  751. $ids = $request->input('ids');
  752. $date = $request->input('date');
  753. list($res, $code) = InvoiceService::actualInvoiced($ids, $date);
  754. return self::returnValue($res, $code);
  755. }
  756. /**
  757. * 出纳取消标记开票
  758. */
  759. public function delActualInvoiced(Request $request)
  760. {
  761. // 处理验证失败信息,不要直接抛异常
  762. $validator = \Validator::make($request->all(), [
  763. 'id' => 'required|int'
  764. ]);
  765. if ($validator->fails()) {
  766. return self::returnValue(['error' => $validator->errors()], 1102);
  767. }
  768. //获取当前角色
  769. $user = \Auth::user();
  770. $role_id = $user->role_id;
  771. #销售媒介只能看自己提的
  772. if(!in_array($role_id, [10,16,17,21])){
  773. return self::returnValue(['error' => '该角色无权限操作'], 1102);
  774. }
  775. $id = $request->input('id');
  776. list($res, $code) = InvoiceService::delActualInvoiced($id);
  777. return self::returnValue($res, $code);
  778. }
  779. /**
  780. * 发票申请列表
  781. */
  782. public function invoiceList(Request $request)
  783. {
  784. $validator = \Validator::make($request->all(), [
  785. 'customer_name' => 'nullable|string',
  786. 'status' => 'nullable|int',
  787. 'cdate' => 'nullable|date',
  788. 'page' => 'required|int|min:1',
  789. 'voided_status' => 'nullable|int',
  790. 'approved_start_date' => 'nullable|date_format:Y-m-d',
  791. 'approved_end_date' => 'nullable|date_format:Y-m-d',
  792. ]);
  793. if ($validator->fails()) {
  794. return self::returnValue(['error' => $validator->errors()], 1102);
  795. }
  796. $search = array();
  797. $search['is_my'] = $request->input('is_my', 0);
  798. $search['status'] = $request->input('status');
  799. $search['customer_name'] = $request->input('customer_name');
  800. $search['cdate'] = $request->input('cdate');
  801. $search['company'] = $request->input('company');
  802. $search['voided_status'] = $request->input('voided_status');
  803. $search['approved_start_date'] = $request->input('approved_start_date');
  804. $search['approved_end_date'] = $request->input('approved_end_date');
  805. $search['id'] = $request->input('id');
  806. $search['statements_id'] = $request->input('statements_id');
  807. $search['pre_audit_status'] = $request->input('pre_audit_status');
  808. $search['voided_pre_audit_status'] = $request->input('voided_pre_audit_status');
  809. $search['collection_date_start'] = $request->input('collection_date_start');
  810. $search['collection_date_end'] = $request->input('collection_date_end');
  811. $page = (int)$request->input('page', 1);
  812. $pageSize = (int)$request->input('pagesize', 20);
  813. list($data, $total) = InvoiceService::invoiceList($search, $page, $pageSize);
  814. return self::returnPageValue($data, $total, $pageSize, $page);
  815. }
  816. public function reminder(Request $request)
  817. {
  818. // 处理验证失败信息,不要直接抛异常
  819. $validator = \Validator::make($request->all(), [
  820. 'ids' => 'required|array',
  821. ]);
  822. if ($validator->fails()) {
  823. return self::returnValue(['error' => $validator->errors()], 1102);
  824. }
  825. $ids = $request->input('ids');
  826. list($res, $code) = InvoiceService::reminder($ids);
  827. return self::returnValue($res, $code);
  828. }
  829. /**
  830. * 发票详情
  831. */
  832. public function invoiceDetail(Request $request)
  833. {
  834. // 处理验证失败信息,不要直接抛异常
  835. $validator = \Validator::make($request->all(), [
  836. 'id' => 'required|int'
  837. ]);
  838. if ($validator->fails()) {
  839. return self::returnValue(['error' => $validator->errors()], 1102);
  840. }
  841. $id = (int)$request->input('id');
  842. $res = InvoiceService::invoiceDetail($id);
  843. return self::returnValue($res);
  844. }
  845. /**
  846. * 发票审核
  847. * 待审核状态
  848. * 不会更新发票enable状态
  849. */
  850. public function verifyInvoice(Request $request)
  851. {
  852. // 处理验证失败信息,不要直接抛异常
  853. $validator = \Validator::make($request->all(), [
  854. 'id' => 'required|int',
  855. 'status' => 'required|int',
  856. 'verify_note' => 'nullable|string',
  857. ]);
  858. if ($validator->fails()) {
  859. return self::returnValue(['error' => $validator->errors()], 1102);
  860. }
  861. $id = (int)$request->input('id');
  862. $status = $request->input('status');
  863. $verify_note = $request->input('verify_note');
  864. $res = InvoiceService::verifyInvoice($id, $status, $verify_note);
  865. if($res) {
  866. return self::returnValue($res, 0);
  867. } else {
  868. return self::returnValue($res, 7003);
  869. }
  870. }
  871. /**
  872. * 批量修改
  873. */
  874. public function batchUpdate(Request $request)
  875. {
  876. $validator = \Validator::make($request->all(), [
  877. 'file' => 'required|file',
  878. 'reason' => 'required'
  879. ]);
  880. if ($validator->fails()) {
  881. return self::returnValue(['error' => $validator->errors()], 1102);
  882. }
  883. $file = $request->file('file');
  884. $reason = $request->input('reason');
  885. $res = OrderService::batchUpdate($file, $reason);
  886. if ($res['code'] == 0) {
  887. return self::returnValue(['info'=>'导入成功']);
  888. } else {
  889. return self::returnValue(['error'=>$res['info']], $res['code']);
  890. }
  891. }
  892. /**
  893. * 批量修改订单详细信息
  894. */
  895. public function getOrderEditingDetail(Request $request)
  896. {
  897. $validator = \Validator::make($request->all(), [
  898. 'edit_id' => 'required|integer'
  899. ]);
  900. if ($validator->fails()) {
  901. return self::returnValue(['error' => $validator->errors()], 1102);
  902. }
  903. $id = $request->input('edit_id');
  904. $detail = OrderService::getOrderEditingDetail($id);
  905. return self::returnValue($detail);
  906. }
  907. /**
  908. * 导出修改记录
  909. */
  910. public function orderEditingExport(Request $request)
  911. {
  912. $search['status'] = $request->input('verify_status');
  913. $search['month'] = $request->input('month');
  914. if($search['month']) $search['month'] = date('Y-m-01', strtotime($search['month']) );
  915. $search['approved_start_date'] = $request->input('approved_start_date');
  916. $search['approved_end_date'] = $request->input('approved_end_date');
  917. $search['customer_name'] = $request->input('customer_name');
  918. $search['task_id'] = $request->input('task_id');
  919. $search['company'] = $request->input('company');
  920. return OrderService::orderEditingExport($search);
  921. }
  922. /**
  923. * 导出某个时间点的所有订单
  924. */
  925. public function orderHistoryExport(Request $request)
  926. {
  927. $validator = \Validator::make($request->all(), [
  928. 'month' => 'required',
  929. 'etime' => 'required',
  930. ]);
  931. if ($validator->fails()) {
  932. return self::returnValue(['error' => $validator->errors()], 1102);
  933. }
  934. $month = $request->input('month');
  935. $etime = $request->input('etime');
  936. if($month) $month = date('Y-m-01', strtotime($month) );
  937. return OrderService::orderHistoryExport($month, $etime);
  938. }
  939. /**
  940. * 上传附件
  941. */
  942. public function fileUpload(Request $request)
  943. {
  944. $validator = \Validator::make($request->all(), [
  945. 'file' => 'required|file',
  946. 'type' => 'int'
  947. ]);
  948. if ($validator->fails()) {
  949. return self::returnValue(['error' => $validator->errors()], 1102);
  950. }
  951. $type = (int)$request->input('type');
  952. if($type == 0){
  953. $dir_path = 'invoice';
  954. } else {
  955. $dir_path = 'other';
  956. }
  957. if( $request->hasFile('file') && $request->file('file')->isValid() ){
  958. $file = $request->file('file');
  959. #文件上传处理
  960. $ext = $file->getClientOriginalExtension();
  961. $file_size = filesize($file->getRealPath());
  962. $filename = $file->getClientOriginalName();
  963. if ($file_size >= 1024*1024*50) {
  964. return self::returnValue(['msg' => '文件过大'], 6005);
  965. }
  966. //文件上传
  967. $ossClient = new OssServices();
  968. $filename = str_replace('.'.$ext, '', $filename);
  969. //文件名过滤特殊字符
  970. $regex = "/\/|\~|\!|\@|\#|\$|\%|\&|\*|\+|\:|\<|\>|\?|\,|\/|\;|\'|\`|\=|\\|\"| |\|/";
  971. // $regex = "/\/|\~|\!|\@|\#|\$|\%|\&|\*|\+|\:|\<|\>|\?|\,|\.|\/|\;|\'|\`|\=|\\|\"| |\|/";
  972. $filename = preg_replace($regex,"",$filename);
  973. // 上传阿里云
  974. $dir = $dir_path.'/'.date("Y-m-d").'/';
  975. $filename = $filename.'_'. date('His') .'.' . $ext;
  976. $file = $ossClient->upload($ext, $file->getRealPath(), $dir, $filename);
  977. $img_url = urldecode($file['oss-request-url']);
  978. } else {
  979. return self::returnValue([], 6006);
  980. }
  981. return self::returnValue(['url' => $img_url]);
  982. }
  983. }