Company.php 12 KB

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