Business.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. use think\facade\Validate;
  7. //业务企业
  8. class Business extends Base
  9. {
  10. public function create()
  11. {
  12. $companyNo = makeNo("GS");
  13. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  14. if ($company == "") {
  15. return error_show(1002, "参数company不能为空");
  16. }
  17. $companyinfo = Db::name('business')->where(['is_del' => 0, 'company' => $company])->find();
  18. if (!empty($companyinfo)) {
  19. return error_show(1002, "企业公司名称已存在");
  20. }
  21. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  22. if ($type == "") {
  23. return error_show(1002, "参数type不能为空");
  24. }
  25. $inv_code = isset($this->post['inv_code']) && $this->post['inv_code'] !== "" ? trim($this->post['inv_code']) : "";
  26. if ($inv_code == "") {
  27. return error_show(1002, "参数inv_code不能为空");
  28. }
  29. $inv_legaler = isset($this->post['inv_legaler']) && $this->post['inv_legaler'] !== "" ? trim($this->post['inv_legaler']) : "";
  30. if ($inv_legaler == "") {
  31. return error_show(1002, "参数inv_legaler不能为空");
  32. }
  33. $inv_time = isset($this->post['inv_time']) && $this->post['inv_time'] !== "" ? $this->post['inv_time'] : "";
  34. if ($inv_time == "") {
  35. return error_show(1005, '参数inv_time不能为空');
  36. }
  37. $inv_addr = isset($this->post['inv_addr']) && $this->post['inv_addr'] !== "" ? trim($this->post['inv_addr']) : "";
  38. if ($inv_addr == "") {
  39. return error_show(1002, "参数inv_addr不能为空");
  40. }
  41. $inv_bank = isset($this->post['inv_bank']) && $this->post['inv_bank'] !== "" ? trim($this->post['inv_bank']) : "";
  42. if ($inv_bank == "") {
  43. return error_show(1002, "参数inv_bank不能为空");
  44. }
  45. $inv_bankNo = isset($this->post['inv_bankNo']) && $this->post['inv_bankNo'] !== "" ? trim($this->post['inv_bankNo']) : "";
  46. if ($inv_bankNo == "") {
  47. return error_show(1002, "参数inv_bankNo不能为空");
  48. }
  49. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  50. if ($contactor == "") {
  51. return error_show(1002, "参数contactor不能为空");
  52. }
  53. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  54. if ($mobile == "") {
  55. return error_show(1002, "参数mobile不能为空");
  56. }
  57. $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  58. if ($addr == "") {
  59. return error_show(1002, "参数addr不能为空");
  60. }
  61. $inv_scope = isset($this->post['inv_scope']) && $this->post['inv_scope'] !== "" ? trim($this->post['inv_scope']) : "";
  62. if ($inv_scope == "") {
  63. return error_show(1002, "参数inv_scope不能为空");
  64. }
  65. $license_img = isset($this->post['license_img']) && $this->post['license_img'] !== "" ? trim($this->post['license_img']) : "";
  66. // if($license_img==""){
  67. // return error_show(1002,"参数license_img不能为空");
  68. // }
  69. $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  70. if ($token == '') {
  71. return error_show(105, "参数token不能为空");
  72. }
  73. // $user =GetUserInfo($token);
  74. // if(empty($user)||$user['code']!=0){
  75. // return error_show(102,"创建人数据不存在");
  76. // }
  77. $createrid = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  78. $creater = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  79. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "1";
  80. // Db::startTrans();
  81. // try{
  82. $data = [
  83. "company" => $company,
  84. "companyNo" => $companyNo,
  85. "inv_code" => $inv_code,
  86. "type" => $type,
  87. "inv_legaler" => $inv_legaler,
  88. "inv_time" => $inv_time,
  89. "inv_addr" => $inv_addr,
  90. "inv_bank" => $inv_bank,
  91. "inv_bankNo" => $inv_bankNo,
  92. "contactor" => $contactor,
  93. "mobile" => $mobile,
  94. "addr" => $addr,
  95. "creater" => $creater,
  96. "createrid" => $createrid,
  97. "inv_scope" => $inv_scope,
  98. "license_img" => $license_img,
  99. "status" => $status,
  100. "is_del" => 0,
  101. "addtime" => date("Y-m-d H:i:s"),
  102. "updatetime" => date("Y-m-d H:i:s")
  103. ];
  104. $userCommon = new \app\admin\common\User();
  105. $rs = $userCommon->handle('bCreate', $data);
  106. return json_show($rs['code'], $rs['message'],$rs['data']);
  107. // $datainfo = Db::name('business')->insert($data);
  108. // if($datainfo){
  109. // Db::commit();
  110. // return error_show(0,"新建成功");
  111. // }else{
  112. // Db::rollback();
  113. // return error_show(1004,"新建失败");
  114. // }
  115. // }catch (\Exception $e) {
  116. // }
  117. // Db::rollback();
  118. // return error_show(1005, $e->getMessage());
  119. }
  120. public function list()
  121. {
  122. $param = $this->request->only([
  123. 'page' => 1,
  124. 'size' => 10,
  125. 'company' => '',
  126. 'status' => '',
  127. 'creater' => '',
  128. 'start' => '',
  129. 'end' => '',
  130. 'company_name' => '',
  131. ], 'post', 'trim');
  132. // $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  133. // $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  134. // $where = [["b.is_del","=",0]];
  135. // $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company']):"";
  136. // if($company!==""){
  137. // $where[]=['b.company',"like","%$company%"];
  138. // }
  139. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  140. // if($status!==""){
  141. // $where[]=['b.status',"=",$status];
  142. // }
  143. // $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  144. // if($creater!==""){
  145. // $where[]=['b.creater',"like","%$creater%"];
  146. // }
  147. // $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  148. // if($start!==""){
  149. // $where[]=['b.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  150. // }
  151. // $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  152. // if($end!==""){
  153. // $where[]=['b.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  154. // }
  155. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  156. // if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  157. $userCommon = new \app\admin\common\User();
  158. $rs = $userCommon->handle('bGetList', $param);
  159. return json_show($rs['code'], $rs['message'],$rs['data']);
  160. // $count = Db::name('business')
  161. // ->alias('b')
  162. // ->where($where)
  163. // ->count();
  164. // $total = ceil($count / $size);
  165. // $page = $page >= $total ? $total : $page;
  166. // $list = Db::name('business')
  167. // ->alias('b')
  168. // ->where($where)
  169. // ->page($page,$size)
  170. // ->field("b.id,b.company,b.companyNo,b.status,b.creater,b.addtime,b.type,u.itemid")
  171. // ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  172. // ->order("addtime desc")
  173. // ->append(['company_name'])
  174. // ->withAttr('company_name',function ($val,$data){
  175. // return implode('/', array_column(GetPart($data['itemid']), 'name'));
  176. // })
  177. // ->select()
  178. // ->toArray();
  179. //
  180. // return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  181. }
  182. public function edit()
  183. {
  184. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  185. if ($id == "") {
  186. return error_show(1002, "参数id不能为空");
  187. }
  188. // $idinfo = Db::name('business')->where(['id'=>$id,'is_del'=>0])->find();
  189. // if($idinfo==""){
  190. // return error_show(1003,"未找到数据");
  191. // }
  192. // $companyNo = makeNo("GS");
  193. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  194. if ($company == "") {
  195. return error_show(1002, "参数company不能为空");
  196. }
  197. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  198. if ($type == "") {
  199. return error_show(1002, "参数type不能为空");
  200. }
  201. $inv_code = isset($this->post['inv_code']) && $this->post['inv_code'] !== "" ? trim($this->post['inv_code']) : "";
  202. if ($inv_code == "") {
  203. return error_show(1002, "参数inv_code不能为空");
  204. }
  205. $inv_legaler = isset($this->post['inv_legaler']) && $this->post['inv_legaler'] !== "" ? trim($this->post['inv_legaler']) : "";
  206. if ($inv_legaler == "") {
  207. return error_show(1002, "参数inv_legaler不能为空");
  208. }
  209. $inv_time = isset($this->post['inv_time']) && $this->post['inv_time'] !== "" ? $this->post['inv_time'] : "";
  210. if ($inv_time == "") {
  211. return error_show(1005, '参数inv_time不能为空');
  212. }
  213. $inv_addr = isset($this->post['inv_addr']) && $this->post['inv_addr'] !== "" ? trim($this->post['inv_addr']) : "";
  214. if ($inv_addr == "") {
  215. return error_show(1002, "参数inv_addr不能为空");
  216. }
  217. $inv_bank = isset($this->post['inv_bank']) && $this->post['inv_bank'] !== "" ? trim($this->post['inv_bank']) : "";
  218. if ($inv_bank == "") {
  219. return error_show(1002, "参数inv_bank不能为空");
  220. }
  221. $inv_bankNo = isset($this->post['inv_bankNo']) && $this->post['inv_bankNo'] !== "" ? trim($this->post['inv_bankNo']) : "";
  222. if ($inv_bankNo == "") {
  223. return error_show(1002, "参数inv_bankNo不能为空");
  224. }
  225. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  226. if ($contactor == "") {
  227. return error_show(1002, "参数contactor不能为空");
  228. }
  229. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  230. if ($mobile == "") {
  231. return error_show(1002, "参数mobile不能为空");
  232. }
  233. $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  234. if ($addr == "") {
  235. return error_show(1002, "参数addr不能为空");
  236. }
  237. $inv_scope = isset($this->post['inv_scope']) && $this->post['inv_scope'] !== "" ? trim($this->post['inv_scope']) : "";
  238. if ($inv_scope == "") {
  239. return error_show(1002, "参数inv_scope不能为空");
  240. }
  241. $license_img = isset($this->post['license_img']) && $this->post['license_img'] !== "" ? trim($this->post['license_img']) : "";
  242. // if($license_img==""){
  243. // return error_show(1002,"参数license_img不能为空");
  244. // }
  245. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  246. // if($token==''){
  247. // return error_show(105,"参数token不能为空");
  248. // }
  249. // $user =GetUserInfo($token);
  250. // if(empty($user)||$user['code']!=0){
  251. // return error_show(102,"创建人数据不存在");
  252. // }
  253. $createrid = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  254. $creater = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  255. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  256. // Db::startTrans();
  257. // try{
  258. $data = [
  259. "id" => $id,
  260. "company" => $company,
  261. // "companyNo"=>$companyNo,
  262. "inv_code" => $inv_code,
  263. "type" => $type,
  264. "creater" => $creater,
  265. "createrid" => $createrid,
  266. "inv_legaler" => $inv_legaler,
  267. "inv_time" => $inv_time,
  268. "inv_addr" => $inv_addr,
  269. "inv_bank" => $inv_bank,
  270. "inv_bankNo" => $inv_bankNo,
  271. "contactor" => $contactor,
  272. "mobile" => $mobile,
  273. "addr" => $addr,
  274. "inv_scope" => $inv_scope,
  275. "license_img" => $license_img,
  276. "status" => $status,
  277. "is_del" => 0,
  278. "updatetime" => date("Y-m-d H:i:s")
  279. ];
  280. $userCommon = new \app\admin\common\User();
  281. $rs = $userCommon->handle('bEdit', $data);
  282. return json_show($rs['code'], $rs['message'],$rs['data']);
  283. // $info = Db::name('business')->save($data);
  284. // if($info){
  285. // Db::commit();
  286. // return error_show(0,"更新成功");
  287. // }else{
  288. // Db::rollback();
  289. // return error_show(1002,"更新失败");
  290. // }
  291. // }catch (\Exception $e) {
  292. // Db::rollback();
  293. // return error_show(1005, $e->getMessage());
  294. // }
  295. }
  296. public function del()
  297. {
  298. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  299. // if($id==""){
  300. // return error_show(1002,"参数id不能为空");
  301. // }
  302. // $str= Db::name('business')->where(['id'=>$id,'is_del'=>0])->find();
  303. // if(empty($str)){
  304. // return error_show(1002,"未找到数据");
  305. // }
  306. // $end = Db::name('business')->update(['id'=>$id,'is_del'=>1]);
  307. // if($end){
  308. // return error_show(0,"删除成功");
  309. // }else{
  310. // return error_show(1002,"删除失败");
  311. // }
  312. $param = $this->request->only(['id' => 0], 'post', 'trim');
  313. $userCommon = new \app\admin\common\User();
  314. $rs = $userCommon->handle('delete', [
  315. 'ids' => [$param['id']],
  316. 'type' => 1,
  317. 'updater' => $this->uname,
  318. 'updaterid' => $this->uid,
  319. ]);
  320. return json_show($rs['code'], $rs['message'],$rs['data']);
  321. }
  322. public function status()
  323. {
  324. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  325. // if($id==""){
  326. // return error_show(1002,"参数id不能为空");
  327. // }
  328. // $info = Db::name("business")->where([["id","=",$id],["is_del","=",0]])->find();
  329. // if(!$info){
  330. // return error_show(1002,"未找到对应数据");
  331. // }
  332. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  333. // if($status===""){
  334. // return error_show(1002,"参数status不能为空");
  335. // }
  336. // if(!in_array($status,[0,1])){
  337. // return error_show(1002,"参数status无效");
  338. // }
  339. // $info['status']=$status;
  340. // $msg = $status==1?"启用":"禁用";
  341. // $update = Db::name("business")->save($info);
  342. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  343. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  344. $val = Validate::rule([
  345. 'id' => 'require|number|gt:0',
  346. 'status|状态' => 'require|number|in:0,1'
  347. ]);
  348. if (!$val->check($param)) return json_show(1005, $val->getError());
  349. $userCommon = new \app\admin\common\User();
  350. $rs = $userCommon->handle('status', [
  351. 'id' => $param['id'],
  352. 'status' => $param['status'],
  353. 'type' => 1,
  354. 'updater' => $this->uname,
  355. 'updaterid' => $this->uid,
  356. ]);
  357. return json_show($rs['code'], $rs['message'],$rs['data']);
  358. }
  359. public function info()
  360. {
  361. // $companyNo =isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']) :"";
  362. $param = $this->request->only(['companyNo'], 'post', 'trim');
  363. $userCommon = new \app\admin\common\User();
  364. $rs = $userCommon->handle('bInfo', $param);
  365. return json_show($rs['code'], $rs['message'],$rs['data']);
  366. // if($companyNo==""){
  367. // return error_show(1004,"参数companyNo不能为空");
  368. // }
  369. // $tod=Db::name('business')->where(['companyNo'=>$companyNo,'is_del'=>0])->find();
  370. // if($tod==""){
  371. // return error_show(1002,"未找到数据");
  372. // }
  373. // $info = Db::name('company_type')->where(['id'=>$tod['type'],"is_del"=>0])->find();
  374. //
  375. // $tod['companytype']=isset($info['company_type'])?$info['company_type']:"" ;
  376. //
  377. // return app_show(0,"获取成功",$tod);
  378. }
  379. public function title()
  380. {
  381. $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
  382. // $where = [["is_del","=",0]];
  383. // $company_type = isset($this->post['company_type']) && $this->post['company_type'] !=="" ? intval($this->post['company_type']):"";
  384. // if($company_type!=""){
  385. // $where[]=['company_type',"like","%$company_type%"];
  386. // }
  387. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  388. // if($status!=""){
  389. // $where[]=['status',"=",$status];
  390. // }
  391. // $list = Db::name('company_type')->where($where)->select();
  392. // return app_show(0,"获取成功",$list);
  393. $userCommon = new \app\admin\common\User();
  394. $rs = $userCommon->handle('bTitle', $param);
  395. return json_show($rs['code'], $rs['message'],$rs['data']);
  396. }
  397. }