Suppler.php 26 KB

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