Suppler.php 27 KB

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