Suppler.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Suppler extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function create(){
  15. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  16. // $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  17. // if (!empty($rename)) {
  18. // return error_show(1002, "公司名称已存在");
  19. // }
  20. $code = rand(0000,9999);
  21. $str = sprintf("%04d",$code);
  22. $tr="GYS-".date("Ymd")."-".$str;
  23. $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :"";
  24. if($source===""){
  25. return error_show(1002,"供应商来源不能为空");
  26. }
  27. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  28. if($token==''){
  29. return error_show(1005,"参数token不能为空");
  30. }
  31. $user =GetUserInfo($token);
  32. if(empty($user)||$user['code']!=0){
  33. return error_show(1002,"创建人数据不存在");
  34. }
  35. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  36. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  37. $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :"";
  38. if($type===""){
  39. return error_show(1002,"申请类型不能为空");
  40. }
  41. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):"";
  42. if($coop_state===""){
  43. return error_show(1002,"参数coop_state不能为空");
  44. }
  45. $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):"";
  46. if($category===""){
  47. return error_show(1002,"参数category不能为空");
  48. }
  49. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):"";
  50. if($delivery_way===""){
  51. return error_show(1002,"参数delivery_way不能为空");
  52. }
  53. $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
  54. if($level===""){
  55. return error_show(1002,"参数level不能为空");
  56. }
  57. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):"";
  58. if($supplier_type===""){
  59. return error_show(1002,"参数supplier_type不能为空");
  60. }
  61. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):"";
  62. if($pay_type===""){
  63. return error_show(1002,"参数pay_type不能为空");
  64. }
  65. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  66. if($prove_img==""){
  67. return error_show(1002,"参数prove_img不能为空");
  68. }
  69. // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  70. // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  71. $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :"";
  72. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  73. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :"";
  74. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  75. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  76. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  77. $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  78. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  79. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  80. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  81. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  82. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  83. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  84. $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  85. $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
  86. $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  87. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  88. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  89. if($contactor==""){
  90. return error_show(1002,"参数contactor不能为空");
  91. }
  92. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  93. if($mobile==""){
  94. return error_show(1002,"参数mobile不能为空");
  95. }
  96. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  97. if($position==""){
  98. return error_show(1002,"参数position不能为空");
  99. }
  100. Db::startTrans();
  101. try{
  102. $data=[
  103. "name"=>$name,
  104. "source"=>$source,
  105. "coop_state"=>$coop_state,
  106. "category"=>$category,
  107. "delivery_way"=>$delivery_way,
  108. "level"=>$level,
  109. "supplier_type"=>$supplier_type,
  110. "pay_type"=>$pay_type,
  111. "registercode"=>$registercode,
  112. "capital"=>$capital,
  113. "product_category"=>$product_category,
  114. "is_payment"=>$is_payment,
  115. "notice_mark"=>$notice_mark,
  116. "agreement"=>$agreement,
  117. "warehouse"=>$warehouse,
  118. "pay_day"=>$pay_day,
  119. "scope"=>$scope,
  120. "status"=>$status,
  121. "code"=>$tr,
  122. "type"=>$type,
  123. // "area"=>$area,
  124. // "city"=>$city,
  125. "nature"=>$nature,
  126. "legaler"=>$legaler,
  127. "addr"=>$addr,
  128. "is_del"=>0,
  129. "ticket_type"=>$ticket_type,
  130. "addtime"=>date('Y-m-d H:i:s'),
  131. "updatetime"=>date("Y-m-d H:i:s"),
  132. "is_platform"=>$is_platform,
  133. "prove_img"=>$prove_img,
  134. "creater"=>$creater,
  135. "createrid"=>$createrid,
  136. "registertime"=>date('Y-m-d H:i:s')
  137. ];
  138. if($supplier_img==""){
  139. if($registercode==""){
  140. return error_show(1002,"参数registercode不能为空");
  141. }
  142. if($name==""){
  143. return error_show(1002,"数据标题不能为空");
  144. }
  145. if($nature===""){
  146. return error_show(1002,"参数nature不能为空");
  147. }
  148. if($legaler==""){
  149. return error_show(1002,"参数legaler不能为空");
  150. }
  151. if($registertime==""){
  152. return error_show(1002,"参数registertime不能为空");
  153. }
  154. if($addr==""){
  155. return error_show(1002,"参数addr不能为空");
  156. }
  157. if($scope==""){
  158. return error_show(1002,"参数scope不能为空");
  159. }
  160. $data['registertime']=$registertime;
  161. }
  162. $join = Db::name('supplier')->insert($data,true);
  163. if($join>0){
  164. $temp = [];
  165. $temp['code']=$code;
  166. $temp['contactor'] =$contactor;
  167. $temp['mobile'] = $mobile;
  168. $temp['position'] = $position;
  169. $temp['email'] ="";
  170. $temp['is_del'] = 0;
  171. $temp['addtime'] = date("Y-m-d H:i:s");
  172. $temp['updatetime'] = date("Y-m-d H:i:s");
  173. $vp = Db::name('supplier_contact')->insert($temp);
  174. if ($vp == "") {
  175. Db::rollback();
  176. return error_show(1002, "添加失败");
  177. }
  178. Db::commit();
  179. return error_show(0,"添加成功") ;
  180. }else{
  181. Db::rollback();
  182. return error_show(1002,"添加失败");
  183. }
  184. }catch (\Exception $e) {
  185. Db::rollback();
  186. return error_show(1003, $e->getMessage());
  187. }
  188. }
  189. public function list(){
  190. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  191. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  192. $where =[['a.is_del',"=",0]];
  193. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  194. if($name !==""){
  195. $where[]=["a.name","like","%$name%"];
  196. }
  197. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  198. if($creater !==""){
  199. $where[] = ["a.creater","like","%$creater%"];
  200. }
  201. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  202. if($status!==""){
  203. $where[]= ["a.status","=",$status];
  204. }
  205. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  206. if($start!==""){
  207. $where[]=['a.addtime',">=",$start];
  208. }
  209. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  210. // if($end !=""){
  211. // $where[]=['a.addtime',"<=",$end];
  212. // }
  213. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
  214. if($contactor !=""){
  215. $where[]=["b.contactor","like","%$contactor%"];
  216. }
  217. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
  218. if($mobile !=""){
  219. $where[] = ['b.mobile',"like","%$mobile%"];
  220. }
  221. $count = Db::name('supplier')->alias("a")
  222. ->join("supplier_contact b","b.code=a.code","left")
  223. ->where($where)->count();
  224. $total = ceil($count / $size);
  225. $page = $page >= $total ? $total : $page;
  226. $list = Db::name('supplier')->alias('a')
  227. ->join("supplier_contact b","b.code=a.code","left")
  228. ->where($where)->page($page,$size)->order("a.addtime desc")
  229. ->field("a.*,b.contactor,b.mobile")->select();
  230. return app_show("0","获取成功",['list'=>$list,'count'=>$count]);
  231. }
  232. public function edit(){
  233. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  234. if($id==""){
  235. return error_show(1002,"参数id不能为空");
  236. }
  237. $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
  238. if($info==""){
  239. return error_show(1002,"未找到数据");
  240. }
  241. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  242. if($source==""){
  243. return error_show(1002,"供应商来源不能为空");
  244. }
  245. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  246. if($type==""){
  247. return error_show(1002,"申请类型不能为空");
  248. }
  249. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
  250. if($coop_state==""){
  251. return error_show(1002,"参数coop_state不能为空");
  252. }
  253. $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
  254. if($category==""){
  255. return error_show(1002,"参数category不能为空");
  256. }
  257. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
  258. if($delivery_way==""){
  259. return error_show(1002,"参数delivery_way不能为空");
  260. }
  261. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  262. if($level==""){
  263. return error_show(1002,"参数level不能为空");
  264. }
  265. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
  266. if($supplier_type==""){
  267. return error_show(1002,"参数supplier_type不能为空");
  268. }
  269. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
  270. if($pay_type==""){
  271. return error_show(1002,"参数pay_type不能为空");
  272. }
  273. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  274. if($prove_img==""){
  275. return error_show(1002,"参数prove_img不能为空");
  276. }
  277. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  278. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  279. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  280. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  281. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  282. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  283. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  284. $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  285. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  286. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  287. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  288. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  289. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  290. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  291. $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  292. $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  293. $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  294. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  295. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  296. if($contactor==""){
  297. return error_show(1002,"参数contactor不能为空");
  298. }
  299. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  300. if($mobile==""){
  301. return error_show(1002,"参数mobile不能为空");
  302. }
  303. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  304. if($position==""){
  305. return error_show(1002,"参数position不能为空");
  306. }
  307. try{
  308. $data=[
  309. "id"=>$id,
  310. "source"=>$source,
  311. "coop_state"=>$coop_state,
  312. "category"=>$category,
  313. "delivery_way"=>$delivery_way,
  314. "level"=>$level,
  315. "supplier_type"=>$supplier_type,
  316. "pay_type"=>$pay_type,
  317. "registercode"=>$registercode,
  318. "capital"=>$capital,
  319. "product_category"=>$product_category,
  320. "is_payment"=>$is_payment,
  321. "notice_mark"=>$notice_mark,
  322. "agreement"=>$agreement,
  323. "warehouse"=>$warehouse,
  324. "pay_day"=>$pay_day,
  325. "scope"=>$scope,
  326. "status"=>$status,
  327. "type"=>$type,
  328. "nature"=>$nature,
  329. "legaler"=>$legaler,
  330. "addr"=>$addr,
  331. "is_del"=>0,
  332. "ticket_type"=>$ticket_type,
  333. "updatetime"=>date("Y-m-d H:i:s"),
  334. "is_platform"=>$is_platform,
  335. "prove_img"=>$prove_img,
  336. "registertime"=>date("Y-m-d H:i:s"),
  337. ];
  338. if($supplier_img==""){
  339. if($registercode==""){
  340. return error_show(1002,"参数registercode不能为空");
  341. }
  342. if($name==""){
  343. return error_show(1002,"数据标题不能为空");
  344. }
  345. if($nature==""){
  346. return error_show(1002,"参数nature不能为空");
  347. }
  348. if($legaler==""){
  349. return error_show(1002,"参数legaler不能为空");
  350. }
  351. if($registertime==""){
  352. return error_show(1002,"参数registertime不能为空");
  353. }
  354. $data['registertime']=$registertime;
  355. }
  356. $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
  357. if($join){
  358. $item = Db::name('supplier_contact')->where(['code'=>$join['code']])->find();
  359. $temp = [];
  360. isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
  361. $temp['code'] = $info['code'];
  362. $temp['contactor'] = $contactor;
  363. $temp['mobile'] = $mobile;
  364. $temp['position'] = $position;
  365. $temp['email'] ="";
  366. $temp['contactor'] ="";
  367. $temp['is_del'] = 0;
  368. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  369. $temp['updatetime'] = date("Y-m-d H:i:s");
  370. $vp = Db::name('supplier_contact')->save($temp);
  371. if ($vp == "") {
  372. Db::rollback();
  373. return error_show(1002, "更新失败");
  374. }
  375. Db::commit();
  376. return error_show(0,"编辑成功") ;
  377. }else{
  378. Db::rollback();
  379. return error_show(1002,"编辑失败");
  380. }
  381. }catch (\Exception $e) {
  382. Db::rollback();
  383. return error_show(1003, $e->getMessage());
  384. }
  385. }
  386. public function info(){
  387. $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
  388. if($id ==""){
  389. return error_show(1002,"参数id不能为空");
  390. }
  391. $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  392. if($info==""){
  393. return error_show(1002,"未找到数据");
  394. }
  395. return app_show(0,"获取成功",$info);
  396. }
  397. public function del(){
  398. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  399. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  400. if($sup==false){
  401. return error_show(1002,"供应商信息不存在");
  402. }
  403. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  404. if($supp){
  405. return error_show(0,"删除成功");
  406. }else{
  407. return error_show(1002,"删除失败");
  408. }
  409. }
  410. public function status(){
  411. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  412. if($id==""){
  413. return error_show(1002,"参数id不能为空");
  414. }
  415. $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  416. if(!$info){
  417. return error_show(1002,"未找到对应数据");
  418. }
  419. $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  420. if($status===""){
  421. return error_show(1002,"参数status不能为空");
  422. }
  423. if(!in_array($status,[0,1])){
  424. return error_show(1002,"参数status无效");
  425. }
  426. $info['status']=$status;
  427. $info['updatetime']=date("Y-m-d H:i:s");
  428. $msg = $status==1?"启用":"禁用";
  429. $update = Db::name("supplier")->save($info);
  430. return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  431. }
  432. }