Suppler.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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']!==""? trim($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']) :"";
  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. ];
  137. if($supplier_img==""){
  138. if($registerCode==""){
  139. return error_show(1002,"参数registerCode不能为空");
  140. }
  141. if($name==""){
  142. return error_show(1002,"数据标题不能为空");
  143. }
  144. if($nature==""){
  145. return error_show(1002,"参数nature不能为空");
  146. }
  147. if($legaler==""){
  148. return error_show(1002,"参数legaler不能为空");
  149. }
  150. if($registertime==""){
  151. return error_show(1002,"参数registertime不能为空");
  152. }
  153. if($addr==""){
  154. return error_show(1002,"参数addr不能为空");
  155. }
  156. if($scope==""){
  157. return error_show(1002,"参数scope不能为空");
  158. }
  159. $data['registertime']=$registertime;
  160. }
  161. $join = Db::name('supplier')->insert($data,true);
  162. if($join>0){
  163. $temp = [];
  164. $temp['code']=$code;
  165. $temp['contactor'] =$contactor;
  166. $temp['mobile'] = $mobile;
  167. $temp['position'] = $position;
  168. $temp['email'] ="";
  169. $temp['is_del'] = 0;
  170. $temp['addtime'] = date("Y-m-d H:i:s");
  171. $temp['updatetime'] = date("Y-m-d H:i:s");
  172. $vp = Db::name('supplier_contact')->insert($temp);
  173. if ($vp == "") {
  174. Db::rollback();
  175. return error_show(1002, "添加失败");
  176. }
  177. Db::commit();
  178. return error_show(0,"添加成功") ;
  179. }else{
  180. Db::rollback();
  181. return error_show(1002,"添加失败");
  182. }
  183. }catch (\Exception $e) {
  184. Db::rollback();
  185. return error_show(1003, $e->getMessage());
  186. }
  187. }
  188. public function list(){
  189. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  190. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  191. $where =[['a.is_del',"=",0]];
  192. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  193. if($name !==""){
  194. $where[]=["a.name","like","%$name%"];
  195. }
  196. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  197. if($creater !==""){
  198. $where[] = ["a.creater","like","%$creater%"];
  199. }
  200. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  201. if($status!==""){
  202. $where[]= ["a.status","=",$status];
  203. }
  204. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  205. if($start!==""){
  206. $where[]=['a.addtime',">=",$start];
  207. }
  208. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  209. // if($end !=""){
  210. // $where[]=['a.addtime',"<=",$end];
  211. // }
  212. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
  213. if($contactor !=""){
  214. $where[]=["b.contactor","like","%$contactor%"];
  215. }
  216. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
  217. if($mobile !=""){
  218. $where[] = ['b.mobile',"like","%$mobile%"];
  219. }
  220. $count = Db::name('supplier')->alias("a")
  221. ->join("supplier_contact b","b.code=a.code","left")
  222. ->where($where)->count();
  223. $total = ceil($count / $size);
  224. $page = $page >= $total ? $total : $page;
  225. $list = Db::name('supplier')->alias('a')
  226. ->join("supplier_contact b","b.code=a.code","left")
  227. ->where($where)->page($page,$size)->order("a.addtime desc")
  228. ->field("a.*,b.contactor,b.mobile")->select();
  229. return app_show("0","获取成功",['list'=>$list,'count'=>$count]);
  230. }
  231. public function edit(){
  232. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  233. if($id==""){
  234. return error_show(1002,"参数id不能为空");
  235. }
  236. $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
  237. if($info==""){
  238. return error_show(1002,"未找到数据");
  239. }
  240. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  241. if($source==""){
  242. return error_show(1002,"供应商来源不能为空");
  243. }
  244. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  245. if($type==""){
  246. return error_show(1002,"申请类型不能为空");
  247. }
  248. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
  249. if($coop_state==""){
  250. return error_show(1002,"参数coop_state不能为空");
  251. }
  252. $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
  253. if($category==""){
  254. return error_show(1002,"参数category不能为空");
  255. }
  256. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
  257. if($delivery_way==""){
  258. return error_show(1002,"参数delivery_way不能为空");
  259. }
  260. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  261. if($level==""){
  262. return error_show(1002,"参数level不能为空");
  263. }
  264. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
  265. if($supplier_type==""){
  266. return error_show(1002,"参数supplier_type不能为空");
  267. }
  268. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
  269. if($pay_type==""){
  270. return error_show(1002,"参数pay_type不能为空");
  271. }
  272. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  273. if($prove_img==""){
  274. return error_show(1002,"参数prove_img不能为空");
  275. }
  276. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  277. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  278. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  279. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  280. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  281. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  282. $registerCode= isset($this->post['registerCode']) && $this->post['registerCode']!==""? trim($this->post['registerCode']) :"";
  283. $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  284. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  285. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  286. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  287. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  288. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  289. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  290. $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  291. $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  292. $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  293. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  294. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  295. if($contactor==""){
  296. return error_show(1002,"参数contactor不能为空");
  297. }
  298. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  299. if($mobile==""){
  300. return error_show(1002,"参数mobile不能为空");
  301. }
  302. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  303. if($position==""){
  304. return error_show(1002,"参数position不能为空");
  305. }
  306. try{
  307. $data=[
  308. "id"=>$id,
  309. "source"=>$source,
  310. "coop_state"=>$coop_state,
  311. "category"=>$category,
  312. "delivery_way"=>$delivery_way,
  313. "level"=>$level,
  314. "supplier_type"=>$supplier_type,
  315. "pay_type"=>$pay_type,
  316. "registerCode"=>$registerCode,
  317. "capital"=>$capital,
  318. "product_category"=>$product_category,
  319. "is_payment"=>$is_payment,
  320. "notice_mark"=>$notice_mark,
  321. "agreement"=>$agreement,
  322. "warehouse"=>$warehouse,
  323. "pay_day"=>$pay_day,
  324. "scope"=>$scope,
  325. "status"=>$status,
  326. "type"=>$type,
  327. "nature"=>$nature,
  328. "legaler"=>$legaler,
  329. "addr"=>$addr,
  330. "is_del"=>0,
  331. "ticket_type"=>$ticket_type,
  332. "updatetime"=>date("Y-m-d H:i:s"),
  333. "is_platform"=>$is_platform,
  334. "prove_img"=>$prove_img
  335. ];
  336. if($supplier_img==""){
  337. if($registerCode==""){
  338. return error_show(1002,"参数registerCode不能为空");
  339. }
  340. if($name==""){
  341. return error_show(1002,"数据标题不能为空");
  342. }
  343. if($nature==""){
  344. return error_show(1002,"参数nature不能为空");
  345. }
  346. if($legaler==""){
  347. return error_show(1002,"参数legaler不能为空");
  348. }
  349. if($registertime==""){
  350. return error_show(1002,"参数registertime不能为空");
  351. }
  352. $data['registertime']=$registertime;
  353. }
  354. $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
  355. if($join){
  356. $item = Db::name('supplier_contact')->where(['code'=>$join['code']])->find();
  357. $temp = [];
  358. isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
  359. $temp['code'] = $info['code'];
  360. $temp['contactor'] = $contactor;
  361. $temp['mobile'] = $mobile;
  362. $temp['position'] = $position;
  363. $temp['email'] ="";
  364. $temp['contactor'] ="";
  365. $temp['is_del'] = 0;
  366. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  367. $temp['updatetime'] = date("Y-m-d H:i:s");
  368. $vp = Db::name('supplier_contact')->save($temp);
  369. if ($vp == "") {
  370. Db::rollback();
  371. return error_show(1002, "更新失败");
  372. }
  373. Db::commit();
  374. return error_show(0,"编辑成功") ;
  375. }else{
  376. Db::rollback();
  377. return error_show(1002,"编辑失败");
  378. }
  379. }catch (\Exception $e) {
  380. Db::rollback();
  381. return error_show(1003, $e->getMessage());
  382. }
  383. }
  384. public function info(){
  385. $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
  386. if($id ==""){
  387. return error_show(1002,"参数id不能为空");
  388. }
  389. $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  390. if($info==""){
  391. return error_show(1002,"未找到数据");
  392. }
  393. return app_show(0,"获取成功",$info);
  394. }
  395. public function del(){
  396. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  397. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  398. if($sup==false){
  399. return error_show(1002,"供应商信息不存在");
  400. }
  401. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  402. if($supp){
  403. return error_show(0,"删除成功");
  404. }else{
  405. return error_show(1002,"删除失败");
  406. }
  407. }
  408. public function status(){
  409. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  410. if($id==""){
  411. return error_show(1002,"参数id不能为空");
  412. }
  413. $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  414. if(!$info){
  415. return error_show(1002,"未找到对应数据");
  416. }
  417. $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  418. if($status===""){
  419. return error_show(1002,"参数status不能为空");
  420. }
  421. if(!in_array($status,[0,1])){
  422. return error_show(1002,"参数status无效");
  423. }
  424. $info['status']=$status;
  425. $info['updatetime']=date("Y-m-d H:i:s");
  426. $msg = $status==1?"启用":"禁用";
  427. $update = Db::name("supplier")->save($info);
  428. return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  429. }
  430. }