123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\api\controller;
- use app\common\model\BillApply;
- use app\common\model\BillHeader;
- use app\common\model\BillType;
- use app\common\service\UserSynth;
- use app\common\validate\BillVali;
- /**
- * @title 发票模块【二期】
- * @controller Bill
- */
- class Bill extends Base
- {
- protected $need_login = [
- 'selBillHeader',
- 'getHeaderList',
- 'getBillHeaderDetail',
- 'delBillHeader',
- 'billApply',
- 'getApplyList',
- 'getApplyInfo',
- ];
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取发票类型
- * @desc 获取发票类型
- * @author qc
- * @url /api/Bill/getBillType
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:id
- * @return name:title type:string default:0 desc:名称
- */
- public function getBillType()
- {
- $list = BillType::getType();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 设置发票抬头
- * @desc 设置发票抬头
- * @author qc
- * @url /api/Bill/selBillHeader
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:id【修改传记录id,新增忽略】
- * @param name:type type:int default:0 desc:类型id
- * @param name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
- * @param name:identify_number type:string default:0 desc:纳税人识别号
- * @param name:email type:string default:0 desc:邮箱
- */
- public function selBillHeader()
- {
- $param = input('post.');
- $validate = new BillVali();
- //if (!$validate->check($param)) $this->error($validate->getError());
- $param['user_id'] = $this->user_id;
- if(isset($param['id']) && $param['id']) {
- BillHeader::where('id',$param['id'])->update($param);
- }else{
- BillHeader::create($param);
- }
- $this->success('编辑成功');
- }
- /**
- * @title 获取发票抬头列表
- * @desc 获取发票抬头列表
- * @author qc
- * @url /api/Bill/getHeaderList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
- * @return name:identify_number type:string default:0 desc:纳税人识别号
- * @return name:email type:string default:0 desc:邮箱
- */
- public function getHeaderList()
- {
- $sel_where=[];
- $sel_where['b.user_id'] = $this->user_id;
- $sel_where['b.is_deleted'] = 0;
- $list = BillHeader::field('b.id,b.header,b.identify_number,b.email')
- ->alias('b')
- ->where($sel_where)
- ->order('b.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $total_num = BillHeader::alias('b')->where($sel_where)->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取发票抬头详情
- * @desc 详情
- * @author qc
- * @url /api/Bill/getBillHeaderDetail
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:发票记录id
- * @return name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
- * @return name:identify_number type:string default:0 desc:纳税人识别号
- */
- public function getBillHeaderDetail()
- {
- $sel_where=[];
- $sel_where['b.user_id'] = $this->user_id;
- $sel_where['b.is_deleted'] = 0;
- if(!input('get.id'))$this->error('参数错误');
- $sel_where['b.id'] = input('get.id');
- $detail = BillHeader::field('b.id,b.header,b.identify_number')->where($sel_where)->find();
- if(!$detail) $this->error('没查到改记录');
- $this->success('ok',['detail'=>$detail->toArray()]);
- }
- /**
- * @title 删除发票抬头记录
- * @desc 删除发票抬头记录
- * @author qc
- * @url /api/Bill/delBillHeader
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:发票记录id
- */
- public function delBillHeader()
- {
- BillHeader::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
- $this->success('删除成功');
- }
- /**
- * @title 申请开票
- * @desc 申请开票
- * @author qc
- * @url /api/Bill/billApply
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:order_id type:int default:0 desc:订单id
- * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
- * @param name:header_id type:int default:0 desc:抬头id
- * @param name:send_type type:int default:1 desc:申请类型【1点子发票2纸质发票】
- * @param name:add_id type:int default:0 desc:售货地址id【点子发票忽略】
- * @param name:remark type:string default:0 desc:备注
- */
- public function billApply()
- {
- $this->error('接口停用');
- $order_id= input('post.order_id');
- $order_type = input('post.order_type');
- $header_id= input('post.header_id');
- $send_type= input('post.send_type');
- $add_id = input('post.add_id');
- $remark = input('post.remark');
- if($send_type == 2 && !$add_id) $this->error('请选择售货地址');
- $ret_val = UserSynth::buildBillApply($this->user_id, $order_id, $order_type,$header_id,$add_id,$send_type,$remark);
- $ret_val['code'] == 200 ? $this->success($ret_val['msg']) : $this->error($ret_val['msg']);
- }
- /**
- * @title 取消开票【删除开票】
- * @desc 取消开票【删除开票】
- * @author qc
- * @url /api/Bill/delApply
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:apply_id type:int default:0 desc:开票记录id【传这个值时,order_id和type可以为空】
- * @param name:order_id type:int default:0 desc:订单id【apply_id为空时必传】
- * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】【apply_id为空时必传】
- */
- public function delApply()
- {
- $apply_info = BillApply::where(input('post.'))->where('user_id',$this->user_id)->where('is_deleted',0)->find();
- if(empty($apply_info)) $this->error('申请记录有误');
- $apply_info->is_deleted = 1;
- $apply_info->save();
- $this->success('取消成功');
- }
- /**
- * @title 获取申请发票列表
- * @desc 获取申请发票列表
- * @author qc
- * @url /api/Bill/getApplyList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:header type:string default:0 desc:抬头
- * @return name:type type:int default:0 desc:发票类型
- * @return name:email type:string default:0 desc:邮箱
- * @return name:phone type:string default:0 desc:电话
- * @return name:bank type:string default:0 desc:开户行
- * @return name:card_no type:string default:0 desc:银行账号
- * @return name:identify_number type:string default:0 desc:纳税人识别号
- * @return name:bill_img type:string default:0 desc:点子发票url
- * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
- * @return name:remark type:string default:0 desc:备注
- * @return name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
- * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
- * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
- * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
- * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
- * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
- */
- public function getApplyList()
- {
- $sel_where=[];
- $sel_where['user_id'] = $this->user_id;
- $sel_where['is_deleted'] = 0;
- $list = BillApply::where($sel_where)
- ->order('create_at desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_map(function (&$val){
- $val['address_info'] = $val['address_info'] ? json_decode($val['address_info'],true):null;
- },$list);
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取开票详情
- * @desc 获取开票详情
- * @author qc
- * @url /api/Bill/getApplyInfo
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:apply_id type:int default:0 desc:开票记录id【传这个值时,order_id和type可以为空】
- * @param name:order_id type:int default:0 desc:订单id【apply_id为空时必传】
- * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】【apply_id为空时必传】
- *
- * @return name:header type:string default:0 desc:抬头
- * @return name:type type:int default:0 desc:发票类型
- * @return name:email type:string default:0 desc:邮箱
- * @return name:phone type:string default:0 desc:电话
- * @return name:bank type:string default:0 desc:开户行
- * @return name:card_no type:string default:0 desc:银行账号
- * @return name:identify_number type:string default:0 desc:纳税人识别号
- * @return name:bill_img type:string default:0 desc:点子发票url
- * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
- * @return name:remark type:string default:0 desc:备注
- * @return name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
- * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
- * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
- * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
- * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
- * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
- */
- public function getApplyInfo()
- {
- $apply_info = BillApply::where('id',input('get.apply_id'))->where('user_id',$this->user_id)->where('is_deleted',0)->find()->toArray();
- $apply_info['address_info'] = $apply_info['address_info'] ? json_decode($apply_info['address_info'],true):null;
- $this->success('ok',['detail'=>$apply_info]);
- }
- }
|