新版订单消耗系统

StatementsController.php 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2021/1/26
  6. * Time: 15:30
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Services\StatementsService;
  10. use Illuminate\Http\Request;
  11. class StatementsController extends Controller
  12. {
  13. /*
  14. * 结算单列表
  15. */
  16. public function index(Request $request)
  17. {
  18. // 处理验证失败信息,不要直接抛异常
  19. $validator = \Validator::make($request->all(), [
  20. 'type' => 'required|in:1,2',
  21. 'is_my' => 'nullable|numeric',
  22. 'status' => 'nullable|integer',
  23. 'month' => 'nullable|date_format:Y-m',
  24. 'apply_start_date' => 'nullable|date_format:Y-m-d',
  25. 'apply_end_date' => 'nullable|date_format:Y-m-d',
  26. 'page' => 'nullable|numeric|min:1',
  27. 'page_size' => 'nullable|numeric'
  28. ]);
  29. if ($validator->fails()) {
  30. return self::returnValue(['error' => $validator->errors()], 1102);
  31. }
  32. $params['is_my'] = $request->input('is_my', 0);
  33. $params['status'] = $request->input('status', 0);
  34. $params['month'] = $request->input('month');
  35. $params['applicant'] = $request->input('applicant');
  36. $params['apply_start_date'] = $request->input('apply_start_date');
  37. $params['apply_end_date'] = $request->input('apply_end_date');
  38. $params['type'] = $request->input('type', 1);
  39. $params['customer_name'] = $request->input('customer_name');
  40. $page = $request->input('page', 1);
  41. $pageSize = $request->input('page_size', 20);
  42. list($list, $count) = StatementsService::index($page, $pageSize, $params);
  43. return self::returnPageValue($list, $count, $pageSize, $page);
  44. }
  45. /*
  46. * 添加结算饭
  47. */
  48. public function add(Request $request)
  49. {
  50. // 处理验证失败信息,不要直接抛异常
  51. $validator = \Validator::make($request->all(), [
  52. 'order_data' => 'required',
  53. 'type' => 'required|in:1,2',
  54. 'party_a_ein' => 'required',
  55. 'party_a_account' => 'required',
  56. 'party_a_contact' => 'required',
  57. 'party_a_phone' => 'required',
  58. 'party_b_contact' => 'required',
  59. 'party_b_phone' => 'required',
  60. 'add_date' => 'required',
  61. 'customer_name' => 'required',
  62. 'party_a_address' => 'required'
  63. ]);
  64. if ($validator->fails()) {
  65. return self::returnValue(['error' => $validator->errors()], 1102);
  66. }
  67. $type = $request->input('type');
  68. $orderData = $request->input('order_data');
  69. if (!is_array($orderData)) {
  70. $orderData = json_decode($orderData, 1);
  71. }
  72. $statementsData['party_a_ein'] = $request->input('party_a_ein');
  73. $statementsData['party_a_account'] = $request->input('party_a_account');
  74. $statementsData['party_a_contact'] = $request->input('party_a_contact');
  75. $statementsData['party_a_phone'] = $request->input('party_a_phone');
  76. $statementsData['party_b_contact'] = $request->input('party_b_contact');
  77. $statementsData['party_b_phone'] = $request->input('party_b_phone');
  78. $statementsData['add_date'] = $request->input('add_date');
  79. $statementsData['customer_name'] = $request->input('customer_name');
  80. $statementsData['party_a_address'] = $request->input('party_a_address');
  81. $statementsData['is_pdd'] = $request->input('is_pdd',0);
  82. if ($type == 1) {
  83. list($res, $code) = StatementsService::SalerStatementsStore($orderData, $statementsData);
  84. } else {
  85. list($res, $code) = StatementsService::McnStatementsStore($orderData, $statementsData);
  86. }
  87. return self::returnValue($res, $code);
  88. }
  89. /*
  90. * 结算单详情
  91. */
  92. public function detail(Request $request)
  93. {
  94. // 处理验证失败信息,不要直接抛异常
  95. $validator = \Validator::make($request->all(), [
  96. 'id' => 'required|integer'
  97. ]);
  98. if ($validator->fails()) {
  99. return self::returnValue(['error' => $validator->errors()], 1102);
  100. }
  101. $id = $request->input('id');
  102. list($res, $code) = StatementsService::detail($id);
  103. return self::returnValue($res, $code);
  104. }
  105. /*
  106. * 结算单编辑
  107. */
  108. public function update(Request $request)
  109. {
  110. // 处理验证失败信息,不要直接抛异常
  111. $validator = \Validator::make($request->all(), [
  112. 'order_data' => 'required',
  113. 'type' => 'required|in:1,2',
  114. 'party_a_ein' => 'required',
  115. 'party_a_account' => 'required',
  116. 'party_a_contact' => 'required',
  117. 'party_a_phone' => 'required',
  118. 'party_b_contact' => 'required',
  119. 'party_b_phone' => 'required',
  120. 'add_date' => 'required',
  121. 'id' => 'required'
  122. ]);
  123. if ($validator->fails()) {
  124. return self::returnValue(['error' => $validator->errors()], 1102);
  125. }
  126. $id = $request->input('id');
  127. $type = $request->input('type');
  128. $orderData = $request->input('order_data');
  129. if (!is_array($orderData)) {
  130. $orderData = json_decode($orderData, 1);
  131. }
  132. $statementsData['party_a_ein'] = $request->input('party_a_ein');
  133. $statementsData['party_a_address'] = $request->input('party_a_address');
  134. $statementsData['party_a_account'] = $request->input('party_a_account');
  135. $statementsData['party_a_contact'] = $request->input('party_a_contact');
  136. $statementsData['party_a_phone'] = $request->input('party_a_phone');
  137. $statementsData['party_b_contact'] = $request->input('party_b_contact');
  138. $statementsData['party_b_phone'] = $request->input('party_b_phone');
  139. $statementsData['add_date'] = $request->input('add_date');
  140. if ($type == 1) {
  141. list($res, $code) = StatementsService::SalerStatementsUpdate($id, $orderData, $statementsData);
  142. } else {
  143. list($res, $code) = StatementsService::McnStatementsUpdate($id, $orderData, $statementsData);
  144. }
  145. return self::returnValue($res, $code);
  146. }
  147. /*
  148. * 返回确认单的订单信息以及乙方银行账户信息
  149. */
  150. public function preData(Request $request)
  151. {
  152. // 处理验证失败信息,不要直接抛异常
  153. $validator = \Validator::make($request->all(), [
  154. 'order_ids' => 'required',
  155. 'type' => 'required|in:1,2',
  156. 'is_discount' => 'required|in:0,1'
  157. ]);
  158. if ($validator->fails()) {
  159. return self::returnValue(['error' => $validator->errors()], 1102);
  160. }
  161. $orderIds = $request->input('order_ids');
  162. $type = $request->input('type');
  163. $isDiscount = $request->input('is_discount', 0);
  164. list($data, $code) = StatementsService::getPreData($orderIds, $type, $isDiscount);
  165. return self::returnValue($data, $code);
  166. }
  167. /*
  168. * 结算单审核
  169. */
  170. public function verify(Request $request)
  171. {
  172. // 处理验证失败信息,不要直接抛异常
  173. $validator = \Validator::make($request->all(), [
  174. 'id' => 'required|integer',
  175. 'status' => 'required|in:2,3',
  176. 'opinion' => 'nullable|string'
  177. ]);
  178. if ($validator->fails()) {
  179. return self::returnValue(['error' => $validator->errors()], 1102);
  180. }
  181. $id = $request->input('id');
  182. $status = $request->input('status');
  183. $verifyOpinion = $request->input('opinion');
  184. if ($status == 3 && empty($verifyOpinion)) {
  185. return self::returnValue('操作失败', 1204);
  186. }
  187. list($res, $code) = StatementsService::verify($id, $status, $verifyOpinion);
  188. return self::returnValue($res, $code);
  189. }
  190. }