Suppler.php 28 KB

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