Suppler.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. $code = rand(0000,9999);
  25. $str = sprintf("%04d",$code);
  26. $tr="GYS-".date("Ymd")."-".$str;
  27. $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :"";
  28. if($source===""){
  29. return error_show(1002,"供应商来源不能为空");
  30. }
  31. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  32. if($token==''){
  33. return error_show(1005,"参数token不能为空");
  34. }
  35. $user =GetUserInfo($token);
  36. if(empty($user)||$user['code']!=0){
  37. return error_show(1002,"创建人数据不存在");
  38. }
  39. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  40. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  41. $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
  42. if($personid==""){
  43. return error_show(1002,"参数personid不能为空");
  44. }
  45. $to= GetInfoById($token,['id'=>$personid]);
  46. if(empty($to)||$to['code']!=0){
  47. return app_show(1002,"负责人信息不存在");
  48. }
  49. $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  50. $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :"";
  51. if($type===""){
  52. return error_show(1002,"申请类型不能为空");
  53. }
  54. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):"";
  55. if($coop_state===""){
  56. return error_show(1002,"参数coop_state不能为空");
  57. }
  58. $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):"";
  59. if($category===""){
  60. return error_show(1002,"参数category不能为空");
  61. }
  62. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):"";
  63. if($delivery_way===""){
  64. return error_show(1002,"参数delivery_way不能为空");
  65. }
  66. $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
  67. if($level===""){
  68. return error_show(1002,"参数level不能为空");
  69. }
  70. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):"";
  71. if($supplier_type===""){
  72. return error_show(1002,"参数supplier_type不能为空");
  73. }
  74. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):"";
  75. if($pay_type===""){
  76. return error_show(1002,"参数pay_type不能为空");
  77. }
  78. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  79. if($prove_img==""){
  80. return error_show(1002,"参数prove_img不能为空");
  81. }
  82. // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  83. // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  84. $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :"";
  85. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  86. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :"";
  87. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  88. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  89. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  90. $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  91. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  92. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  93. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  94. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  95. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  96. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  97. $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  98. $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"0";
  99. //$registertime= isset($this->post['registertime']) && $this->post['registertime']!==""?
  100. // $this->post['registertime'] :"";
  101. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  102. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  103. if($contactor==""){
  104. return error_show(1002,"参数contactor不能为空");
  105. }
  106. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  107. if($mobile==""){
  108. return error_show(1002,"参数mobile不能为空");
  109. }
  110. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  111. if($position==""){
  112. return error_show(1002,"参数position不能为空");
  113. }
  114. if($registercode==""){
  115. return error_show(1002,"参数registercode不能为空");
  116. }
  117. Db::startTrans();
  118. try{
  119. $data=[
  120. "name"=>$name,
  121. "source"=>$source,
  122. "coop_state"=>$coop_state,
  123. "category"=>$category,
  124. "delivery_way"=>$delivery_way,
  125. "level"=>$level,
  126. "supplier_type"=>$supplier_type,
  127. "pay_type"=>$pay_type,
  128. "registercode"=>$registercode,
  129. "capital"=>$capital,
  130. "product_category"=>$product_category,
  131. "is_payment"=>$is_payment,
  132. "notice_mark"=>$notice_mark,
  133. "agreement"=>$agreement,
  134. "warehouse"=>$warehouse,
  135. "pay_day"=>$pay_day,
  136. "scope"=>$scope,
  137. "status"=>$status,
  138. "code"=>$tr,
  139. "type"=>$type,
  140. "nature"=>$nature,
  141. "legaler"=>$legaler,
  142. "addr"=>$addr,
  143. "is_del"=>0,
  144. "remark"=>'',
  145. "ticket_type"=>$ticket_type,
  146. "addtime"=>date('Y-m-d H:i:s'),
  147. "updatetime"=>date("Y-m-d H:i:s"),
  148. "is_platform"=>$is_platform,
  149. "prove_img"=>$prove_img,
  150. "license_img"=>$supplier_img,
  151. "creater"=>$creater,
  152. "createrid"=>$createrid,
  153. "registertime"=>date('Y-m-d H:i:s'),
  154. "person"=>$person,
  155. "personid"=>$personid,
  156. ];
  157. if($supplier_img!==""){
  158. $ocr=new Ocr();
  159. $datwa = $ocr->query("",$supplier_img);
  160. // var_dump($data);
  161. if($datwa['code']==0 && isset($datwa['data']['result'])){
  162. $license = $datwa['data']['result'];
  163. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  164. $data['addr']= isset($license['address'])?$license['address']:"";
  165. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  166. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  167. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  168. $data['nature']= isset($license['type'])?$license['type']:"";
  169. $data['status']=1;
  170. if($name!=$license['name']){
  171. $data['remark']="企业名称与营业执照不匹配";
  172. $data['status']=0;
  173. }
  174. if($registercode!=$license['registration_number']){
  175. $data['remark'].="企业名称与营业执照不匹配";
  176. $data['status']=0;
  177. }
  178. }else{
  179. $data['remark']="营业执照识别失败";
  180. $data['status']=0;
  181. }
  182. }
  183. $join = Db::name('supplier')->insert($data,true);
  184. if($join>0){
  185. $temp = [];
  186. $temp['code']=$tr;
  187. $temp['contactor'] =$contactor;
  188. $temp['mobile'] = $mobile;
  189. $temp['position'] = $position;
  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. }