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