UserTax.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\mall\Orders;
  4. use app\common\controller\Api;
  5. use app\common\validate\TaxValidate;
  6. use Yansongda\Supports\Arr;
  7. /**
  8. * 发票接口
  9. */
  10. class UserTax extends Api
  11. {
  12. protected $noNeedRight='*';
  13. use TaxValidate;
  14. /**
  15. * 发票列表
  16. * @ApiParams (name=page,description=分页)
  17. * @ApiParams (name=limit,description=分页)
  18. * @ApiReturnParams (name=status,description=1开票中2可查看)
  19. */
  20. public function list(){
  21. $user=$this->auth->getUser();
  22. $tax=$user->tax()
  23. ->with(['orders','orders.info'])
  24. ->order('is_default','desc')
  25. ->order('id','desc')
  26. ->paginate(input('limit',15));
  27. $newList=[
  28. 'data'=>[]
  29. ];
  30. foreach ($tax->items() as $item){
  31. $order=[
  32. 'order_no'=>$item['orders']['order_no']??'',
  33. 'create_time'=>$item['create_time'],
  34. 'amount_pay'=>$item['orders']['amount_pay']??0,
  35. 'tax'=>$item['tax'],
  36. 'info'=>$item['orders']['info']??[],
  37. 'id'=>$item['id'],
  38. 'tax_link'=>$item['orders']['tax_link'],
  39. 'status'=>empty($item['orders']['tax_link'])?1:2,
  40. ];
  41. $newList['data'][]=$order;
  42. }
  43. $newList['current_page']=$tax->currentPage();
  44. $newList['last_page']=$tax->lastPage();
  45. $newList['per_page']=$tax->listRows();
  46. $newList['total']=$tax->total();
  47. $this->success('',$newList);
  48. }
  49. /**
  50. * 创建发票
  51. * @ApiMethod (POST)
  52. * @ApiParams (name=id,description=如果要修改传ID)
  53. * @ApiParams (name=tax,description="发票对象,见注释")
  54. * @ApiParams (name=is_default,description="是1否0默认")
  55. */
  56. public function store(){
  57. $data=$this->request->post();
  58. $this->validateTaxBody($data);
  59. $user=$this->auth->getUser();
  60. $needData=Arr::only($data,['tax','is_default']);
  61. if(!empty($data['id'])){
  62. $tax=$user->tax()->findOrFail($data['id']);
  63. $tax->save($needData);
  64. }
  65. $user->tax()->save($needData);
  66. $this->success();
  67. }
  68. }