123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\OcrTotal;use think\App;
- use think\facade\Config;use think\facade\Db;
- class Company extends Base
- {
- protected $invoiceType;
- public function __construct(App $app) {
- parent::__construct($app);
- $invoice =Config::get("invoiceType");
- $this->invoiceType = $invoice['invoiceType'];
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function Info()
- {
- $post =$this->post;
- if($this->level==1){
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- }else{
- $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- }
- if($companyNo==""){
- return error_show(1004,"参数companyNo 不能为空");
- }
- $company = Db::name("company_info")->where("companyNo","=",$companyNo)->find();
- if(empty($company)){
- return error_show(1004,"未找到对应的数据");
- }
- return app_show(0,"获取成功",$company);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $post =$this->post;
- if($this->level==1){
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- }else{
- $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- }
- if($companyNo==""){
- return error_show(1004,"参数companyNo 不能为空");
- }
- $supplierinfo =Db::name("supplier_info")->where(["code"=>$companyNo])->findOrEmpty();
- if(empty($supplierinfo)){
- return error_show(1004,"未找到企业信息");
- }
- $isIn =Db::name("company_info")->where(["companyNo"=>$companyNo,"is_del"=>0])->findOrEmpty();
- if(!empty($isIn))return error_show(1004,"财务信息已存在!");
- $name = isset($post['company_name'])&&$post['company_name']!="" ? trim($post['company_name']) :"";
- if($name==""){
- return error_show(1004,"参数company_name 不能为空");
- }
- $title = isset($post['company_license'])&&$post['company_license']!="" ? trim($post['company_license']) :"";
- if($title==""){
- return error_show(1004,"参数company_license 不能为空");
- }
- $bank = isset($post['bank_name'])&&$post['bank_name']!="" ? trim($post['bank_name']) :"";
- if($bank==""){
- return error_show(1004,"参数bank_name 不能为空");
- }
- $bankNo = isset($post['bankNo'])&&$post['bankNo']!="" ? trim($post['bankNo']) :"";
- if($bankNo==""){
- return error_show(1004,"参数bankNo 不能为空");
- }
- // $is_bank = Db::name("company_info")->where([["bankNo","=",$bankNo],["status","=",1]])->find();
- // if(!empty($is_bank)){
- // return error_show(1004,"银行卡号已存在!");
- // }
- $address = isset($post['company_address'])&&$post['company_address']!="" ? trim($post['company_address']) :"";
- if($address==""){
- return error_show(1004,"参数company_address 不能为空");
- }
- $contector = isset($post['contector'])&&$post['contector']!="" ? trim($post['contector']) :"";
- $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
- $img = isset($post['company_img'])&&$post['company_img']!="" ? trim($post['company_img']) :"";
- if($mobile!=""){
- if(!checkTel($mobile)&&!checkMobile($mobile)){
- return error_show(1004,"手机号/电话格式不正确");
- }
- }
- $inputTicket = isset($post['input_ticket'])&&$post['input_ticket']!="" ? intval($post['input_ticket']) :"0";
- if($inputTicket==""){
- return error_show(1004,"进项票未设置验票方式");
- }
- $outTicket = isset($post['out_ticket'])&&$post['out_ticket']!="" ? intval($post['out_ticket']) :"0";
- if($outTicket==""){
- return error_show(1004,"销项票未设置验票方式");
- }
- $voider = isset($post['voider'])&&$post['voider']!="" ? trim($post['voider']) :"";
- $payee = isset($post['payee'])&&$post['payee']!="" ? trim($post['payee']) :"";
- $drawer = isset($post['drawer'])&&$post['drawer']!="" ? trim($post['drawer']) :"";
- $reviewer = isset($post['reviewer'])&&$post['reviewer']!="" ? trim($post['reviewer']) :"";
- $ownerPlace = isset($post['ownerPlace'])&&$post['ownerPlace']!="" ? trim($post['ownerPlace']) :"";
- $denomination = isset($post['denomination'])&&$post['denomination']!="" ? trim($post['denomination']) :"";
- $invoiceType = isset($post['invoiceType'])&&!empty($post['invoiceType']) ? $post['invoiceType']:"";
- if($invoiceType!=''&& !empty(array_diff($invoiceType,$this->invoiceType))) return error_show(1004,"存在无效发票类型");
- $data = [
- "companyNo"=>$companyNo,
- "company_name"=>$name,
- "company_address"=>$address,
- "company_license"=>$title,
- "bank_name"=>$bank,
- "bankNo"=>$bankNo,
- "contector"=>$contector,
- "mobile"=>$mobile,
- "company_img"=>$img,
- "input_ticket"=>$inputTicket,
- "out_ticket"=>$outTicket,
- "voider"=>$voider,
- "payee"=>$payee,
- "drawer"=>$drawer,
- "reviewer"=>$reviewer,
- "ownerPlace"=>$ownerPlace,
- "denomination"=>$denomination,
- "invoiceType"=>$invoiceType!=''|| empty($invoiceType)?implode(",",$invoiceType):"",
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $result = Db::name("company_info")->insert($data);
- return $result? app_show(0,"新建成功",["companyNo"=>$companyNo]):error_show(1005,"新建失败");
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save()
- {
- $post =$this->post;
- if($this->level==1){
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- }else{
- $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- }
- if($companyNo==""){
- return error_show(1004,"参数companyNo 不能为空");
- }
- $name = isset($post['company_name'])&&$post['company_name']!="" ? trim($post['company_name']) :"";
- if($name==""){
- return error_show(1004,"参数company_name 不能为空");
- }
- $title = isset($post['company_license'])&&$post['company_license']!="" ? trim($post['company_license']) :"";
- if($title==""){
- return error_show(1004,"参数company_license 不能为空");
- }
- $bank = isset($post['bank_name'])&&$post['bank_name']!="" ? trim($post['bank_name']) :"";
- if($bank==""){
- return error_show(1004,"参数bank_name 不能为空");
- }
- $bankNo = isset($post['bankNo'])&&$post['bankNo']!="" ? trim($post['bankNo']) :"";
- if($bankNo==""){
- return error_show(1004,"参数bankNo 不能为空");
- }
- $address = isset($post['company_address'])&&$post['company_address']!="" ? trim($post['company_address']) :"";
- $contector = isset($post['contector'])&&$post['contector']!="" ? trim($post['contector']) :"";
- $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
- $img = isset($post['company_img'])&&$post['company_img']!="" ? trim($post['company_img']) :"";
- if($mobile!=""){
- if(!checkTel($mobile)&&!checkMobile($mobile)){
- return error_show(1004,"手机号/电话格式不正确");
- }
- }
- $inputTicket = isset($post['input_ticket'])&&$post['input_ticket']!="" ? intval($post['input_ticket']) :"0";
- if($inputTicket==""){
- return error_show(1004,"进项票未设置验票方式");
- }
- $outTicket = isset($post['out_ticket'])&&$post['out_ticket']!="" ? intval($post['out_ticket']) :"0";
- if($outTicket==""){
- return error_show(1004,"销项票未设置验票方式");
- }
- $voider = isset($post['voider'])&&$post['voider']!="" ? trim($post['voider']) :"";
- $payee = isset($post['payee'])&&$post['payee']!="" ? trim($post['payee']) :"";
- $drawer = isset($post['drawer'])&&$post['drawer']!="" ? trim($post['drawer']) :"";
- $reviewer = isset($post['reviewer'])&&$post['reviewer']!="" ? trim($post['reviewer']) :"";
- $ownerPlace = isset($post['ownerPlace'])&&$post['ownerPlace']!="" ? trim($post['ownerPlace']) :"";
- $denomination = isset($post['denomination'])&&$post['denomination']!="" ? trim($post['denomination']) :"";
- $invoiceType = isset($post['invoiceType'])&&!empty($post['invoiceType']) ? $post['invoiceType']:[];
- if(($invoiceType!=''|| !empty($invoiceType))&& !empty(array_diff(array_filter($invoiceType),$this->invoiceType)))
- return error_show(1004,"存在无效发票类型");
- $data = [
- "company_name"=>$name,
- "company_address"=>$address,
- "company_license"=>$title,
- "bank_name"=>$bank,
- "bankNo"=>$bankNo,
- "contector"=>$contector,
- "mobile"=>$mobile,
- "company_img"=>$img,
- "input_ticket"=>$inputTicket,
- "out_ticket"=>$outTicket,
- "voider"=>$voider,
- "payee"=>$payee,
- "drawer"=>$drawer,
- "reviewer"=>$reviewer,
- "ownerPlace"=>$ownerPlace,
- "denomination"=>$denomination,
- "invoiceType"=>$invoiceType!=''|| !empty($invoiceType)?implode(",",array_filter($invoiceType)):"",
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $result = Db::name("company_info")->where("companyNo","=",$companyNo)->update($data);
- return $result? app_show(0,"更新成功"):error_show(1005,"更新失败");
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function status()
- {
- $post =$this->post;
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- if($companyNo==""){
- return error_show(1004,"参数companyNo 不能为空");
- }
- $info = Db::name("company_info")
- ->where(['is_del' => 0, 'companyNo' => $companyNo])
- ->findOrEmpty();
- if(empty($info)) return error_show(1004,'该记录不存在');
- $status = isset($post['status'])&&$post['status']!="" ? trim($post['status']) :"";
- if($status==""){
- return error_show(1004,"参数status 不能为空");
- }
- if(!in_array($status,[0,1])){
- return error_show(1004,"参数status 无效");
- }
- if (($status == 1) && (!in_array($info['input_ticket'], [1, 2]) || !in_array($info['out_ticket'], [1, 2]))) return error_show(1004, '未设置查票字段,无法启用');
- $message = $status==1 ?"启用" :"禁用";
- $data = [
- "status"=>$status,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $result = Db::name("company_info")->where("companyNo","=",$companyNo)->update($data);
- return $result? app_show(0,"{$message}成功"):error_show(1005,"{$message}失败");
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function list()
- {
- $post =$this->post;
- $condition = [["is_del","=",0]];
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- if($companyNo!=""){
- $condition[]=['a.companyNo',"=",$companyNo];
- }
- $relaComNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!="") $condition[]=['a.companyNo',"=",$relaComNo];
- $company_name = isset($post['company_name']) && $post['company_name'] != "" ? trim($post['company_name']) : "";
- if ($company_name != "") {
- $condition[] = ['a.company_name', "like", "%$company_name%"];
- }
- $status = isset($post['status'])&&$post['status']!=="" ? intval($post['status']) :"";
- if($status!==""){
- $condition[]=['a.status',"=",$status];
- }
- $page = isset($post['page'])&& $post['page']!="" ? intval($post['page']) :1;
- $size = isset($post['size'])&& $post['size']!="" ? intval($post['size']) :10;
- $count = Db::name("company_info")
- ->alias("a")
- // ->leftJoin("supplier_info b", "a.companyNo=b.code")
- ->where($condition)
- ->count();
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("company_info")
- ->alias("a")
- // ->leftJoin("supplier_info b", "a.companyNo=b.code")
- ->where($condition)
- ->page($page, $size)
- ->order("id desc")
- ->select()
- ->toArray();
- return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function all()
- {
- $post =$this->post;
- $condition = [["is_del","=",0]];
- $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
- if($companyNo!=""){
- $condition[]=['companyNo',"=",$companyNo];
- }
- $companyName = isset($post['companyName'])&&$post['companyName']!="" ? trim($post['companyName']) :"";
- if($companyName!=""){
- $condition[]=['company_name',"like","%$companyName%"];
- }
- $list = Db::name("company_info")->where($condition)->field("companyNo,company_name,status,bank_name,bankNo,company_license,LENGTH('company_name') as weight")->order("weight asc")->select();
- return app_show(0,"获取成功",$list);
- }
- /** 获取利率设置
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function RateList(){
- $list=Db::name("order_rate")->where("status","=",1)->select();
- return app_show(0,"获取成功",$list);
- }
- /** 获取OCR统计
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function OcrTotalList(){
- $param=$this->request->param(["page"=>1,"size"=>10,"start"=>"","end"=>"","companyNo"=>""],"post","trim");
- $where=[];
- if($param["companyNo"]!=""){
- $where[]=["companyNo","like","%".$param["companyNo"]."%"];
- }
- if($param["start"]!=""&&$param["end"]!=""){
- $where[]=["daydate","between",[startTime($param['start']),endTime($param["end"])]];
- }
- $list = OcrTotal::where($where)->order('daydate desc')
- ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
- return app_show(0, '获取成功', ['list'=>$list->items(),'count'=>$list->total()]);
- }
- }
|