Business.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. $param = $this->request->only(['id', 'inv_addr', 'inv_bank', 'inv_bankNo', 'mobile','invoice_title'], 'post', 'trim');
  185. $val = Validate::rule([
  186. 'id' => 'require|number|gt:0',
  187. 'inv_addr' => 'require|max:255',
  188. 'inv_bank' => 'require|max:255',
  189. 'inv_bankNo' => 'require|max:255',
  190. 'mobile' => 'require|max:255',
  191. 'invoice_title' => 'require|max:255',
  192. ]);
  193. if ($val->check($param) == false) return json_show(1005, $val->getError());
  194. $userCommon = new \app\admin\common\User();
  195. $rs = $userCommon->handle('bEdit', $param);
  196. return json_show($rs['code'], $rs['message'], $rs['data']);
  197. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  198. // if ($id == "") {
  199. // return error_show(1002, "参数id不能为空");
  200. // }
  201. // $idinfo = Db::name('business')->where(['id'=>$id,'is_del'=>0])->find();
  202. // if($idinfo==""){
  203. // return error_show(1003,"未找到数据");
  204. // }
  205. // $companyNo = makeNo("GS");
  206. // $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  207. // if ($company == "") {
  208. // return error_show(1002, "参数company不能为空");
  209. // }
  210. // $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  211. // if ($type == "") {
  212. // return error_show(1002, "参数type不能为空");
  213. // }
  214. // $inv_code = isset($this->post['inv_code']) && $this->post['inv_code'] !== "" ? trim($this->post['inv_code']) : "";
  215. // if ($inv_code == "") {
  216. // return error_show(1002, "参数inv_code不能为空");
  217. // }
  218. // $inv_legaler = isset($this->post['inv_legaler']) && $this->post['inv_legaler'] !== "" ? trim($this->post['inv_legaler']) : "";
  219. // if ($inv_legaler == "") {
  220. // return error_show(1002, "参数inv_legaler不能为空");
  221. // }
  222. // $inv_time = isset($this->post['inv_time']) && $this->post['inv_time'] !== "" ? $this->post['inv_time'] : "";
  223. // if ($inv_time == "") {
  224. // return error_show(1005, '参数inv_time不能为空');
  225. // }
  226. // $inv_addr = isset($this->post['inv_addr']) && $this->post['inv_addr'] !== "" ? trim($this->post['inv_addr']) : "";
  227. // if ($inv_addr == "") {
  228. // return error_show(1002, "参数inv_addr不能为空");
  229. // }
  230. // $inv_bank = isset($this->post['inv_bank']) && $this->post['inv_bank'] !== "" ? trim($this->post['inv_bank']) : "";
  231. // if ($inv_bank == "") {
  232. // return error_show(1002, "参数inv_bank不能为空");
  233. // }
  234. // $inv_bankNo = isset($this->post['inv_bankNo']) && $this->post['inv_bankNo'] !== "" ? trim($this->post['inv_bankNo']) : "";
  235. // if ($inv_bankNo == "") {
  236. // return error_show(1002, "参数inv_bankNo不能为空");
  237. // }
  238. // $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  239. // if ($contactor == "") {
  240. // return error_show(1002, "参数contactor不能为空");
  241. // }
  242. // $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  243. // if ($mobile == "") {
  244. // return error_show(1002, "参数mobile不能为空");
  245. // }
  246. // $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  247. // if ($addr == "") {
  248. // return error_show(1002, "参数addr不能为空");
  249. // }
  250. // $inv_scope = isset($this->post['inv_scope']) && $this->post['inv_scope'] !== "" ? trim($this->post['inv_scope']) : "";
  251. // if ($inv_scope == "") {
  252. // return error_show(1002, "参数inv_scope不能为空");
  253. // }
  254. // $license_img = isset($this->post['license_img']) && $this->post['license_img'] !== "" ? trim($this->post['license_img']) : "";
  255. // if($license_img==""){
  256. // return error_show(1002,"参数license_img不能为空");
  257. // }
  258. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  259. // if($token==''){
  260. // return error_show(105,"参数token不能为空");
  261. // }
  262. // $user =GetUserInfo($token);
  263. // if(empty($user)||$user['code']!=0){
  264. // return error_show(102,"创建人数据不存在");
  265. // }
  266. // $createrid = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  267. // $creater = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  268. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  269. // Db::startTrans();
  270. // try{
  271. // $info = Db::name('business')->save($data);
  272. // if($info){
  273. // Db::commit();
  274. // return error_show(0,"更新成功");
  275. // }else{
  276. // Db::rollback();
  277. // return error_show(1002,"更新失败");
  278. // }
  279. // }catch (\Exception $e) {
  280. // Db::rollback();
  281. // return error_show(1005, $e->getMessage());
  282. // }
  283. }
  284. public function del()
  285. {
  286. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  287. // if($id==""){
  288. // return error_show(1002,"参数id不能为空");
  289. // }
  290. // $str= Db::name('business')->where(['id'=>$id,'is_del'=>0])->find();
  291. // if(empty($str)){
  292. // return error_show(1002,"未找到数据");
  293. // }
  294. // $end = Db::name('business')->update(['id'=>$id,'is_del'=>1]);
  295. // if($end){
  296. // return error_show(0,"删除成功");
  297. // }else{
  298. // return error_show(1002,"删除失败");
  299. // }
  300. $param = $this->request->only(['id' => 0], 'post', 'trim');
  301. $userCommon = new \app\admin\common\User();
  302. $rs = $userCommon->handle('delete', [
  303. 'ids' => [$param['id']],
  304. 'type' => 1,
  305. 'updater' => $this->uname,
  306. 'updaterid' => $this->uid,
  307. ]);
  308. return json_show($rs['code'], $rs['message'], $rs['data']);
  309. }
  310. public function status()
  311. {
  312. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  313. // if($id==""){
  314. // return error_show(1002,"参数id不能为空");
  315. // }
  316. // $info = Db::name("business")->where([["id","=",$id],["is_del","=",0]])->find();
  317. // if(!$info){
  318. // return error_show(1002,"未找到对应数据");
  319. // }
  320. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  321. // if($status===""){
  322. // return error_show(1002,"参数status不能为空");
  323. // }
  324. // if(!in_array($status,[0,1])){
  325. // return error_show(1002,"参数status无效");
  326. // }
  327. // $info['status']=$status;
  328. // $msg = $status==1?"启用":"禁用";
  329. // $update = Db::name("business")->save($info);
  330. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  331. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  332. $val = Validate::rule([
  333. 'id' => 'require|number|gt:0',
  334. 'status|状态' => 'require|number|in:0,1'
  335. ]);
  336. if (!$val->check($param)) return json_show(1005, $val->getError());
  337. $userCommon = new \app\admin\common\User();
  338. $rs = $userCommon->handle('status', [
  339. 'id' => $param['id'],
  340. 'status' => $param['status'],
  341. 'type' => 1,
  342. 'updater' => $this->uname,
  343. 'updaterid' => $this->uid,
  344. ]);
  345. return json_show($rs['code'], $rs['message'], $rs['data']);
  346. }
  347. public function info()
  348. {
  349. // $companyNo =isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']) :"";
  350. $param = $this->request->only(['companyNo'], 'post', 'trim');
  351. $userCommon = new \app\admin\common\User();
  352. $rs = $userCommon->handle('bInfo', $param);
  353. return json_show($rs['code'], $rs['message'], $rs['data']);
  354. // if($companyNo==""){
  355. // return error_show(1004,"参数companyNo不能为空");
  356. // }
  357. // $tod=Db::name('business')->where(['companyNo'=>$companyNo,'is_del'=>0])->find();
  358. // if($tod==""){
  359. // return error_show(1002,"未找到数据");
  360. // }
  361. // $info = Db::name('company_type')->where(['id'=>$tod['type'],"is_del"=>0])->find();
  362. //
  363. // $tod['companytype']=isset($info['company_type'])?$info['company_type']:"" ;
  364. //
  365. // return app_show(0,"获取成功",$tod);
  366. }
  367. public function title()
  368. {
  369. $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
  370. // $where = [["is_del","=",0]];
  371. // $company_type = isset($this->post['company_type']) && $this->post['company_type'] !=="" ? intval($this->post['company_type']):"";
  372. // if($company_type!=""){
  373. // $where[]=['company_type',"like","%$company_type%"];
  374. // }
  375. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  376. // if($status!=""){
  377. // $where[]=['status',"=",$status];
  378. // }
  379. // $list = Db::name('company_type')->where($where)->select();
  380. // return app_show(0,"获取成功",$list);
  381. $userCommon = new \app\admin\common\User();
  382. $rs = $userCommon->handle('bTitle', $param);
  383. return json_show($rs['code'], $rs['message'], $rs['data']);
  384. }
  385. }