post=$this->request->post(); } public function create(){ $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :""; if($name==""){ return error_show(1002,"参数name不能为空"); } $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find(); if (!empty($rename)) { return error_show(1002, "公司名称已存在"); } $tr=makeNo("QS"); $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :""; if($source===""){ return error_show(1002,"供应商来源不能为空"); } $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(1005,"参数token不能为空"); } $user =GetUserInfo($token); if(empty($user)||$user['code']!=0){ return error_show(1002,"创建人数据不存在"); } $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : ""; $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):""; if($personid==""){ return error_show(1002,"参数personid不能为空"); } $to= GetInfoById($token,['id'=>$personid]); if(empty($to)||$to['code']!=0){ return app_show(1002,"负责人信息不存在"); } $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ; $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :""; if($type===""){ return error_show(1002,"申请类型不能为空"); } $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):""; if($coop_state===""){ return error_show(1002,"参数coop_state不能为空"); } $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):""; if($category===""){ return error_show(1002,"参数category不能为空"); } $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):""; if($delivery_way===""){ return error_show(1002,"参数delivery_way不能为空"); } $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):""; if($level===""){ return error_show(1002,"参数level不能为空"); } $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):""; if($supplier_type===""){ return error_show(1002,"参数supplier_type不能为空"); } $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):""; if($pay_type===""){ return error_show(1002,"参数pay_type不能为空"); } $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):""; if($prove_img==""){ return error_show(1002,"参数prove_img不能为空"); } // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :""; // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :""; $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :""; $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0"; $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :""; $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :""; $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :""; $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :""; $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :""; $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :""; $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :""; $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :""; $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :""; $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :""; $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :""; $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :""; $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"0"; //$registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? // $this->post['registertime'] :""; $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):""; $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):""; if($contactor==""){ return error_show(1002,"参数contactor不能为空"); } $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):""; if($mobile==""){ return error_show(1002,"参数mobile不能为空"); } $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):""; $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):""; if($position==""){ return error_show(1002,"参数position不能为空"); } if($registercode==""){ return error_show(1002,"参数registercode不能为空"); } Db::startTrans(); try{ $data=[ "name"=>$name, "source"=>$source, "coop_state"=>$coop_state, "category"=>$category, "delivery_way"=>$delivery_way, "level"=>$level, "supplier_type"=>$supplier_type, "pay_type"=>$pay_type, "registercode"=>$registercode, "capital"=>$capital, "product_category"=>$product_category, "is_payment"=>$is_payment, "notice_mark"=>$notice_mark, "agreement"=>$agreement, "warehouse"=>$warehouse, "pay_day"=>$pay_day, "scope"=>$scope, "status"=>$status, "code"=>$tr, "type"=>$type, "nature"=>$nature, "legaler"=>$legaler, "addr"=>$addr, "is_del"=>0, "remark"=>'', "ticket_type"=>$ticket_type, "addtime"=>date('Y-m-d H:i:s'), "updatetime"=>date("Y-m-d H:i:s"), "is_platform"=>$is_platform, "prove_img"=>$prove_img, "license_img"=>$supplier_img, "creater"=>$creater, "createrid"=>$createrid, "registertime"=>date('Y-m-d H:i:s'), "person"=>$person, "personid"=>$personid, ]; if($supplier_img!==""){ $ocr=new Ocr(); $datwa = $ocr->query("",$supplier_img); // var_dump($data); if($datwa['code']==0 && isset($datwa['data']['result'])){ $license = $datwa['data']['result']; $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:""; $data['addr']= isset($license['address'])?$license['address']:""; $data['registertime']= isset($license['found_date'])? $license['found_date']:""; $data['scope']= isset($license['business_scope'])?$license['business_scope']:""; $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:""; $data['nature']= isset($license['type'])?$license['type']:""; $data['status']=1; if($name!=$license['name']){ $data['remark']="企业名称与营业执照不匹配"; $data['status']=0; } if($registercode!=$license['registration_number']){ $data['remark'].="企业名称与营业执照不匹配"; $data['status']=0; } }else{ $data['remark']="营业执照识别失败"; $data['status']=0; } } $join = Db::name('supplier')->insert($data,true); if($join>0){ $temp = []; $temp['code']=$tr; $temp['contactor'] =$contactor; $temp['mobile'] = $mobile; $temp['position'] = $position; $temp['telephone'] =$telephone; $temp['email'] =""; $temp['is_del'] = 0; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $vp = Db::name('supplier_contact')->insert($temp); if ($vp == "") { Db::rollback(); return error_show(1002, "添加失败"); } Db::commit(); return error_show(0,"添加成功",["id"=>$join]) ; }else{ Db::rollback(); return error_show(1002,"添加失败"); } }catch (\Exception $e) { Db::rollback(); return error_show(1003, $e->getMessage()); } } public function list(){ $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1"; $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10"; $where =[['a.is_del',"=",0]]; $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):""; if($name !==""){ $where[]=["a.name","like","%$name%"]; } $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):""; if($creater !==""){ $where[] = ["a.creater","like","%$creater%"]; } $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):""; if($status!==""){ $where[]= ["a.status","=",$status]; } $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:""; if($start!==""){ $where[]=['a.addtime',">=",$start]; } // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :""; // if($end !=""){ // $where[]=['a.addtime',"<=",$end]; // } $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):""; if($contactor !=""){ $where[]=["b.contactor","like","%$contactor%"]; } $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):""; if($mobile !=""){ $where[] = ['b.mobile',"like","%$mobile%"]; } $count = Db::name('supplier')->alias("a") ->join("supplier_contact b","b.code=a.code","left") ->where($where)->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('supplier')->alias('a') ->join("supplier_contact b","b.code=a.code","left") ->where($where)->page($page,$size)->order("a.addtime desc") ->field("a.*,b.contactor,b.mobile")->select(); return app_show("0","获取成功",['list'=>$list,'count'=>$count]); } public function edit(){ $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(1005,"参数token不能为空"); } $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):""; if($id==""){ return error_show(1002,"参数id不能为空"); } $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find(); if($info==""){ return error_show(1002,"未找到数据"); } if($info['status']==1){ return error_show(1002,"状态是启用状态,无法编辑"); } $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :""; if($source==""){ return error_show(1002,"供应商来源不能为空"); } $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :""; if($type==""){ return error_show(1002,"申请类型不能为空"); } $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):""; if($coop_state==""){ return error_show(1002,"参数coop_state不能为空"); } $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):""; if($category==""){ return error_show(1002,"参数category不能为空"); } $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):""; if($delivery_way==""){ return error_show(1002,"参数delivery_way不能为空"); } $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):""; if($level==""){ return error_show(1002,"参数level不能为空"); } $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):""; if($supplier_type==""){ return error_show(1002,"参数supplier_type不能为空"); } $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):""; if($pay_type==""){ return error_show(1002,"参数pay_type不能为空"); } $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):""; if($prove_img==""){ return error_show(1002,"参数prove_img不能为空"); } $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):""; if($personid==""){ return error_show(1002,"参数personid不能为空"); } $to= GetInfoById($token,['id'=>$personid]); if(empty($to)||$to['code']!=0){ return app_show(1002,"负责人信息不存在"); } $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ; $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :""; if($name==""){ return error_show(1002,"数据标题不能为空"); } $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find(); if (!empty($rename)&&$rename['id']!=$id) { return error_show(1002, "公司名称已存在"); } // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :""; $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0"; $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :""; // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :""; // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :""; $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :""; // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :""; $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :""; $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :""; $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :""; $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :""; $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :""; $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :""; // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :""; //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :""; // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :""; $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):""; $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):""; if($contactor==""){ return error_show(1002,"参数contactor不能为空"); } $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):""; if($mobile==""){ return error_show(1002,"参数mobile不能为空"); } $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):""; if($position==""){ return error_show(1002,"参数position不能为空"); } if($registercode==""){ return error_show(1002,"参数registercode不能为空"); } Db::startTrans(); try{ $data=[ "id"=>$id, "source"=>$source, "name"=>$name, "coop_state"=>$coop_state, "category"=>$category, "delivery_way"=>$delivery_way, "level"=>$level, "supplier_type"=>$supplier_type, "pay_type"=>$pay_type, "registercode"=>$registercode, "product_category"=>$product_category, "is_payment"=>$is_payment, "notice_mark"=>$notice_mark, "agreement"=>$agreement, "warehouse"=>$warehouse, "pay_day"=>$pay_day, "type"=>$type, "license_img"=>$supplier_img, "is_del"=>0, "status"=>$info['license_img']==$supplier_img ? $info['status']:0, "ticket_type"=>$ticket_type, "updatetime"=>date("Y-m-d H:i:s"), "is_platform"=>$is_platform, "prove_img"=>$prove_img, "person"=>$person, "personid"=>$personid, "remark"=>"" ]; if($supplier_img!=="" &&$info['license_img']!=$supplier_img){ $ocr=new Ocr(); $dataw = $ocr->query("",$supplier_img); // var_dump($data); if($dataw['code']==0 && isset($dataw['data']['result'])){ $license = $dataw['data']['result']; $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:""; $data['addr']= isset($license['address'])?$license['address']:""; $data['registertime']= isset($license['found_date'])? $license['found_date']:""; $data['scope']= isset($license['business_scope'])?$license['business_scope']:""; $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:""; $data['nature']= isset($license['type'])?$license['type']:""; $data['status']=1; if($name!=$license['name']){ $data['remark']="企业名称与营业执照不匹配"; $data['status']=0; } if($registercode!=$license['registration_number']){ $data['remark'].="企业名称与营业执照不匹配"; $data['status']=0; } }else{ $data['remark']="营业执照识别失败"; $data['status']=0; } } $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data); if($join){ $item = Db::name('supplier_contact')->where(['code'=>$info['code']])->find(); $temp = []; isset($item['id']) && $item['id'] !== "" ? $temp['id'] =$item['id'] : ''; $temp['code'] = $info['code']; $temp['contactor'] = $contactor; $temp['mobile'] = $mobile; $temp['position'] = $position; $temp['email'] =""; $temp['is_del'] = 0; isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $vp = Db::name('supplier_contact')->save($temp); if ($vp == "") { Db::rollback(); return error_show(1002, "更新失败"); } Db::commit(); return error_show(0,"编辑成功") ; }else{ Db::rollback(); return error_show(1002,"编辑失败"); } }catch (\Exception $e) { Db::rollback(); return error_show(1003, $e->getMessage()); } } public function info(){ $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id ==""){ return error_show(1002,"参数id不能为空"); } $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find(); if($info==""){ return error_show(1002,"未找到数据"); } $contact = Db::name("supplier_contact")->where(["code"=>$info['code'],"is_del"=>0])->find(); $info['contactor']=isset($contact['contactor'])? $contact['contactor']:""; $info['mobile']=isset($contact['mobile'])? $contact['mobile']:""; $info['position']=isset($contact['position'])? $contact['position']:""; $info['email']=isset($contact['email'])? $contact['email']:""; $info['supplier_img']=isset($info['license_img'])? $info['license_img']:""; return app_show(0,"获取成功",$info); } public function del(){ $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :""; $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find(); if($sup==false){ return error_show(1002,"供应商信息不存在"); } $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]); if($supp){ return error_show(0,"删除成功"); }else{ return error_show(1002,"删除失败"); } } public function status(){ $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):""; if($id==""){ return error_show(1002,"参数id不能为空"); } $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find(); if(!$info){ return error_show(1002,"未找到对应数据"); } $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):""; if($status===""){ return error_show(1002,"参数status不能为空"); } if(!in_array($status,[0,1,2])){ return error_show(1002,"参数status无效"); } $info['status']=$status; $info['updatetime']=date("Y-m-d H:i:s"); $msg = $status==1?"启用":"禁用"; $update = Db::name("supplier")->save($info); return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败"); } }