Business.php 18 KB

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