新版订单消耗系统

CustomerInvoicesComplementController.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2021/5/25
  6. * Time: 17:43
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Services\CustomerInvoicesComplementService;
  10. use Illuminate\Http\Request;
  11. class CustomerInvoicesComplementController extends Controller
  12. {
  13. public function add(Request $request)
  14. {
  15. $validator = \Validator::make($request->all(), [
  16. 'statements_id' => 'required|int',
  17. 'invoice_type' => 'required|int',
  18. 'service_type' => 'required|string',
  19. 'invoice_note' => 'nullable|string',
  20. 'files' => 'required|array',
  21. ]);
  22. if ($validator->fails()) {
  23. return self::returnValue(['error' => $validator->errors()], 1102);
  24. }
  25. $statements_id = $request->input('statements_id');
  26. #判断开票资格
  27. if(!CustomerInvoicesComplementService::verifySetInvoice($statements_id)){
  28. return self::returnValue(['msg'=>'已经存在对应开票'], 7001);
  29. }
  30. $params = array();
  31. $params['invoice_type'] = $request->input('invoice_type');
  32. $params['service_type'] = $request->input('service_type');
  33. $params['invoice_note'] = $request->input('invoice_note');
  34. $params['consignee'] = $request->input('consignee');//收件人
  35. $params['contacts'] = $request->input('contacts');//联系人
  36. $params['contact_number'] = $request->input('contact_number');//联系电话
  37. $params['mail_address'] = $request->input('mail_address');//联系电话
  38. $params['note'] = $request->input('note');
  39. $files = $request->input('files');
  40. if(!empty($files)){
  41. $files = array_map(function($val){
  42. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  43. },$files);
  44. }
  45. $params['url_json'] = json_encode($files);
  46. $res = CustomerInvoicesComplementService::add($statements_id, $params);
  47. return self::returnValue($res);
  48. }
  49. public function index(Request $request)
  50. {
  51. $validator = \Validator::make($request->all(), [
  52. 'customer_name' => 'nullable|string',
  53. 'status' => 'nullable|int',
  54. 'page' => 'required|int|min:1',
  55. 'order_month' => 'nullable|date_format:Y-m',
  56. 'change_month' => 'nullable|date_format:Y-m',
  57. 'approved_start_date' => 'nullable|date_format:Y-m-d',
  58. 'approved_end_date' => 'nullable|date_format:Y-m-d',
  59. ]);
  60. if ($validator->fails()) {
  61. return self::returnValue(['error' => $validator->errors()], 1102);
  62. }
  63. //获取当前角色
  64. $user = \Auth::user();
  65. $role_id = $user->role_id;
  66. $search = array();
  67. #销售媒介只能看自己提的
  68. if($role_id == 9 || $role_id == 11){
  69. $search['applicant_id'] = $user->id;
  70. }
  71. $search['status'] = $request->input('status');
  72. $search['customer_name'] = $request->input('customer_name');
  73. $search['invoice_month'] = $request->input('invoice_month');
  74. $search['company'] = $request->input('company');
  75. $search['order_month'] = $request->input('order_month');
  76. $search['change_month'] = $request->input('change_month');
  77. $isExport = $request->input('is_export', 0);
  78. $search['approved_start_date'] = $request->input('approved_start_date');
  79. $search['approved_end_date'] = $request->input('approved_end_date');
  80. $page = (int)$request->input('page', 1);
  81. $pagesize = (int)$request->input('pagesize', 20);
  82. if($role_id == 16) {
  83. $search['status'] = 4;
  84. }
  85. list($data, $total) = CustomerInvoicesComplementService::index($search, $page, $pagesize, $isExport);
  86. return self::returnPageValue($data, $total, $pagesize, $page);
  87. }
  88. public function detail(Request $request)
  89. {
  90. // 处理验证失败信息,不要直接抛异常
  91. $validator = \Validator::make($request->all(), [
  92. 'id' => 'required|int'
  93. ]);
  94. if ($validator->fails()) {
  95. return self::returnValue(['error' => $validator->errors()], 1102);
  96. }
  97. $id = (int)$request->input('id');
  98. $res = CustomerInvoicesComplementService::detail($id);
  99. return self::returnValue($res);
  100. }
  101. public function update(Request $request)
  102. {
  103. // 处理验证失败信息,不要直接抛异常
  104. $validator = \Validator::make($request->all(), [
  105. 'id' => 'required|int',
  106. 'tax_id' => 'nullable|string',
  107. 'address_tel' => 'nullable|string',
  108. 'bank_account' => 'nullable|string',
  109. ]);
  110. if ($validator->fails()) {
  111. return self::returnValue(['error' => $validator->errors()], 1102);
  112. }
  113. $params = array();
  114. $params['tax_id'] = $request->input('tax_id');
  115. $params['address_tel'] = $request->input('address_tel');
  116. $params['bank_account'] = $request->input('bank_account');
  117. $params['consignee'] = $request->input('consignee');//收件人
  118. $params['contacts'] = $request->input('contacts');//联系人
  119. $params['contact_number'] = $request->input('contact_number');//联系电话
  120. $params['mail_address'] = $request->input('mail_address');//联系电话
  121. $params['note'] = $request->input('note');
  122. $files = $request->input('files');
  123. if(!empty($files)){
  124. $files = array_map(function($val){
  125. return str_replace('https://order-consumption-system.oss-cn-beijing.aliyuncs.com', '', $val);
  126. },$files);
  127. }
  128. $params['url_json'] = json_encode($files);
  129. $params = array_filter($params);
  130. if(empty($params)){
  131. return self::returnValue(['未做修改'], 4199);
  132. }
  133. $id = (int)$request->input('id');
  134. $res = CustomerInvoicesComplementService::update($id, $params);
  135. if($res === 7002){
  136. return self::returnValue(['msg' => '非法操作'], $res);
  137. }
  138. return self::returnValue($res);
  139. }
  140. public function verify(Request $request)
  141. {
  142. // 处理验证失败信息,不要直接抛异常
  143. $validator = \Validator::make($request->all(), [
  144. 'id' => 'required|int',
  145. 'status' => 'required|int',
  146. 'verify_note' => 'nullable|string',
  147. ]);
  148. if ($validator->fails()) {
  149. return self::returnValue(['error' => $validator->errors()], 1102);
  150. }
  151. $id = (int)$request->input('id');
  152. $status = $request->input('status');
  153. $verify_note = $request->input('verify_note');
  154. $res = CustomerInvoicesComplementService::verify($id, $status, $verify_note);
  155. if( !$res ){
  156. return self::returnValue($res, 7003);
  157. }
  158. return self::returnValue($res);
  159. }
  160. public function actualInvoiced(Request $request)
  161. {
  162. // 处理验证失败信息,不要直接抛异常
  163. $validator = \Validator::make($request->all(), [
  164. 'ids' => 'required|array',
  165. 'date' => 'required|date'
  166. ]);
  167. if ($validator->fails()) {
  168. return self::returnValue(['error' => $validator->errors()], 1102);
  169. }
  170. $ids = $request->input('ids');
  171. $date = $request->input('date');
  172. $res = CustomerInvoicesComplementService::actualInvoiced($ids, $date);
  173. return self::returnValue($res);
  174. }
  175. public function delActualInvoiced(Request $request)
  176. {
  177. // 处理验证失败信息,不要直接抛异常
  178. $validator = \Validator::make($request->all(), [
  179. 'id' => 'required|int'
  180. ]);
  181. if ($validator->fails()) {
  182. return self::returnValue(['error' => $validator->errors()], 1102);
  183. }
  184. $id = $request->input('id');
  185. $res = CustomerInvoicesComplementService::delActualInvoiced($id);
  186. return self::returnValue($res);
  187. }
  188. }