123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/1/26
- * Time: 15:30
- */
- namespace App\Http\Controllers\Api;
- use App\Services\StatementsService;
- use Illuminate\Http\Request;
- class StatementsController extends Controller
- {
- /*
- * 结算单列表
- */
- public function index(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'type' => 'required|in:1,2',
- 'is_my' => 'nullable|numeric',
- 'status' => 'nullable|integer',
- 'month' => 'nullable|date_format:Y-m',
- 'apply_start_date' => 'nullable|date_format:Y-m-d',
- 'apply_end_date' => 'nullable|date_format:Y-m-d',
- 'page' => 'nullable|numeric|min:1',
- 'page_size' => 'nullable|numeric'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $params['is_my'] = $request->input('is_my', 0);
- $params['status'] = $request->input('status', 0);
- $params['month'] = $request->input('month');
- $params['applicant'] = $request->input('applicant');
- $params['apply_start_date'] = $request->input('apply_start_date');
- $params['apply_end_date'] = $request->input('apply_end_date');
- $params['type'] = $request->input('type', 1);
- $params['customer_name'] = $request->input('customer_name');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- list($list, $count) = StatementsService::index($page, $pageSize, $params);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /*
- * 添加结算饭
- */
- public function add(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'order_data' => 'required',
- 'type' => 'required|in:1,2',
- 'party_a_ein' => 'required',
- 'party_a_account' => 'required',
- 'party_a_contact' => 'required',
- 'party_a_phone' => 'required',
- 'party_b_contact' => 'required',
- 'party_b_phone' => 'required',
- 'add_date' => 'required',
- 'customer_name' => 'required',
- 'party_a_address' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $type = $request->input('type');
- $orderData = $request->input('order_data');
- if (!is_array($orderData)) {
- $orderData = json_decode($orderData, 1);
- }
- $statementsData['party_a_ein'] = $request->input('party_a_ein');
- $statementsData['party_a_account'] = $request->input('party_a_account');
- $statementsData['party_a_contact'] = $request->input('party_a_contact');
- $statementsData['party_a_phone'] = $request->input('party_a_phone');
- $statementsData['party_b_contact'] = $request->input('party_b_contact');
- $statementsData['party_b_phone'] = $request->input('party_b_phone');
- $statementsData['add_date'] = $request->input('add_date');
- $statementsData['customer_name'] = $request->input('customer_name');
- $statementsData['party_a_address'] = $request->input('party_a_address');
- $statementsData['is_pdd'] = $request->input('is_pdd',0);
- if ($type == 1) {
- list($res, $code) = StatementsService::SalerStatementsStore($orderData, $statementsData);
- } else {
- list($res, $code) = StatementsService::McnStatementsStore($orderData, $statementsData);
- }
- return self::returnValue($res, $code);
- }
- /*
- * 结算单详情
- */
- public function detail(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- list($res, $code) = StatementsService::detail($id);
- return self::returnValue($res, $code);
- }
- /*
- * 结算单编辑
- */
- public function update(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'order_data' => 'required',
- 'type' => 'required|in:1,2',
- 'party_a_ein' => 'required',
- 'party_a_account' => 'required',
- 'party_a_contact' => 'required',
- 'party_a_phone' => 'required',
- 'party_b_contact' => 'required',
- 'party_b_phone' => 'required',
- 'add_date' => 'required',
- 'id' => 'required'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- $type = $request->input('type');
- $orderData = $request->input('order_data');
- if (!is_array($orderData)) {
- $orderData = json_decode($orderData, 1);
- }
- $statementsData['party_a_ein'] = $request->input('party_a_ein');
- $statementsData['party_a_address'] = $request->input('party_a_address');
- $statementsData['party_a_account'] = $request->input('party_a_account');
- $statementsData['party_a_contact'] = $request->input('party_a_contact');
- $statementsData['party_a_phone'] = $request->input('party_a_phone');
- $statementsData['party_b_contact'] = $request->input('party_b_contact');
- $statementsData['party_b_phone'] = $request->input('party_b_phone');
- $statementsData['add_date'] = $request->input('add_date');
- if ($type == 1) {
- list($res, $code) = StatementsService::SalerStatementsUpdate($id, $orderData, $statementsData);
- } else {
- list($res, $code) = StatementsService::McnStatementsUpdate($id, $orderData, $statementsData);
- }
- return self::returnValue($res, $code);
- }
- /*
- * 返回确认单的订单信息以及乙方银行账户信息
- */
- public function preData(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'order_ids' => 'required',
- 'type' => 'required|in:1,2',
- 'is_discount' => 'required|in:0,1'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $orderIds = $request->input('order_ids');
- $type = $request->input('type');
- $isDiscount = $request->input('is_discount', 0);
- list($data, $code) = StatementsService::getPreData($orderIds, $type, $isDiscount);
- return self::returnValue($data, $code);
- }
- /*
- * 结算单审核
- */
- public function verify(Request $request)
- {
- // 处理验证失败信息,不要直接抛异常
- $validator = \Validator::make($request->all(), [
- 'id' => 'required|integer',
- 'status' => 'required|in:2,3',
- 'opinion' => 'nullable|string'
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $id = $request->input('id');
- $status = $request->input('status');
- $verifyOpinion = $request->input('opinion');
- if ($status == 3 && empty($verifyOpinion)) {
- return self::returnValue('操作失败', 1204);
- }
- list($res, $code) = StatementsService::verify($id, $status, $verifyOpinion);
- return self::returnValue($res, $code);
- }
- }
|