123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\api\controller;
- use app\api\controller\mall\Orders;
- use app\common\controller\Api;
- use app\common\validate\TaxValidate;
- use think\db\Query;
- use Yansongda\Supports\Arr;
- /**
- * 发票接口
- */
- class UserTax extends Api
- {
- protected $noNeedRight='*';
- use TaxValidate;
- /**
- * 发票列表
- * @ApiParams (name=from,description=1自己创建的2订单生成的)
- * @ApiParams (name=id,description=查看单条传id)
- * @ApiParams (name=page,description=分页)
- * @ApiParams (name=limit,description=分页)
- * @ApiReturnParams (name=status,description=1开票中2可查看)
- */
- public function list(){
- $user=$this->auth->getUser();
- $data=input();
- $map=[];
- if(!empty($data['id'])){
- $map['id']=$data['id'];
- }
- $tax=$user->tax()
- ->where($map)
- ->where(function (Query $query)use ($data){
- if(!empty($data['from'])){
- if($data['from']==1){
- $query->whereNull('order_id');
- }elseif ($data['from']==2){
- $query->whereNotNull('order_id');
- }
- }
- })
- ->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']??null,
- 'status'=>empty($item['orders']['tax_link'])?1:2,
- 'is_default'=>$item['is_default'],
- 'order_id'=>$item['order_id'],
- ];
- $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);
- }else {
- $user->tax()->save($needData);
- }
- $this->success();
- }
- /**
- * 删除发票
- * @ApiParams (name=id,description=ID)
- */
- public function del(){
- $user=$this->auth->getUser();
- $data=$this->_validate([
- 'id'=>['require']
- ]);
- $tax=$user->tax()->where('id',$data['id'])->delete();
- $this->success();
- }
- }
|