123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 |
- <?php
- namespace app\admin\controller;
- use app\admin\common\Ocr;
- use app\admin\model\ChangeLog;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- //供应商
- class Suppler extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->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(105,"参数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']):"";
- // $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']) :"1";
- //$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不能为空");
- }
- 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,
- "code"=>$tr,
- "type"=>$type,
- "nature"=>$nature,
- "legaler"=>$legaler,
- "addr"=>$addr,
- "status"=>1,
- "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);
- 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['registercode']= isset($license['registration_number'])?$license['registration_number']:"";
- $data['ocr_status']=1;
- if($name!=$license['name']){
- $data['remark']="企业名称与营业执照不匹配";
- $data['status']=0;
- $data['ocr_status']=1;
- }
- if($registercode!=$license['registration_number'] && $registercode!=""){
- $data['remark'].="企业名称与营业执照不匹配";
- $data['status']=0;
- $data['ocr_status']=1;
- }
- }else{
- $data['remark']="营业执照识别失败";
- $data['status']=0;
- $data['ocr_status']=2;
- }
- }
- $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 =[['is_del',"=",0]];
- $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
- if($name !==""){
- $where[]=["name","like","%$name%"];
- }
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
- if($creater !==""){
- $where[] = ["creater","like","%$creater%"];
- }
- $person = isset($this->post['person']) && $this->post['person'] !=="" ? trim($this->post['person']):"";
- if($person !==""){
- $where[] = ["person","like","%$person%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]= ["status","=",$status];
- }
- $ocr_status = isset($this->post['ocr_status']) && $this->post['ocr_status'] !=="" ? intval($this->post['ocr_status']):"";
- if($ocr_status!==""){
- $where[]= ["ocr_status","=",$ocr_status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['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[]=["contactor","like","%$contactor%"];
- // }
- // $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
- // if($mobile !=""){
- // $where[] = ['mobile',"like","%$mobile%"];
- // }
- $count = Db::name('supplier')->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();
- $list = Db::name('supplier')->where($where)->page($page,$size)->order("addtime desc")->select();
- $var=[];
- foreach ($list as $value){
- $tem = Db::name('supplier_contact')->where(['code'=>$value['code']])->field("contactor,mobile")->find();
- $iten=[];
- $value['contactor']=$tem['contactor'];
- $value['mobile']=$tem['mobile'];
- $var[]=$value;
- }
- return app_show("0","获取成功",['list'=>$var,'count'=>$count]);
- }
- public function edit(){
- $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数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']):"";
- $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,"负责人信息不存在");
- }
- $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):"";
- $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])->where([["id","<>",$id]])->find();
- if ($rename!=false) {
- 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);
- 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['registercode']=isset($license['registration_number'])? $license['registration_number']:"";//12356
- $data['ocr_status']=1;
- if($name!=$license['name']){
- $data['remark']="企业名称与营业执照不匹配";
- $data['ocr_status']=1;
- }
- if($registercode!=$license['registration_number']&&$registercode!=''){
- $data['remark'].="企业名称与营业执照不匹配";
- $data['ocr_status']=1;
- }
- }else{
- $data['remark']="营业执照识别失败";
- $data['ocr_status']=2;
- }
- }
- $ino = array_diff($data,$info);
- $tem = json_encode($ino,JSON_UNESCAPED_UNICODE);
- $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
- $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
- if($join){
- ChangeLog::logAdd("1",$info['code'],$jsp,$tem,$this->post['token'],$this->post);
- $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['telephone'] = $telephone;
- $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");
- // $st = array_diff($item,$temp);
- // $snm =json_encode($st);
- $vp = Db::name('supplier_contact')->save($temp);
- if ($vp == "") {
- // ChangeLog::logAdd("1",$item['code'],$item,$snm,$this->post['token'],$this->post);
- 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['telephone']=isset($contact['telephone'])? $contact['telephone']:"";
- $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")]);
- $vam = array_diff($sup,$supp);
- $vap = json_encode($vam);
- if($supp){
- ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
- 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}失败");
- }
- }
|