Company.php 13 KB

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