Company.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\OcrTotal;use think\App;
  5. use think\facade\Config;use think\facade\Db;
  6. class Company extends Base
  7. {
  8. protected $invoiceType;
  9. public function __construct(App $app) {
  10. parent::__construct($app);
  11. $invoice =Config::get("invoiceType");
  12. $this->invoiceType = $invoice['invoiceType'];
  13. }
  14. /**
  15. * 显示资源列表
  16. *
  17. * @return \think\Response
  18. */
  19. public function Info()
  20. {
  21. $post =$this->post;
  22. if($this->level==1){
  23. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  24. }else{
  25. $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  26. }
  27. if($companyNo==""){
  28. return error_show(1004,"参数companyNo 不能为空");
  29. }
  30. $company = Db::name("company_info")->where("companyNo","=",$companyNo)->find();
  31. if(empty($company)){
  32. return error_show(1004,"未找到对应的数据");
  33. }
  34. return app_show(0,"获取成功",$company);
  35. }
  36. /**
  37. * 显示创建资源表单页.
  38. *
  39. * @return \think\Response
  40. */
  41. public function create()
  42. {
  43. $post =$this->post;
  44. if($this->level==1){
  45. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  46. }else{
  47. $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  48. }
  49. if($companyNo==""){
  50. return error_show(1004,"参数companyNo 不能为空");
  51. }
  52. $supplierinfo =Db::name("supplier_info")->where(["code"=>$companyNo])->findOrEmpty();
  53. if(empty($supplierinfo)){
  54. return error_show(1004,"未找到企业信息");
  55. }
  56. $isIn =Db::name("company_info")->where(["companyNo"=>$companyNo,"is_del"=>0])->findOrEmpty();
  57. if(!empty($isIn))return error_show(1004,"财务信息已存在!");
  58. $name = isset($post['company_name'])&&$post['company_name']!="" ? trim($post['company_name']) :"";
  59. if($name==""){
  60. return error_show(1004,"参数company_name 不能为空");
  61. }
  62. $title = isset($post['company_license'])&&$post['company_license']!="" ? trim($post['company_license']) :"";
  63. if($title==""){
  64. return error_show(1004,"参数company_license 不能为空");
  65. }
  66. $bank = isset($post['bank_name'])&&$post['bank_name']!="" ? trim($post['bank_name']) :"";
  67. if($bank==""){
  68. return error_show(1004,"参数bank_name 不能为空");
  69. }
  70. $bankNo = isset($post['bankNo'])&&$post['bankNo']!="" ? trim($post['bankNo']) :"";
  71. if($bankNo==""){
  72. return error_show(1004,"参数bankNo 不能为空");
  73. }
  74. // $is_bank = Db::name("company_info")->where([["bankNo","=",$bankNo],["status","=",1]])->find();
  75. // if(!empty($is_bank)){
  76. // return error_show(1004,"银行卡号已存在!");
  77. // }
  78. $address = isset($post['company_address'])&&$post['company_address']!="" ? trim($post['company_address']) :"";
  79. if($address==""){
  80. return error_show(1004,"参数company_address 不能为空");
  81. }
  82. $contector = isset($post['contector'])&&$post['contector']!="" ? trim($post['contector']) :"";
  83. $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
  84. $img = isset($post['company_img'])&&$post['company_img']!="" ? trim($post['company_img']) :"";
  85. if($mobile!=""){
  86. if(!checkTel($mobile)&&!checkMobile($mobile)){
  87. return error_show(1004,"手机号/电话格式不正确");
  88. }
  89. }
  90. $inputTicket = isset($post['input_ticket'])&&$post['input_ticket']!="" ? intval($post['input_ticket']) :"0";
  91. if($inputTicket==""){
  92. return error_show(1004,"进项票未设置验票方式");
  93. }
  94. $outTicket = isset($post['out_ticket'])&&$post['out_ticket']!="" ? intval($post['out_ticket']) :"0";
  95. if($outTicket==""){
  96. return error_show(1004,"销项票未设置验票方式");
  97. }
  98. $voider = isset($post['voider'])&&$post['voider']!="" ? trim($post['voider']) :"";
  99. $payee = isset($post['payee'])&&$post['payee']!="" ? trim($post['payee']) :"";
  100. $drawer = isset($post['drawer'])&&$post['drawer']!="" ? trim($post['drawer']) :"";
  101. $reviewer = isset($post['reviewer'])&&$post['reviewer']!="" ? trim($post['reviewer']) :"";
  102. $ownerPlace = isset($post['ownerPlace'])&&$post['ownerPlace']!="" ? trim($post['ownerPlace']) :"";
  103. $denomination = isset($post['denomination'])&&$post['denomination']!="" ? trim($post['denomination']) :"";
  104. $invoiceType = isset($post['invoiceType'])&&!empty($post['invoiceType']) ? $post['invoiceType']:"";
  105. if($invoiceType!=''&& !empty(array_diff($invoiceType,$this->invoiceType))) return error_show(1004,"存在无效发票类型");
  106. $data = [
  107. "companyNo"=>$companyNo,
  108. "company_name"=>$name,
  109. "company_address"=>$address,
  110. "company_license"=>$title,
  111. "bank_name"=>$bank,
  112. "bankNo"=>$bankNo,
  113. "contector"=>$contector,
  114. "mobile"=>$mobile,
  115. "company_img"=>$img,
  116. "input_ticket"=>$inputTicket,
  117. "out_ticket"=>$outTicket,
  118. "voider"=>$voider,
  119. "payee"=>$payee,
  120. "drawer"=>$drawer,
  121. "reviewer"=>$reviewer,
  122. "ownerPlace"=>$ownerPlace,
  123. "denomination"=>$denomination,
  124. "invoiceType"=>$invoiceType!=''|| empty($invoiceType)?implode(",",$invoiceType):"",
  125. "status"=>1,
  126. "addtime"=>date("Y-m-d H:i:s"),
  127. "updatetime"=>date("Y-m-d H:i:s")
  128. ];
  129. $result = Db::name("company_info")->insert($data);
  130. return $result? app_show(0,"新建成功",["companyNo"=>$companyNo]):error_show(1005,"新建失败");
  131. }
  132. /**
  133. * 保存新建的资源
  134. *
  135. * @param \think\Request $request
  136. * @return \think\Response
  137. */
  138. public function save()
  139. {
  140. $post =$this->post;
  141. if($this->level==1){
  142. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  143. }else{
  144. $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  145. }
  146. if($companyNo==""){
  147. return error_show(1004,"参数companyNo 不能为空");
  148. }
  149. $name = isset($post['company_name'])&&$post['company_name']!="" ? trim($post['company_name']) :"";
  150. if($name==""){
  151. return error_show(1004,"参数company_name 不能为空");
  152. }
  153. $title = isset($post['company_license'])&&$post['company_license']!="" ? trim($post['company_license']) :"";
  154. if($title==""){
  155. return error_show(1004,"参数company_license 不能为空");
  156. }
  157. $bank = isset($post['bank_name'])&&$post['bank_name']!="" ? trim($post['bank_name']) :"";
  158. if($bank==""){
  159. return error_show(1004,"参数bank_name 不能为空");
  160. }
  161. $bankNo = isset($post['bankNo'])&&$post['bankNo']!="" ? trim($post['bankNo']) :"";
  162. if($bankNo==""){
  163. return error_show(1004,"参数bankNo 不能为空");
  164. }
  165. $address = isset($post['company_address'])&&$post['company_address']!="" ? trim($post['company_address']) :"";
  166. $contector = isset($post['contector'])&&$post['contector']!="" ? trim($post['contector']) :"";
  167. $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
  168. $img = isset($post['company_img'])&&$post['company_img']!="" ? trim($post['company_img']) :"";
  169. if($mobile!=""){
  170. if(!checkTel($mobile)&&!checkMobile($mobile)){
  171. return error_show(1004,"手机号/电话格式不正确");
  172. }
  173. }
  174. $inputTicket = isset($post['input_ticket'])&&$post['input_ticket']!="" ? intval($post['input_ticket']) :"0";
  175. if($inputTicket==""){
  176. return error_show(1004,"进项票未设置验票方式");
  177. }
  178. $outTicket = isset($post['out_ticket'])&&$post['out_ticket']!="" ? intval($post['out_ticket']) :"0";
  179. if($outTicket==""){
  180. return error_show(1004,"销项票未设置验票方式");
  181. }
  182. $voider = isset($post['voider'])&&$post['voider']!="" ? trim($post['voider']) :"";
  183. $payee = isset($post['payee'])&&$post['payee']!="" ? trim($post['payee']) :"";
  184. $drawer = isset($post['drawer'])&&$post['drawer']!="" ? trim($post['drawer']) :"";
  185. $reviewer = isset($post['reviewer'])&&$post['reviewer']!="" ? trim($post['reviewer']) :"";
  186. $ownerPlace = isset($post['ownerPlace'])&&$post['ownerPlace']!="" ? trim($post['ownerPlace']) :"";
  187. $denomination = isset($post['denomination'])&&$post['denomination']!="" ? trim($post['denomination']) :"";
  188. $invoiceType = isset($post['invoiceType'])&&!empty($post['invoiceType']) ? $post['invoiceType']:[];
  189. if(($invoiceType!=''|| !empty($invoiceType))&& !empty(array_diff(array_filter($invoiceType),$this->invoiceType)))
  190. return error_show(1004,"存在无效发票类型");
  191. $data = [
  192. "company_name"=>$name,
  193. "company_address"=>$address,
  194. "company_license"=>$title,
  195. "bank_name"=>$bank,
  196. "bankNo"=>$bankNo,
  197. "contector"=>$contector,
  198. "mobile"=>$mobile,
  199. "company_img"=>$img,
  200. "input_ticket"=>$inputTicket,
  201. "out_ticket"=>$outTicket,
  202. "voider"=>$voider,
  203. "payee"=>$payee,
  204. "drawer"=>$drawer,
  205. "reviewer"=>$reviewer,
  206. "ownerPlace"=>$ownerPlace,
  207. "denomination"=>$denomination,
  208. "invoiceType"=>$invoiceType!=''|| !empty($invoiceType)?implode(",",array_filter($invoiceType)):"",
  209. "updatetime"=>date("Y-m-d H:i:s")
  210. ];
  211. $result = Db::name("company_info")->where("companyNo","=",$companyNo)->update($data);
  212. return $result? app_show(0,"更新成功"):error_show(1005,"更新失败");
  213. }
  214. /**
  215. * 显示指定的资源
  216. *
  217. * @param int $id
  218. * @return \think\Response
  219. */
  220. public function status()
  221. {
  222. $post =$this->post;
  223. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  224. if($companyNo==""){
  225. return error_show(1004,"参数companyNo 不能为空");
  226. }
  227. $info = Db::name("company_info")
  228. ->where(['is_del' => 0, 'companyNo' => $companyNo])
  229. ->findOrEmpty();
  230. if(empty($info)) return error_show(1004,'该记录不存在');
  231. $status = isset($post['status'])&&$post['status']!="" ? trim($post['status']) :"";
  232. if($status==""){
  233. return error_show(1004,"参数status 不能为空");
  234. }
  235. if(!in_array($status,[0,1])){
  236. return error_show(1004,"参数status 无效");
  237. }
  238. if (($status == 1) && (!in_array($info['input_ticket'], [1, 2]) || !in_array($info['out_ticket'], [1, 2]))) return error_show(1004, '未设置查票字段,无法启用');
  239. $message = $status==1 ?"启用" :"禁用";
  240. $data = [
  241. "status"=>$status,
  242. "updatetime"=>date("Y-m-d H:i:s")
  243. ];
  244. $result = Db::name("company_info")->where("companyNo","=",$companyNo)->update($data);
  245. return $result? app_show(0,"{$message}成功"):error_show(1005,"{$message}失败");
  246. }
  247. /**
  248. * 显示编辑资源表单页.
  249. *
  250. * @param int $id
  251. * @return \think\Response
  252. */
  253. public function list()
  254. {
  255. $post =$this->post;
  256. $condition = [["is_del","=",0]];
  257. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  258. if($companyNo!=""){
  259. $condition[]=['a.companyNo',"=",$companyNo];
  260. }
  261. $relaComNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  262. if($relaComNo!="") $condition[]=['a.companyNo',"=",$relaComNo];
  263. $company_name = isset($post['company_name']) && $post['company_name'] != "" ? trim($post['company_name']) : "";
  264. if ($company_name != "") {
  265. $condition[] = ['a.company_name', "like", "%$company_name%"];
  266. }
  267. $status = isset($post['status'])&&$post['status']!=="" ? intval($post['status']) :"";
  268. if($status!==""){
  269. $condition[]=['a.status',"=",$status];
  270. }
  271. $page = isset($post['page'])&& $post['page']!="" ? intval($post['page']) :1;
  272. $size = isset($post['size'])&& $post['size']!="" ? intval($post['size']) :10;
  273. $count = Db::name("company_info")
  274. ->alias("a")
  275. // ->leftJoin("supplier_info b", "a.companyNo=b.code")
  276. ->where($condition)
  277. ->count();
  278. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  279. $page = $page >= $total ? intval($total) : $page;
  280. $list = Db::name("company_info")
  281. ->alias("a")
  282. // ->leftJoin("supplier_info b", "a.companyNo=b.code")
  283. ->where($condition)
  284. ->page($page, $size)
  285. ->order("id desc")
  286. ->select()
  287. ->toArray();
  288. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  289. }
  290. /**
  291. * 保存更新的资源
  292. *
  293. * @param \think\Request $request
  294. * @param int $id
  295. * @return \think\Response
  296. */
  297. public function all()
  298. {
  299. $post =$this->post;
  300. $condition = [["is_del","=",0]];
  301. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  302. if($companyNo!=""){
  303. $condition[]=['companyNo',"=",$companyNo];
  304. }
  305. $companyName = isset($post['companyName'])&&$post['companyName']!="" ? trim($post['companyName']) :"";
  306. if($companyName!=""){
  307. $condition[]=['company_name',"like","%$companyName%"];
  308. }
  309. $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();
  310. return app_show(0,"获取成功",$list);
  311. }
  312. /** 获取利率设置
  313. * @return \think\response\Json|void
  314. * @throws \think\db\exception\DataNotFoundException
  315. * @throws \think\db\exception\DbException
  316. * @throws \think\db\exception\ModelNotFoundException
  317. */
  318. public function RateList(){
  319. $list=Db::name("order_rate")->where("status","=",1)->select();
  320. return app_show(0,"获取成功",$list);
  321. }
  322. /** 获取OCR统计
  323. * @return \think\response\Json|void
  324. * @throws \think\db\exception\DataNotFoundException
  325. * @throws \think\db\exception\ModelNotFoundException
  326. * @throws \think\exception\DbException
  327. */
  328. public function OcrTotalList(){
  329. $param=$this->request->param(["page"=>1,"size"=>10,"start"=>"","end"=>"","companyNo"=>""],"post","trim");
  330. $where=[];
  331. if($param["companyNo"]!=""){
  332. $where[]=["companyNo","like","%".$param["companyNo"]."%"];
  333. }
  334. if($param["start"]!=""&&$param["end"]!=""){
  335. $where[]=["daydate","between",[startTime($param['start']),endTime($param["end"])]];
  336. }
  337. $list = OcrTotal::where($where)->order('daydate desc')
  338. ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
  339. return app_show(0, '获取成功', ['list'=>$list->items(),'count'=>$list->total()]);
  340. }
  341. }