Business.php 15 KB

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