新版订单消耗系统

CustomerInvoicesController.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2021/6/15
  6. * Time: 17:02
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Services\InvoiceService;
  10. use Illuminate\Http\Request;
  11. class CustomerInvoicesController extends Controller
  12. {
  13. /*
  14. * 发票作废申请
  15. */
  16. public function voidedOrderAdd(Request $request)
  17. {
  18. $validator = \Validator::make($request->all(), [
  19. 'id' => 'required|int',
  20. 'reason' => 'required|string',
  21. 'files' => 'required|array',
  22. ]);
  23. if ($validator->fails()) {
  24. return self::returnValue(['error' => $validator->errors()], 1102);
  25. }
  26. $id = $request->input('id');
  27. $reason = $request->input('reason');
  28. $files = $request->input('files');
  29. if(!empty($files)){
  30. $files = array_map(function($val){
  31. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  32. },$files);
  33. }
  34. list($res, $code) = InvoiceService::voidedOrderAdd($id, $reason, $files);
  35. return self::returnValue($res, $code);
  36. }
  37. /*
  38. * 发票作废申请审批
  39. */
  40. public function verifyVoidedInvoice(Request $request)
  41. {
  42. // 处理验证失败信息,不要直接抛异常
  43. $validator = \Validator::make($request->all(), [
  44. 'id' => 'required|int',
  45. 'status' => 'required|int',
  46. 'verify_note' => 'nullable|string',
  47. ]);
  48. if ($validator->fails()) {
  49. return self::returnValue(['error' => $validator->errors()], 1102);
  50. }
  51. $id = (int)$request->input('id');
  52. $status = $request->input('status');
  53. $verifyNote = $request->input('verify_note');
  54. $res = InvoiceService::verifyVoidedInvoice($id, $status, $verifyNote);
  55. if( !$res ){
  56. return self::returnValue($res, 7003);
  57. }
  58. return self::returnValue($res);
  59. }
  60. public function voidedOrderUpdate(Request $request)
  61. {
  62. $validator = \Validator::make($request->all(), [
  63. 'id' => 'required|int',
  64. 'reason' => 'required|string',
  65. 'files' => 'required|array',
  66. ]);
  67. if ($validator->fails()) {
  68. return self::returnValue(['error' => $validator->errors()], 1102);
  69. }
  70. $id = $request->input('id');
  71. $reason = $request->input('reason');
  72. $files = $request->input('files');
  73. if(!empty($files)){
  74. $files = array_map(function($val){
  75. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  76. },$files);
  77. }
  78. list($res, $code) = InvoiceService::voidedOrderUpdate($id, $reason, $files);
  79. return self::returnValue($res, $code);
  80. }
  81. /*
  82. * 新版发票编辑(删除原来的发票,并且生成新的发票)
  83. * 判断发票状态为驳回还是撤销
  84. */
  85. public function editInvoiceNew(Request $request)
  86. {
  87. // 处理验证失败信息,不要直接抛异常
  88. $validator = \Validator::make($request->all(), [
  89. 'id' => 'required|int',
  90. 'tax_id' => 'nullable|string',
  91. 'address_tel' => 'nullable|string',
  92. 'bank_account' => 'nullable|string',
  93. ]);
  94. if ($validator->fails()) {
  95. return self::returnValue(['error' => $validator->errors()], 1102);
  96. }
  97. $user = \Auth::user();
  98. $id = (int)$request->input('id');
  99. #判断开票资格
  100. if(!InvoiceService::verifyInvoiceReply($id)){
  101. return self::returnValue(['error'=>'已经重新申请开票了或者结算单被撤销了'], 1102);
  102. }
  103. $params = array();
  104. $params['tax_id'] = $request->input('tax_id');
  105. $params['address_tel'] = $request->input('address_tel');
  106. $params['bank_account'] = $request->input('bank_account');
  107. $params['service_type'] = $request->input('service_type');
  108. $params['consignee'] = $request->input('consignee');//收件人
  109. $params['contacts'] = $request->input('contacts');//联系人
  110. $params['contact_number'] = $request->input('contact_number');//联系电话
  111. $params['mail_address'] = $request->input('mail_address');//联系电话
  112. $params['note'] = $request->input('note');
  113. $files = $request->input('files');
  114. if(!empty($files)){
  115. $files = array_map(function($val){
  116. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  117. },$files);
  118. }
  119. $params['url_json'] = json_encode($files);
  120. $params = array_filter($params);
  121. if(empty($params)){
  122. return self::returnValue(['未做修改'], 4199);
  123. }
  124. list($res, $code) = InvoiceService::editInvoiceNew($id, $params);
  125. return self::returnValue($res, $code);
  126. }
  127. /*
  128. * 发票撤销(财务及出纳权限)
  129. * 财务审核通过状态
  130. * 直接将发票enable更新为0
  131. */
  132. public function invoiceCancel(Request $request)
  133. {
  134. // 处理验证失败信息,不要直接抛异常
  135. $validator = \Validator::make($request->all(), [
  136. 'id' => 'required|int',
  137. 'verify_note' => 'nullable|string',
  138. ]);
  139. if ($validator->fails()) {
  140. return self::returnValue(['error' => $validator->errors()], 1102);
  141. }
  142. $id = (int)$request->input('id');
  143. $verify_note = $request->input('verify_note');
  144. $res = InvoiceService::invoiceCancel($id, $verify_note);
  145. if( !$res ){
  146. return self::returnValue($res, 7003);
  147. }
  148. return self::returnValue($res);
  149. }
  150. /*
  151. * 发票撤回申请
  152. * 待审核状态
  153. */
  154. public function invoiceWithdraw(Request $request)
  155. {
  156. // 处理验证失败信息,不要直接抛异常
  157. $validator = \Validator::make($request->all(), [
  158. 'id' => 'required|int',
  159. ]);
  160. if ($validator->fails()) {
  161. return self::returnValue(['error' => $validator->errors()], 1102);
  162. }
  163. $id = (int)$request->input('id');
  164. list($res, $code) = InvoiceService::invoiceWithdraw($id);
  165. return self::returnValue($res, $code);
  166. }
  167. // 红字发票申请列表
  168. public function redInvoicesList(Request $request)
  169. {
  170. $validator = \Validator::make($request->all(), [
  171. 'customer_name' => 'nullable|string',
  172. 'status' => 'nullable|int',
  173. 'cdate' => 'nullable|date',
  174. 'page' => 'required|int|min:1',
  175. 'approved_start_date' => 'nullable|date_format:Y-m-d',
  176. 'approved_end_date' => 'nullable|date_format:Y-m-d',
  177. ]);
  178. if ($validator->fails()) {
  179. return self::returnValue(['error' => $validator->errors()], 1102);
  180. }
  181. //获取当前角色
  182. $user = \Auth::user();
  183. $role_id = $user->role_id;
  184. $search = array();
  185. #销售媒介只能看自己提的
  186. if($role_id == 9 || $role_id == 11){
  187. $search['handler_id'] = $user->id;
  188. }
  189. $search['status'] = $request->input('status');
  190. $search['customer_name'] = $request->input('customer_name');
  191. $search['cdate'] = $request->input('cdate');
  192. $search['company'] = $request->input('company');
  193. $search['approved_start_date'] = $request->input('approved_start_date');
  194. $search['approved_end_date'] = $request->input('approved_end_date');
  195. $search['id'] = $request->input('id');
  196. $page = (int)$request->input('page', 1);
  197. $pagesize = (int)$request->input('pagesize', 20);
  198. list($data, $total) = InvoiceService::redInvoiceList($search, $page, $pagesize);
  199. return self::returnPageValue($data, $total, $pagesize, $page);
  200. }
  201. // 红字发票详情
  202. public function redInvoicesDetail(Request $request)
  203. {
  204. // 处理验证失败信息,不要直接抛异常
  205. $validator = \Validator::make($request->all(), [
  206. 'id' => 'required|int'
  207. ]);
  208. if ($validator->fails()) {
  209. return self::returnValue(['error' => $validator->errors()], 1102);
  210. }
  211. $id = (int)$request->input('id');
  212. $res = InvoiceService::redInvoiceDetail($id);
  213. return self::returnValue($res);
  214. }
  215. // 红字发票审核
  216. public function redInvoicesVerify(Request $request)
  217. {
  218. // 处理验证失败信息,不要直接抛异常
  219. $validator = \Validator::make($request->all(), [
  220. 'id' => 'required|int',
  221. 'status' => 'required|int',
  222. 'verify_note' => 'nullable|string',
  223. ]);
  224. if ($validator->fails()) {
  225. return self::returnValue(['error' => $validator->errors()], 1102);
  226. }
  227. $id = (int)$request->input('id');
  228. $status = $request->input('status');
  229. $verify_note = $request->input('verify_note');
  230. $res = InvoiceService::redInvoicesVerify($id, $status, $verify_note);
  231. if(!$res) {
  232. return self::returnValue($res, 7003);
  233. }
  234. return self::returnValue($res, 0);
  235. }
  236. public function redInvoiceEdit(Request $request)
  237. {
  238. // 处理验证失败信息,不要直接抛异常
  239. $validator = \Validator::make($request->all(), [
  240. 'id' => 'required|int',
  241. 'tax_id' => 'nullable|string',
  242. 'address_tel' => 'nullable|string',
  243. 'bank_account' => 'nullable|string',
  244. ]);
  245. if ($validator->fails()) {
  246. return self::returnValue(['error' => $validator->errors()], 1102);
  247. }
  248. $user = \Auth::user();
  249. $id = (int)$request->input('id');
  250. #判断开票资格
  251. if(!InvoiceService::verifyRedInvoiceReply($id)){
  252. return self::returnValue(['error'=>'已经重新申请开票了'], 1102);
  253. }
  254. $params = array();
  255. $params['tax_id'] = $request->input('tax_id');
  256. $params['address_tel'] = $request->input('address_tel');
  257. $params['bank_account'] = $request->input('bank_account');
  258. $params['service_type'] = $request->input('service_type');
  259. $params['consignee'] = $request->input('consignee');//收件人
  260. $params['contacts'] = $request->input('contacts');//联系人
  261. $params['contact_number'] = $request->input('contact_number');//联系电话
  262. $params['mail_address'] = $request->input('mail_address');//联系电话
  263. $params['note'] = $request->input('note');
  264. $files = $request->input('files');
  265. if(!empty($files)){
  266. $files = array_map(function($val){
  267. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  268. },$files);
  269. }
  270. $params['url_json'] = json_encode($files);
  271. $params = array_filter($params);
  272. if(empty($params)){
  273. return self::returnValue(['未做修改'], 4199);
  274. }
  275. list($res, $code) = InvoiceService::editRedInvoiceNew($id, $params);
  276. return self::returnValue($res, $code);
  277. }
  278. /**
  279. * 红字发票申请导入
  280. */
  281. public function redApplyImport(Request $request)
  282. {
  283. // 处理验证失败信息,不要直接抛异常
  284. $validator = \Validator::make($request->all(), [
  285. 'file' => 'required|file'
  286. ]);
  287. if ($validator->fails()) {
  288. return self::returnValue(['error' => $validator->errors()], 1102);
  289. }
  290. $file = $request->file('file');
  291. $res = InvoiceService::redApplyImport($file);
  292. if ($res['code'] == 0) {
  293. return self::returnValue($res);
  294. } else {
  295. return self::returnValue(['error'=>$res['info']], $res['code']);
  296. }
  297. }
  298. /**
  299. * 红字发票申请导入文件详情
  300. */
  301. public function redApplyOrders(Request $request)
  302. {
  303. // 处理验证失败信息,不要直接抛异常
  304. $validator = \Validator::make($request->all(), [
  305. 'filename' => 'required|string'
  306. ]);
  307. if ($validator->fails()) {
  308. return self::returnValue(['error' => $validator->errors()], 1102);
  309. }
  310. $filename = $request->input('filename');
  311. $res = InvoiceService::redApplyOrders($filename);
  312. if (!empty($res)) {
  313. return self::returnValue($res);
  314. } else {
  315. return self::returnValue($res, 10001);
  316. }
  317. }
  318. /**
  319. * 红字发票申请导入文件详情
  320. */
  321. public function redApplyConfirm(Request $request)
  322. {
  323. // 处理验证失败信息,不要直接抛异常
  324. $validator = \Validator::make($request->all(), [
  325. 'filename' => 'required|string',
  326. 'invoice_type' => 'required|int',
  327. 'service_type' => 'required|string',
  328. 'invoice_note' => 'nullable|string',
  329. 'files' => 'required|array',
  330. ]);
  331. if ($validator->fails()) {
  332. return self::returnValue(['error' => $validator->errors()], 1102);
  333. }
  334. $user = \Auth::user();
  335. $filename = $request->input('filename');
  336. $params = array();
  337. $params['handler_id'] = $user->id;
  338. $params['handler'] = $user->real_name;
  339. $params['invoice_type'] = $request->input('invoice_type');
  340. $params['service_type'] = $request->input('service_type');
  341. $params['invoice_note'] = $request->input('invoice_note');
  342. $params['consignee'] = $request->input('consignee');//收件人
  343. $params['contacts'] = $request->input('contacts');//联系人
  344. $params['contact_number'] = $request->input('contact_number');//联系电话
  345. $params['mail_address'] = $request->input('mail_address');//联系电话
  346. $params['note'] = $request->input('note');
  347. $files = $request->input('files');
  348. if(!empty($files)){
  349. $files = array_map(function($val){
  350. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  351. },$files);
  352. }
  353. $params['urls'] = $files;
  354. list($res, $code) = InvoiceService::setRedInvoice($filename, $params);
  355. return self::returnValue($res, $code);
  356. }
  357. }