Bill.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\common\model\BillApply;
  16. use app\common\model\BillHeader;
  17. use app\common\model\BillType;
  18. use app\common\service\UserSynth;
  19. use app\common\validate\BillVali;
  20. /**
  21. * @title 发票模块【二期】
  22. * @controller Bill
  23. */
  24. class Bill extends Base
  25. {
  26. protected $need_login = [
  27. 'selBillHeader',
  28. 'getHeaderList',
  29. 'getBillHeaderDetail',
  30. 'delBillHeader',
  31. 'billApply',
  32. 'getApplyList',
  33. 'getApplyInfo',
  34. ];
  35. public function initialize()
  36. {
  37. parent::initialize();
  38. parent::setUid();
  39. }
  40. /**
  41. * @title 获取发票类型
  42. * @desc 获取发票类型
  43. * @author qc
  44. * @url /api/Bill/getBillType
  45. * @method GET
  46. * @header name:Authorization require:1 desc:Token
  47. * @return name:id type:int default:-- desc:id
  48. * @return name:title type:string default:0 desc:名称
  49. */
  50. public function getBillType()
  51. {
  52. $list = BillType::getType();
  53. $this->success('ok',['list'=>$list]);
  54. }
  55. /**
  56. * @title 设置发票抬头
  57. * @desc 设置发票抬头
  58. * @author qc
  59. * @url /api/Bill/selBillHeader
  60. * @method POST
  61. * @header name:Authorization require:1 desc:Token
  62. * @param name:id type:int default:-- desc:id【修改传记录id,新增忽略】
  63. * @param name:type type:int default:0 desc:类型id
  64. * @param name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
  65. * @param name:identify_number type:string default:0 desc:纳税人识别号
  66. * @param name:email type:string default:0 desc:邮箱
  67. */
  68. public function selBillHeader()
  69. {
  70. $param = input('post.');
  71. $validate = new BillVali();
  72. //if (!$validate->check($param)) $this->error($validate->getError());
  73. $param['user_id'] = $this->user_id;
  74. if(isset($param['id']) && $param['id']) {
  75. BillHeader::where('id',$param['id'])->update($param);
  76. }else{
  77. BillHeader::create($param);
  78. }
  79. $this->success('编辑成功');
  80. }
  81. /**
  82. * @title 获取发票抬头列表
  83. * @desc 获取发票抬头列表
  84. * @author qc
  85. * @url /api/Bill/getHeaderList
  86. * @method GET
  87. * @header name:Authorization require:1 desc:Token
  88. * @param name:page type:int default:0 desc:页数
  89. * @param name:page_num type:int default:20 desc:每页数
  90. * @return name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
  91. * @return name:identify_number type:string default:0 desc:纳税人识别号
  92. * @return name:email type:string default:0 desc:邮箱
  93. */
  94. public function getHeaderList()
  95. {
  96. $sel_where=[];
  97. $sel_where['b.user_id'] = $this->user_id;
  98. $sel_where['b.is_deleted'] = 0;
  99. $list = BillHeader::field('b.id,b.header,b.identify_number,b.email')
  100. ->alias('b')
  101. ->where($sel_where)
  102. ->order('b.id desc')
  103. ->limit($this->off_set,$this->page_num)
  104. ->select()->toArray();
  105. $total_num = BillHeader::alias('b')->where($sel_where)->count();
  106. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  107. }
  108. /**
  109. * @title 获取发票抬头详情
  110. * @desc 详情
  111. * @author qc
  112. * @url /api/Bill/getBillHeaderDetail
  113. * @method GET
  114. * @header name:Authorization require:1 desc:Token
  115. * @param name:id type:int default:0 desc:发票记录id
  116. * @return name:header type:string default:0 desc:抬头名称[公司名称||个人名称]
  117. * @return name:identify_number type:string default:0 desc:纳税人识别号
  118. */
  119. public function getBillHeaderDetail()
  120. {
  121. $sel_where=[];
  122. $sel_where['b.user_id'] = $this->user_id;
  123. $sel_where['b.is_deleted'] = 0;
  124. if(!input('get.id'))$this->error('参数错误');
  125. $sel_where['b.id'] = input('get.id');
  126. $detail = BillHeader::field('b.id,b.header,b.identify_number')->where($sel_where)->find();
  127. if(!$detail) $this->error('没查到改记录');
  128. $this->success('ok',['detail'=>$detail->toArray()]);
  129. }
  130. /**
  131. * @title 删除发票抬头记录
  132. * @desc 删除发票抬头记录
  133. * @author qc
  134. * @url /api/Bill/delBillHeader
  135. * @method POST
  136. * @header name:Authorization require:1 desc:Token
  137. * @param name:id type:int default:0 desc:发票记录id
  138. */
  139. public function delBillHeader()
  140. {
  141. BillHeader::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  142. $this->success('删除成功');
  143. }
  144. /**
  145. * @title 申请开票
  146. * @desc 申请开票
  147. * @author qc
  148. * @url /api/Bill/billApply
  149. * @method POST
  150. * @header name:Authorization require:1 desc:Token
  151. * @param name:order_id type:int default:0 desc:订单id
  152. * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
  153. * @param name:header_id type:int default:0 desc:抬头id
  154. * @param name:send_type type:int default:1 desc:申请类型【1点子发票2纸质发票】
  155. * @param name:add_id type:int default:0 desc:售货地址id【点子发票忽略】
  156. * @param name:remark type:string default:0 desc:备注
  157. */
  158. public function billApply()
  159. {
  160. $this->error('接口停用');
  161. $order_id= input('post.order_id');
  162. $order_type = input('post.order_type');
  163. $header_id= input('post.header_id');
  164. $send_type= input('post.send_type');
  165. $add_id = input('post.add_id');
  166. $remark = input('post.remark');
  167. if($send_type == 2 && !$add_id) $this->error('请选择售货地址');
  168. $ret_val = UserSynth::buildBillApply($this->user_id, $order_id, $order_type,$header_id,$add_id,$send_type,$remark);
  169. $ret_val['code'] == 200 ? $this->success($ret_val['msg']) : $this->error($ret_val['msg']);
  170. }
  171. /**
  172. * @title 取消开票【删除开票】
  173. * @desc 取消开票【删除开票】
  174. * @author qc
  175. * @url /api/Bill/delApply
  176. * @method POST
  177. * @header name:Authorization require:1 desc:Token
  178. * @param name:apply_id type:int default:0 desc:开票记录id【传这个值时,order_id和type可以为空】
  179. * @param name:order_id type:int default:0 desc:订单id【apply_id为空时必传】
  180. * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】【apply_id为空时必传】
  181. */
  182. public function delApply()
  183. {
  184. $apply_info = BillApply::where(input('post.'))->where('user_id',$this->user_id)->where('is_deleted',0)->find();
  185. if(empty($apply_info)) $this->error('申请记录有误');
  186. $apply_info->is_deleted = 1;
  187. $apply_info->save();
  188. $this->success('取消成功');
  189. }
  190. /**
  191. * @title 获取申请发票列表
  192. * @desc 获取申请发票列表
  193. * @author qc
  194. * @url /api/Bill/getApplyList
  195. * @method GET
  196. * @header name:Authorization require:1 desc:Token
  197. * @param name:page type:int default:0 desc:页数
  198. * @param name:page_num type:int default:20 desc:每页数
  199. * @return name:header type:string default:0 desc:抬头
  200. * @return name:type type:int default:0 desc:发票类型
  201. * @return name:email type:string default:0 desc:邮箱
  202. * @return name:phone type:string default:0 desc:电话
  203. * @return name:bank type:string default:0 desc:开户行
  204. * @return name:card_no type:string default:0 desc:银行账号
  205. * @return name:identify_number type:string default:0 desc:纳税人识别号
  206. * @return name:bill_img type:string default:0 desc:点子发票url
  207. * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
  208. * @return name:remark type:string default:0 desc:备注
  209. * @return name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
  210. * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
  211. * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
  212. * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
  213. * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
  214. * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
  215. */
  216. public function getApplyList()
  217. {
  218. $sel_where=[];
  219. $sel_where['user_id'] = $this->user_id;
  220. $sel_where['is_deleted'] = 0;
  221. $list = BillApply::where($sel_where)
  222. ->order('create_at desc')
  223. ->limit($this->off_set,$this->page_num)
  224. ->select()->toArray();
  225. array_map(function (&$val){
  226. $val['address_info'] = $val['address_info'] ? json_decode($val['address_info'],true):null;
  227. },$list);
  228. $this->success('ok',['list'=>$list]);
  229. }
  230. /**
  231. * @title 获取开票详情
  232. * @desc 获取开票详情
  233. * @author qc
  234. * @url /api/Bill/getApplyInfo
  235. * @method GET
  236. * @header name:Authorization require:1 desc:Token
  237. * @param name:apply_id type:int default:0 desc:开票记录id【传这个值时,order_id和type可以为空】
  238. * @param name:order_id type:int default:0 desc:订单id【apply_id为空时必传】
  239. * @param name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】【apply_id为空时必传】
  240. *
  241. * @return name:header type:string default:0 desc:抬头
  242. * @return name:type type:int default:0 desc:发票类型
  243. * @return name:email type:string default:0 desc:邮箱
  244. * @return name:phone type:string default:0 desc:电话
  245. * @return name:bank type:string default:0 desc:开户行
  246. * @return name:card_no type:string default:0 desc:银行账号
  247. * @return name:identify_number type:string default:0 desc:纳税人识别号
  248. * @return name:bill_img type:string default:0 desc:点子发票url
  249. * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
  250. * @return name:remark type:string default:0 desc:备注
  251. * @return name:order_type type:int default:0 desc:订单类型【1会员订单,2商城商品订单,3活动报名】
  252. * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
  253. * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
  254. * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
  255. * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
  256. * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
  257. */
  258. public function getApplyInfo()
  259. {
  260. $apply_info = BillApply::where('id',input('get.apply_id'))->where('user_id',$this->user_id)->where('is_deleted',0)->find()->toArray();
  261. $apply_info['address_info'] = $apply_info['address_info'] ? json_decode($apply_info['address_info'],true):null;
  262. $this->success('ok',['detail'=>$apply_info]);
  263. }
  264. }