Suppler.php 29 KB

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