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']) :"1";
  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. "remark"=>""
  157. ];
  158. if($supplier_img!==""){
  159. $ocr=new Ocr();
  160. $datwa = $ocr->query("",$supplier_img);
  161. // var_dump($data);
  162. if($datwa['code']==0 && isset($datwa['data']['result'])){
  163. $license = $datwa['data']['result'];
  164. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  165. $data['addr']= isset($license['address'])?$license['address']:"";
  166. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  167. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  168. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  169. $data['nature']= isset($license['type'])?$license['type']:"";
  170. $data['status']=1;
  171. if($name!=$license['name']){
  172. $data['remark']="企业名称与营业执照不匹配";
  173. $data['status']=0;
  174. }
  175. if($registercode!=$license['registration_number']){
  176. $data['remark'].="企业名称与营业执照不匹配";
  177. $data['status']=0;
  178. }
  179. }else{
  180. $data['remark']="营业执照识别失败";
  181. $data['status']=0;
  182. }
  183. }
  184. $join = Db::name('supplier')->insert($data,true);
  185. if($join>0){
  186. $temp = [];
  187. $temp['code']=$tr;
  188. $temp['contactor'] =$contactor;
  189. $temp['mobile'] = $mobile;
  190. $temp['position'] = $position;
  191. $temp['email'] ="";
  192. $temp['is_del'] = 0;
  193. $temp['addtime'] = date("Y-m-d H:i:s");
  194. $temp['updatetime'] = date("Y-m-d H:i:s");
  195. $vp = Db::name('supplier_contact')->insert($temp);
  196. if ($vp == "") {
  197. Db::rollback();
  198. return error_show(1002, "添加失败");
  199. }
  200. Db::commit();
  201. return error_show(0,"添加成功",["id"=>$join]) ;
  202. }else{
  203. Db::rollback();
  204. return error_show(1002,"添加失败");
  205. }
  206. }catch (\Exception $e) {
  207. Db::rollback();
  208. return error_show(1003, $e->getMessage());
  209. }
  210. }
  211. public function list(){
  212. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  213. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  214. $where =[['a.is_del',"=",0]];
  215. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  216. if($name !==""){
  217. $where[]=["a.name","like","%$name%"];
  218. }
  219. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  220. if($creater !==""){
  221. $where[] = ["a.creater","like","%$creater%"];
  222. }
  223. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  224. if($status!==""){
  225. $where[]= ["a.status","=",$status];
  226. }
  227. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  228. if($start!==""){
  229. $where[]=['a.addtime',">=",$start];
  230. }
  231. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  232. // if($end !=""){
  233. // $where[]=['a.addtime',"<=",$end];
  234. // }
  235. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
  236. if($contactor !=""){
  237. $where[]=["b.contactor","like","%$contactor%"];
  238. }
  239. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
  240. if($mobile !=""){
  241. $where[] = ['b.mobile',"like","%$mobile%"];
  242. }
  243. $count = Db::name('supplier')->alias("a")
  244. ->join("supplier_contact b","b.code=a.code","left")
  245. ->where($where)->count();
  246. $total = ceil($count / $size);
  247. $page = $page >= $total ? $total : $page;
  248. $list = Db::name('supplier')->alias('a')
  249. ->join("supplier_contact b","b.code=a.code","left")
  250. ->where($where)->page($page,$size)->order("a.addtime desc")
  251. ->field("a.*,b.contactor,b.mobile")->select();
  252. return app_show("0","获取成功",['list'=>$list,'count'=>$count]);
  253. }
  254. public function edit(){
  255. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  256. if($token==''){
  257. return error_show(1005,"参数token不能为空");
  258. }
  259. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  260. if($id==""){
  261. return error_show(1002,"参数id不能为空");
  262. }
  263. $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
  264. if($info==""){
  265. return error_show(1002,"未找到数据");
  266. }
  267. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  268. if($source==""){
  269. return error_show(1002,"供应商来源不能为空");
  270. }
  271. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  272. if($type==""){
  273. return error_show(1002,"申请类型不能为空");
  274. }
  275. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
  276. if($coop_state==""){
  277. return error_show(1002,"参数coop_state不能为空");
  278. }
  279. $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
  280. if($category==""){
  281. return error_show(1002,"参数category不能为空");
  282. }
  283. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
  284. if($delivery_way==""){
  285. return error_show(1002,"参数delivery_way不能为空");
  286. }
  287. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  288. if($level==""){
  289. return error_show(1002,"参数level不能为空");
  290. }
  291. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
  292. if($supplier_type==""){
  293. return error_show(1002,"参数supplier_type不能为空");
  294. }
  295. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
  296. if($pay_type==""){
  297. return error_show(1002,"参数pay_type不能为空");
  298. }
  299. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  300. if($prove_img==""){
  301. return error_show(1002,"参数prove_img不能为空");
  302. }
  303. $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
  304. if($personid==""){
  305. return error_show(1002,"参数personid不能为空");
  306. }
  307. $to= GetInfoById($token,['id'=>$personid]);
  308. if(empty($to)||$to['code']!=0){
  309. return app_show(1002,"负责人信息不存在");
  310. }
  311. $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  312. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  313. if($name==""){
  314. return error_show(1002,"数据标题不能为空");
  315. }
  316. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  317. if (!empty($rename)&&$rename['id']!=$id) {
  318. return error_show(1002, "公司名称已存在");
  319. }
  320. // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  321. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  322. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  323. // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  324. // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  325. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  326. // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  327. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  328. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  329. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  330. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  331. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  332. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  333. // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  334. //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  335. // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  336. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  337. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  338. if($contactor==""){
  339. return error_show(1002,"参数contactor不能为空");
  340. }
  341. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  342. if($mobile==""){
  343. return error_show(1002,"参数mobile不能为空");
  344. }
  345. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  346. if($position==""){
  347. return error_show(1002,"参数position不能为空");
  348. }
  349. if($registercode==""){
  350. return error_show(1002,"参数registercode不能为空");
  351. }
  352. Db::startTrans();
  353. try{
  354. $data=[
  355. "id"=>$id,
  356. "source"=>$source,
  357. "name"=>$name,
  358. "coop_state"=>$coop_state,
  359. "category"=>$category,
  360. "delivery_way"=>$delivery_way,
  361. "level"=>$level,
  362. "supplier_type"=>$supplier_type,
  363. "pay_type"=>$pay_type,
  364. "registercode"=>$registercode,
  365. "product_category"=>$product_category,
  366. "is_payment"=>$is_payment,
  367. "notice_mark"=>$notice_mark,
  368. "agreement"=>$agreement,
  369. "warehouse"=>$warehouse,
  370. "pay_day"=>$pay_day,
  371. "type"=>$type,
  372. "license_img"=>$supplier_img,
  373. "is_del"=>0,
  374. "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
  375. "ticket_type"=>$ticket_type,
  376. "updatetime"=>date("Y-m-d H:i:s"),
  377. "is_platform"=>$is_platform,
  378. "prove_img"=>$prove_img,
  379. "person"=>$person,
  380. "personid"=>$personid,
  381. "remark"=>""
  382. ];
  383. if($supplier_img!=="" &&$info['license_img']!=$supplier_img){
  384. $ocr=new Ocr();
  385. $dataw = $ocr->query("",$supplier_img);
  386. // var_dump($data);
  387. if($dataw['code']==0 && isset($dataw['data']['result'])){
  388. $license = $dataw['data']['result'];
  389. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  390. $data['addr']= isset($license['address'])?$license['address']:"";
  391. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  392. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  393. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  394. $data['nature']= isset($license['type'])?$license['type']:"";
  395. $data['status']=1;
  396. if($name!=$license['name']){
  397. $data['remark']="企业名称与营业执照不匹配";
  398. $data['status']=0;
  399. }
  400. if($registercode!=$license['registration_number']){
  401. $data['remark'].="企业名称与营业执照不匹配";
  402. $data['status']=0;
  403. }
  404. }else{
  405. $data['remark']="营业执照识别失败";
  406. $data['status']=0;
  407. }
  408. }
  409. $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
  410. if($join){
  411. $item = Db::name('supplier_contact')->where(['code'=>$info['code']])->find();
  412. $temp = [];
  413. isset($item['id']) && $item['id'] !== "" ? $temp['id'] =$item['id'] : '';
  414. $temp['code'] = $info['code'];
  415. $temp['contactor'] = $contactor;
  416. $temp['mobile'] = $mobile;
  417. $temp['position'] = $position;
  418. $temp['email'] ="";
  419. $temp['is_del'] = 0;
  420. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  421. $temp['updatetime'] = date("Y-m-d H:i:s");
  422. $vp = Db::name('supplier_contact')->save($temp);
  423. if ($vp == "") {
  424. Db::rollback();
  425. return error_show(1002, "更新失败");
  426. }
  427. Db::commit();
  428. return error_show(0,"编辑成功") ;
  429. }else{
  430. Db::rollback();
  431. return error_show(1002,"编辑失败");
  432. }
  433. }catch (\Exception $e) {
  434. Db::rollback();
  435. return error_show(1003, $e->getMessage());
  436. }
  437. }
  438. public function info(){
  439. $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
  440. if($id ==""){
  441. return error_show(1002,"参数id不能为空");
  442. }
  443. $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  444. if($info==""){
  445. return error_show(1002,"未找到数据");
  446. }
  447. $contact = Db::name("supplier_contact")->where(["code"=>$info['code'],"is_del"=>0])->find();
  448. $info['contactor']=isset($contact['contactor'])? $contact['contactor']:"";
  449. $info['mobile']=isset($contact['mobile'])? $contact['mobile']:"";
  450. $info['position']=isset($contact['position'])? $contact['position']:"";
  451. $info['email']=isset($contact['email'])? $contact['email']:"";
  452. $info['supplier_img']=isset($info['license_img'])? $info['license_img']:"";
  453. return app_show(0,"获取成功",$info);
  454. }
  455. public function del(){
  456. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  457. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  458. if($sup==false){
  459. return error_show(1002,"供应商信息不存在");
  460. }
  461. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  462. if($supp){
  463. return error_show(0,"删除成功");
  464. }else{
  465. return error_show(1002,"删除失败");
  466. }
  467. }
  468. public function status(){
  469. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  470. if($id==""){
  471. return error_show(1002,"参数id不能为空");
  472. }
  473. $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  474. if(!$info){
  475. return error_show(1002,"未找到对应数据");
  476. }
  477. $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  478. if($status===""){
  479. return error_show(1002,"参数status不能为空");
  480. }
  481. if(!in_array($status,[0,1,2])){
  482. return error_show(1002,"参数status无效");
  483. }
  484. $info['status']=$status;
  485. $info['updatetime']=date("Y-m-d H:i:s");
  486. $msg = $status==1?"启用":"禁用";
  487. $update = Db::name("supplier")->save($info);
  488. return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  489. }
  490. }