Company.php 14 KB

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