Suppler.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. if($info['status']==1){
  267. return error_show(1002,"状态是启用状态,无法编辑");
  268. }
  269. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  270. if($source==""){
  271. return error_show(1002,"供应商来源不能为空");
  272. }
  273. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  274. if($type==""){
  275. return error_show(1002,"申请类型不能为空");
  276. }
  277. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
  278. if($coop_state==""){
  279. return error_show(1002,"参数coop_state不能为空");
  280. }
  281. $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
  282. if($category==""){
  283. return error_show(1002,"参数category不能为空");
  284. }
  285. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
  286. if($delivery_way==""){
  287. return error_show(1002,"参数delivery_way不能为空");
  288. }
  289. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  290. if($level==""){
  291. return error_show(1002,"参数level不能为空");
  292. }
  293. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
  294. if($supplier_type==""){
  295. return error_show(1002,"参数supplier_type不能为空");
  296. }
  297. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
  298. if($pay_type==""){
  299. return error_show(1002,"参数pay_type不能为空");
  300. }
  301. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  302. if($prove_img==""){
  303. return error_show(1002,"参数prove_img不能为空");
  304. }
  305. $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
  306. if($personid==""){
  307. return error_show(1002,"参数personid不能为空");
  308. }
  309. $to= GetInfoById($token,['id'=>$personid]);
  310. if(empty($to)||$to['code']!=0){
  311. return app_show(1002,"负责人信息不存在");
  312. }
  313. $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  314. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  315. if($name==""){
  316. return error_show(1002,"数据标题不能为空");
  317. }
  318. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  319. if (!empty($rename)&&$rename['id']!=$id) {
  320. return error_show(1002, "公司名称已存在");
  321. }
  322. // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  323. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  324. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  325. // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  326. // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  327. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  328. // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  329. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  330. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  331. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  332. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  333. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  334. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  335. // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  336. //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  337. // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  338. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  339. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  340. if($contactor==""){
  341. return error_show(1002,"参数contactor不能为空");
  342. }
  343. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  344. if($mobile==""){
  345. return error_show(1002,"参数mobile不能为空");
  346. }
  347. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  348. if($position==""){
  349. return error_show(1002,"参数position不能为空");
  350. }
  351. if($registercode==""){
  352. return error_show(1002,"参数registercode不能为空");
  353. }
  354. Db::startTrans();
  355. try{
  356. $data=[
  357. "id"=>$id,
  358. "source"=>$source,
  359. "name"=>$name,
  360. "coop_state"=>$coop_state,
  361. "category"=>$category,
  362. "delivery_way"=>$delivery_way,
  363. "level"=>$level,
  364. "supplier_type"=>$supplier_type,
  365. "pay_type"=>$pay_type,
  366. "registercode"=>$registercode,
  367. "product_category"=>$product_category,
  368. "is_payment"=>$is_payment,
  369. "notice_mark"=>$notice_mark,
  370. "agreement"=>$agreement,
  371. "warehouse"=>$warehouse,
  372. "pay_day"=>$pay_day,
  373. "type"=>$type,
  374. "license_img"=>$supplier_img,
  375. "is_del"=>0,
  376. "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
  377. "ticket_type"=>$ticket_type,
  378. "updatetime"=>date("Y-m-d H:i:s"),
  379. "is_platform"=>$is_platform,
  380. "prove_img"=>$prove_img,
  381. "person"=>$person,
  382. "personid"=>$personid,
  383. "remark"=>""
  384. ];
  385. if($supplier_img!=="" &&$info['license_img']!=$supplier_img){
  386. $ocr=new Ocr();
  387. $dataw = $ocr->query("",$supplier_img);
  388. // var_dump($data);
  389. if($dataw['code']==0 && isset($dataw['data']['result'])){
  390. $license = $dataw['data']['result'];
  391. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  392. $data['addr']= isset($license['address'])?$license['address']:"";
  393. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  394. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  395. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  396. $data['nature']= isset($license['type'])?$license['type']:"";
  397. $data['status']=1;
  398. if($name!=$license['name']){
  399. $data['remark']="企业名称与营业执照不匹配";
  400. $data['status']=0;
  401. }
  402. if($registercode!=$license['registration_number']){
  403. $data['remark'].="企业名称与营业执照不匹配";
  404. $data['status']=0;
  405. }
  406. }else{
  407. $data['remark']="营业执照识别失败";
  408. $data['status']=0;
  409. }
  410. }
  411. $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
  412. if($join){
  413. $item = Db::name('supplier_contact')->where(['code'=>$info['code']])->find();
  414. $temp = [];
  415. isset($item['id']) && $item['id'] !== "" ? $temp['id'] =$item['id'] : '';
  416. $temp['code'] = $info['code'];
  417. $temp['contactor'] = $contactor;
  418. $temp['mobile'] = $mobile;
  419. $temp['position'] = $position;
  420. $temp['email'] ="";
  421. $temp['is_del'] = 0;
  422. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  423. $temp['updatetime'] = date("Y-m-d H:i:s");
  424. $vp = Db::name('supplier_contact')->save($temp);
  425. if ($vp == "") {
  426. Db::rollback();
  427. return error_show(1002, "更新失败");
  428. }
  429. Db::commit();
  430. return error_show(0,"编辑成功") ;
  431. }else{
  432. Db::rollback();
  433. return error_show(1002,"编辑失败");
  434. }
  435. }catch (\Exception $e) {
  436. Db::rollback();
  437. return error_show(1003, $e->getMessage());
  438. }
  439. }
  440. public function info(){
  441. $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
  442. if($id ==""){
  443. return error_show(1002,"参数id不能为空");
  444. }
  445. $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  446. if($info==""){
  447. return error_show(1002,"未找到数据");
  448. }
  449. $contact = Db::name("supplier_contact")->where(["code"=>$info['code'],"is_del"=>0])->find();
  450. $info['contactor']=isset($contact['contactor'])? $contact['contactor']:"";
  451. $info['mobile']=isset($contact['mobile'])? $contact['mobile']:"";
  452. $info['position']=isset($contact['position'])? $contact['position']:"";
  453. $info['email']=isset($contact['email'])? $contact['email']:"";
  454. $info['supplier_img']=isset($info['license_img'])? $info['license_img']:"";
  455. return app_show(0,"获取成功",$info);
  456. }
  457. public function del(){
  458. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  459. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  460. if($sup==false){
  461. return error_show(1002,"供应商信息不存在");
  462. }
  463. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  464. if($supp){
  465. return error_show(0,"删除成功");
  466. }else{
  467. return error_show(1002,"删除失败");
  468. }
  469. }
  470. public function status(){
  471. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  472. if($id==""){
  473. return error_show(1002,"参数id不能为空");
  474. }
  475. $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  476. if(!$info){
  477. return error_show(1002,"未找到对应数据");
  478. }
  479. $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  480. if($status===""){
  481. return error_show(1002,"参数status不能为空");
  482. }
  483. if(!in_array($status,[0,1,2])){
  484. return error_show(1002,"参数status无效");
  485. }
  486. $info['status']=$status;
  487. $info['updatetime']=date("Y-m-d H:i:s");
  488. $msg = $status==1?"启用":"禁用";
  489. $update = Db::name("supplier")->save($info);
  490. return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  491. }
  492. }