Suppler.php 28 KB

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