1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\api\controller;
- use app\api\controller\mall\Orders;
- use app\common\controller\Api;
- use app\common\validate\TaxValidate;
- use Yansongda\Supports\Arr;
- /**
- * 发票接口
- */
- class UserTax extends Api
- {
- protected $noNeedRight='*';
- use TaxValidate;
- /**
- * 发票列表
- * @ApiParams (name=page,description=分页)
- * @ApiParams (name=limit,description=分页)
- * @ApiReturnParams (name=status,description=1开票中2可查看)
- */
- public function list(){
- $user=$this->auth->getUser();
- $tax=$user->tax()
- ->with(['orders','orders.info'])
- ->order('is_default','desc')
- ->order('id','desc')
- ->paginate(input('limit',15));
- $newList=[
- 'data'=>[]
- ];
- foreach ($tax->items() as $item){
- $order=[
- 'order_no'=>$item['orders']['order_no']??'',
- 'create_time'=>$item['create_time'],
- 'amount_pay'=>$item['orders']['amount_pay']??0,
- 'tax'=>$item['tax'],
- 'info'=>$item['orders']['info']??[],
- 'id'=>$item['id'],
- 'tax_link'=>$item['orders']['tax_link'],
- 'status'=>empty($item['orders']['tax_link'])?1:2,
- ];
- $newList['data'][]=$order;
- }
- $newList['current_page']=$tax->currentPage();
- $newList['last_page']=$tax->lastPage();
- $newList['per_page']=$tax->listRows();
- $newList['total']=$tax->total();
- $this->success('',$newList);
- }
- /**
- * 创建发票
- * @ApiMethod (POST)
- * @ApiParams (name=id,description=如果要修改传ID)
- * @ApiParams (name=tax,description="发票对象,见注释")
- * @ApiParams (name=is_default,description="是1否0默认")
- */
- public function store(){
- $data=$this->request->post();
- $this->validateTaxBody($data);
- $user=$this->auth->getUser();
- $needData=Arr::only($data,['tax','is_default']);
- if(!empty($data['id'])){
- $tax=$user->tax()->findOrFail($data['id']);
- $tax->save($needData);
- }
- $user->tax()->save($needData);
- $this->success();
- }
- }
|