Company.php 13 KB

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