新版订单消耗系统

NewOrderController.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2021/4/6
  6. * Time: 17:49
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Services\NewOrderService;
  10. use App\Services\NewStatementsService;
  11. use App\Services\SpecialColumnEditService;
  12. use Illuminate\Http\Request;
  13. use App\Services\OrderIncomeService;
  14. use App\Services\OrderMcnService;
  15. class NewOrderController extends Controller
  16. {
  17. /**
  18. * 模板导入数据
  19. */
  20. public function orderImportSecond(Request $request)
  21. {
  22. // 处理验证失败信息,不要直接抛异常
  23. $validator = \Validator::make($request->all(), [
  24. 'file' => 'required|file',
  25. 'type' => 'required|int'
  26. ]);
  27. if ($validator->fails()) {
  28. return self::returnValue(['error' => $validator->errors()], 1102);
  29. }
  30. $type = (int)$request->input('type');
  31. $file = $request->file('file');
  32. if( 1 == $type ) {
  33. // 2022年起作废
  34. $res = OrderIncomeService::salerOrderImport($file);
  35. } else if ( 2 == $type ) {
  36. $res = OrderMcnService::mcnOrderImport($file);
  37. } else if ( 3 == $type ) {
  38. $res = OrderMcnService::caOrderImport($file);
  39. } else if ( 4 == $type) {
  40. $res = OrderIncomeService::redInvoiceImport($file);
  41. }
  42. if ($res['code'] == 0) {
  43. return self::returnValue(['info'=>'导入成功']);
  44. } else {
  45. return self::returnValue(['error'=>$res['info']], $res['code']);
  46. }
  47. }
  48. public function salerOrderImportValidate(Request $request)
  49. {
  50. // 处理验证失败信息,不要直接抛异常
  51. $validator = \Validator::make($request->all(), [
  52. 'file' => 'required|file',
  53. ]);
  54. if ($validator->fails()) {
  55. return self::returnValue(['error' => $validator->errors()], 1102);
  56. }
  57. $userId = \Auth::id();
  58. $extArr = ['xlsx', 'xls', 'csv'];
  59. // 验证文件后缀是否合法
  60. $ext = strtolower($request->file('file')->getClientOriginalExtension());
  61. if(!in_array($ext, $extArr)) {
  62. return self::returnValue(['error' => '文件格式不合法'], 1102);
  63. }
  64. // 将文件保存到服务器
  65. $newFileName = $userId.'.'.$ext;// 新文件名,便于二次确认接口查找文件
  66. $fileName = $request->file('file')->storeAs('', $newFileName, 'uploads');
  67. $filePath = public_path('uploads').'/'.$fileName;// 拼接完整文件路径,因为读取文件时需要
  68. // 读取文件内容并验证
  69. $res = OrderIncomeService::salerOrderImportValidate($filePath);
  70. if ($res['code'] == 0) {
  71. return self::returnValue(['info'=>'导入成功']);
  72. } else {
  73. return self::returnValue(['error'=>$res['info']], $res['code']);
  74. }
  75. }
  76. public function salerOrderImportConfirm(Request $request)
  77. {
  78. // 处理验证失败信息,不要直接抛异常
  79. $validator = \Validator::make($request->all(), [
  80. 'confirm' => 'required|in:1,0',
  81. ]);
  82. if ($validator->fails()) {
  83. return self::returnValue(['error' => $validator->errors()], 1102);
  84. }
  85. $confirm = $request->input('confirm');
  86. $res = OrderIncomeService::salerOrderImportConfirm($confirm);
  87. if ($res['code'] == 0) {
  88. return self::returnValue(['info'=>'导入成功']);
  89. } else {
  90. return self::returnValue(['error'=>$res['info']], $res['code']);
  91. }
  92. }
  93. /**
  94. * 订单收入数据列表
  95. */
  96. public function orderIncomeList(Request $request)
  97. {
  98. $validator = \Validator::make($request->all(), [
  99. 'page' => 'required|int',
  100. 'pagesize' => 'nullable|int',
  101. 'amount_min' => 'nullable|numeric',
  102. 'amount_max' => 'nullable|numeric',
  103. 'final_amount_min' => 'nullable|numeric',
  104. 'final_amount_max' => 'nullable|numeric',
  105. 'launch_end_date_start' => 'nullable|date',
  106. 'launch_end_date_end' => 'nullable|date',
  107. 'if_public' => 'nullable|int',
  108. 'verify_status' => 'nullable|int',
  109. 'statements_status' => 'nullable|numeric',
  110. 'task_id' => 'nullable|string',
  111. ], [
  112. 'page.required' => '页码必传',
  113. ]);
  114. if ($validator->fails()) {
  115. return self::returnValue($validator->getMessageBag(), 1102);
  116. }
  117. $search = $request->all();
  118. $page = $request->input('page', 1);
  119. $pageSize = $request->input('pagesize', 20);
  120. list($data, $total) = OrderIncomeService::orderIncomeList($page, $pageSize, $search);
  121. return self::returnPageValue($data, $total, $pageSize, $page);
  122. }
  123. /**
  124. * 单条编辑收入数据
  125. */
  126. public function orderIncomeUpdate(Request $request)
  127. {
  128. $validator = \Validator::make($request->all(), [
  129. 'id' => 'required|int',
  130. 'company' => 'nullable|string',
  131. 'salesman' => 'nullable|string',
  132. 'customer_name' => 'nullable|string',
  133. 'final_customer_name' => 'nullable|string',
  134. 'launch_start_date' => 'nullable|date',
  135. 'launch_end_date' => 'nullable|date',
  136. 'launch_platform' => 'nullable|string',
  137. 'amount' => 'nullable|numeric',
  138. 'internet_celebrity_name' => 'nullable|string',
  139. 'internet_celebrity_id' => 'nullable|string',
  140. 'final_amount' => 'nullable|numeric',
  141. 'actual_consumption_before' => 'nullable|numeric',
  142. 'link_fee_before' => 'nullable|numeric',
  143. 'flow_boost_back_point_before' => 'nullable|numeric',
  144. 'top_fee_before' => 'nullable|numeric',
  145. 'actual_consumption_after' => 'nullable|numeric',
  146. 'link_fee_after' => 'nullable|numeric',
  147. 'flow_boost_back_point_after' => 'nullable|numeric',
  148. 'top_fee_after' => 'nullable|numeric',
  149. 'customer_rebate_amount' => 'nullable|numeric',
  150. 'rebate_expense_receiving_unit' => 'nullable|string',
  151. 'income_red_invoice_date' => 'nullable|date',
  152. 'income_red_invoice_amount' => 'nullable|numeric',
  153. 'saler_note' => 'nullable|string',
  154. 'is_pdd_refund' => 'nullable|numeric',
  155. 'payment_date' => 'nullable|date',
  156. 'verify_edit' => 'nullable|int',
  157. ], [
  158. 'id.required' => '需选择订单',
  159. ]);
  160. if ($validator->fails()) {
  161. return self::returnValue($validator->getMessageBag(), 1102);
  162. }
  163. //获取当前角色
  164. $user = \Auth::user();
  165. $roleId = $user->role_id;
  166. $params = array();
  167. $params['company'] = trim($request->input('company', null));
  168. $params['customer_name'] = trim($request->input('customer_name', null));//客户全称
  169. $params['final_customer_name'] = trim($request->input('final_customer_name', null));
  170. $params['launch_platform'] = trim($request->input('launch_platform', null));
  171. // $params['media_name'] = trim($request->input('media_name', null));
  172. $params['internet_celebrity_name'] = trim($request->input('internet_celebrity_name', null));
  173. $params['internet_celebrity_id'] = trim($request->input('internet_celebrity_id', null));
  174. $params['launch_start_date'] = trim($request->input('launch_start_date', null));
  175. $params['launch_end_date'] = trim($request->input('launch_end_date', null));
  176. $params['payment_date'] = trim($request->input('payment_date', null)); //回款日期
  177. $params['salesman'] = trim($request->input('salesman', null));
  178. $params['project_name'] = trim($request->input('project_name', null));
  179. $params['amount'] = trim($request->input('amount', null));
  180. $params['final_amount'] = trim($request->input('final_amount', null));
  181. $params['actual_consumption_before'] = trim($request->input('actual_consumption_before', null)); //实际消耗
  182. $params['link_fee_before'] = trim($request->input('link_fee_before', null)); //链接费
  183. $params['flow_boost_back_point_before'] = trim($request->input('flow_boost_back_point_before', null)); //流量助推
  184. $params['top_fee_before'] = trim($request->input('top_fee_before', null)); //置顶费
  185. $params['actual_consumption_after'] = trim($request->input('actual_consumption_after', null)); //实际消耗
  186. $params['link_fee_after'] = trim($request->input('link_fee_after', null)); //链接费
  187. $params['flow_boost_back_point_after'] = trim($request->input('flow_boost_back_point_after', null)); //流量助推
  188. $params['top_fee_after'] = trim($request->input('top_fee_after', null)); //置顶费
  189. $params['customer_rebate_amount'] = trim($request->input('customer_rebate_amount', null));
  190. $params['rebate_expense_receiving_unit'] = trim($request->input('rebate_expense_receiving_unit', null)); //暂估返点支出收款单位
  191. $params['income_red_invoice_date'] = trim($request->input('income_red_invoice_date', null)); //开具红字发票日期
  192. $params['income_red_invoice_amount'] = trim($request->input('income_red_invoice_amount', null)); //开具红字发票金额
  193. $params['cpa_single_quantity'] = trim($request->input('cpa_single_quantity', null)); //cpa单量
  194. $params['saler_note'] = trim($request->input('saler_note', null)); //(备注)利润异常原因
  195. // $params['if_public'] = $request->input('if_public');
  196. $id = (int)$request->input('id');
  197. $verifyEdit = (int)$request->input('verify_edit');
  198. //锁单修改提交审核
  199. if($verifyEdit){
  200. $opReason = $request->input('op_reason');
  201. if(12 == $roleId) {
  202. $res = SpecialColumnEditService::orderIncomeVerifyAdd($id, $params, $opReason, $roleId);
  203. } else {
  204. $res = OrderIncomeService::orderIncomeVerifyAdd($id, $params, $opReason, $roleId);
  205. }
  206. } else {
  207. //正常修改
  208. $res = OrderIncomeService::orderIncomeUpdate($id, $params, $roleId);
  209. }
  210. if( is_numeric($res) && in_array($res, [
  211. 1216, 1217, 1223, 1224, 1225, 1228, 1232,
  212. 2002,
  213. 3015, 3016, 3017,
  214. 4199, 4200, 4201, 4205,
  215. 5005,
  216. 6003 ]) ){
  217. return self::returnValue(['msg' => '操作有误'], $res);
  218. }
  219. return self::returnValue($res);
  220. }
  221. /**
  222. * 批量删除订单
  223. */
  224. public function orderIncomeBatchDel(Request $request)
  225. {
  226. $validator = \Validator::make($request->all(), [
  227. 'id_list' => 'required',
  228. ], [
  229. 'id_list.required' => '需选择订单',
  230. ]);
  231. if ($validator->fails()) {
  232. return self::returnValue($validator->getMessageBag(), 1102);
  233. }
  234. $idList = $request->input('id_list');
  235. list($res, $code) = OrderIncomeService::orderIncomeBatchDel($idList);
  236. return self::returnValue($res, $code);
  237. }
  238. /*
  239. * 单条编辑mcn数据
  240. */
  241. public function orderMcnUpdate(Request $request)
  242. {
  243. $validator = \Validator::make($request->all(), [
  244. 'id' => 'required|int',
  245. 'mcn_name' => 'nullable|string',
  246. 'mcn_rebate' => 'nullable|string',
  247. 'mcn_handler' => 'nullable|string',
  248. 'mcn_user' => 'nullable|string',
  249. 'organization_amount' => 'nullable|string',
  250. 'mcn_final_amount' => 'nullable|string',
  251. ], [
  252. 'id.required' => '需选择订单',
  253. ]);
  254. if ($validator->fails()) {
  255. return self::returnValue($validator->getMessageBag(), 1102);
  256. }
  257. //获取当前角色
  258. $user = \Auth::user();
  259. $roleId = $user->role_id;
  260. $params = array();
  261. $params['mcn_name'] = trim($request->input('mcn_name'));//客户全称
  262. $params['mcn_handler'] = trim($request->input('mcn_handler'));
  263. $params['mcn_user'] = trim($request->input('mcn_user'));
  264. $params['organization_amount'] = trim($request->input('organization_amount'));
  265. $params['mcn_final_amount'] = trim($request->input('mcn_final_amount'));
  266. $id = (int)$request->input('id');
  267. $verifyEdit = (int)$request->input('verify_edit');
  268. //锁单修改提交审核
  269. if($verifyEdit){
  270. $opReason = $request->input('op_reason');
  271. if(12 == $roleId) {
  272. $res = SpecialColumnEditService::orderMcnVerifyAdd($id, $params, $opReason, $roleId);
  273. } else {
  274. $res = OrderMcnService::orderMcnVerifyAdd($id, $params, $opReason, $roleId);
  275. }
  276. } else {
  277. $res = OrderMcnService::orderMcnUpdate($id, $params, $roleId);
  278. }
  279. if( is_numeric($res) && in_array($res, [
  280. 1216,
  281. 2002,
  282. 4199, 4200, 4201, 4205,
  283. 6003, 6007, 6008
  284. ]) ){
  285. return self::returnValue(['msg' => '操作有误'], $res);
  286. }
  287. return self::returnValue($res);
  288. }
  289. public function orderMcnList(Request $request)
  290. {
  291. $validator = \Validator::make($request->all(), [
  292. 'page' => 'required|int',
  293. 'page_size' => 'required|int',
  294. ]);
  295. if ($validator->fails()) {
  296. return self::returnValue($validator->getMessageBag(), 1102);
  297. }
  298. $search = $request->all();
  299. $page = $request->input('page', 1);
  300. $pageSize = $request->input('page_size', 20);
  301. $isExport = (int)$request->input('is_export');
  302. list($data, $total) = OrderMcnService::orderMcnList($page, $pageSize, $search, $isExport);
  303. return self::returnPageValue($data, $total, $pageSize, $page);
  304. }
  305. public function orderMcnBatchDel(Request $request)
  306. {
  307. $validator = \Validator::make($request->all(), [
  308. 'id_list' => 'required'
  309. ]);
  310. if ($validator->fails()) {
  311. return self::returnValue($validator->getMessageBag(), 1102);
  312. }
  313. $idList = $request->input('id_list');
  314. list($res, $code) = OrderMcnService::orderMcnBatchDel($idList);
  315. return self::returnValue($res, $code);
  316. }
  317. public function batchSetRedInvoice(Request $request)
  318. {
  319. $validator = \Validator::make($request->all(), [
  320. 'id_list' => 'required',
  321. 'red_invoice_date' => 'nullable|date',
  322. 'refund_invoice_date' => 'nullable|date',
  323. ], [
  324. 'id_list.required' => '需选择订单',
  325. ]);
  326. if ($validator->fails()) {
  327. return self::returnValue($validator->getMessageBag(), 1102);
  328. }
  329. $idList = $request->input('id_list');
  330. $redInvoiceDate = $request->input('red_invoice_date');
  331. $refundInvoiceDate = $request->input('refund_invoice_date');
  332. $res = NewOrderService::batchSetRedInvoice($idList, $redInvoiceDate, $refundInvoiceDate);
  333. return self::returnValue($res);
  334. }
  335. public function lockMonthOrderSecond(Request $request)
  336. {
  337. $validator = \Validator::make($request->all(), [
  338. 'month' => 'required|string',
  339. 'type' => 'required|int',
  340. ], [
  341. 'month.required' => '参数有误',
  342. ]);
  343. if ($validator->fails()) {
  344. return self::returnValue($validator->getMessageBag(), 1102);
  345. }
  346. $month = $request->input('month');
  347. $month = date('Y-m-01', strtotime($month) );
  348. $type = (int)$request->input('type');
  349. if( !NewOrderService::note($month, $type)) {
  350. return self::returnValue([], 8002);
  351. }
  352. if( !NewOrderService::enableLock($month, $type) ){
  353. return self::returnValue([], 8001);
  354. }
  355. list($res, $code) = NewOrderService::lockMonthOrder($month, $type);
  356. return self::returnValue($res, $code);
  357. }
  358. /**
  359. * 解锁-财务退回
  360. */
  361. public function unlockOrder(Request $request)
  362. {
  363. $validator = \Validator::make($request->all(), [
  364. 'month' => 'required|string',
  365. ], [
  366. 'month.required' => '参数有误',
  367. ]);
  368. if ($validator->fails()) {
  369. return self::returnValue($validator->getMessageBag(), 1102);
  370. }
  371. $month = $request->input('month');
  372. $month = date('Y-m-01', strtotime($month) );
  373. list($res, $code) = NewOrderService::unlockOrder($month);
  374. return self::returnValue($res, $code);
  375. }
  376. public function batchVerifyDetail(Request $request)
  377. {
  378. $validator = \Validator::make($request->all(), [
  379. 'edit_ids' => 'required',
  380. ], [
  381. 'edit_ids.required' => '参数有误',
  382. ]);
  383. if ($validator->fails()) {
  384. return self::returnValue($validator->getMessageBag(), 1102);
  385. }
  386. $editIdList = $request->input('edit_ids');
  387. list($code, $list) = NewOrderService::batchVerifyDetail($editIdList);
  388. return self::returnValue($list, $code);
  389. }
  390. public function batchVerify(Request $request)
  391. {
  392. $validator = \Validator::make($request->all(), [
  393. 'edit_ids' => 'required',
  394. 'verify_status' => 'required|int',
  395. 'reason' => 'nullable|string'
  396. ], [
  397. 'edit_ids.required' => '参数有误',
  398. ]);
  399. if ($validator->fails()) {
  400. return self::returnValue($validator->getMessageBag(), 1102);
  401. }
  402. $editIdList = $request->input('edit_ids');
  403. $verifyStatus = $request->input('verify_status');
  404. $reason = $request->input('reason');
  405. list($code, $res) = NewOrderService::batchVerify($editIdList, $verifyStatus, $reason);
  406. return self::returnValue($res, $code);
  407. }
  408. public function getAllMonthList()
  409. {
  410. $list = NewOrderService::getAllMonthList();
  411. return self::returnValue($list);
  412. }
  413. /**
  414. * 撤销审核订单
  415. */
  416. public static function delVerifyOrderSecond(Request $request)
  417. {
  418. $validator = \Validator::make($request->all(), [
  419. 'id' => 'nullable|int',
  420. 'order_id' => 'nullable|int',
  421. 'type' => 'required|in:1,2'
  422. ], [
  423. 'id.int' => '参数有误',
  424. ]);
  425. if ($validator->fails()) {
  426. return self::returnValue($validator->getMessageBag(), 1102);
  427. }
  428. $id = $request->input('id');
  429. $order_id = $request->input('order_id');
  430. $type = $request->input('type');
  431. if(!$id && !$order_id){
  432. return self::returnValue(null, 1102);
  433. }
  434. $res = NewOrderService::delVerifyOrderSecond($id, $order_id, $type);
  435. if( !$res ){
  436. return self::returnValue($res, 4401);
  437. }
  438. return self::returnValue($res);
  439. }
  440. /*
  441. * 批量修改
  442. */
  443. public function importUpdate(Request $request)
  444. {
  445. $validator = \Validator::make($request->all(), [
  446. 'file' => 'required|file',
  447. 'reason' => 'required'
  448. ]);
  449. if ($validator->fails()) {
  450. return self::returnValue(['error' => $validator->errors()], 1102);
  451. }
  452. $file = $request->file('file');
  453. $reason = $request->input('reason');
  454. $res = NewOrderService::importUpdate($file, $reason);
  455. if ($res['code'] == 0) {
  456. return self::returnValue(['info'=>'导入成功']);
  457. } else {
  458. return self::returnValue(['error'=>$res['info']], $res['code']);
  459. }
  460. }
  461. public function enableBatchUpdateField()
  462. {
  463. $list = config('batch_update');
  464. //获取当前角色
  465. $user = \Auth::user();
  466. $roleId = $user->role_id;
  467. if($roleId != 12) {
  468. unset($list['customer_rebate_amount']);
  469. unset($list['rebate_expense_receiving_unit']);
  470. }
  471. return self::returnValue(array_values($list));
  472. }
  473. public function verifyZeroOrder(Request $request) {
  474. $validator = \Validator::make($request->all(), [
  475. 'month' => 'required|string',
  476. 'type' => 'required|int',
  477. ], [
  478. 'month.required' => '参数有误',
  479. ]);
  480. if ($validator->fails()) {
  481. return self::returnValue($validator->getMessageBag(), 1102);
  482. }
  483. $month = $request->input('month');
  484. $month = date('Y-m-01', strtotime($month) );
  485. $type = (int)$request->input('type');
  486. // if(2 == $type) {
  487. // return self::returnValue([]);
  488. // }
  489. $data = NewOrderService::verifyZeroOrder($month);
  490. return self::returnValue($data);
  491. }
  492. public function deleteZeroOrder(Request $request) {
  493. $validator = \Validator::make($request->all(), [
  494. 'month' => 'required|string',
  495. ], [
  496. 'month.required' => '参数有误',
  497. ]);
  498. if ($validator->fails()) {
  499. return self::returnValue($validator->getMessageBag(), 1102);
  500. }
  501. $month = $request->input('month');
  502. $month = date('Y-m-01', strtotime($month) );
  503. $code = 0;
  504. $data = NewOrderService::deleteZeroOrder($month, $code);
  505. return self::returnValue($data, $code);
  506. }
  507. public function zeroOrderList(Request $request) {
  508. $validator = \Validator::make($request->all(), [
  509. 'month' => 'required|string',
  510. ], [
  511. 'month.required' => '参数有误',
  512. ]);
  513. if ($validator->fails()) {
  514. return self::returnValue($validator->getMessageBag(), 1102);
  515. }
  516. $month = $request->input('month');
  517. $month = date('Y-m-01', strtotime($month) );
  518. $data = NewOrderService::zeroOrderList($month);
  519. return self::returnValue($data);
  520. }
  521. }