post; $condition = []; $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :""; if($companyNo!=""){ $condition []=["code","=",$companyNo]; } $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :""; if($name!=""){ $condition []=["name|a.contector","like","%{$name}%"]; } $type=isset($post['type'])&&$post['type']!="" ? trim($post['type']) :""; if($type!=""){ $condition []=["type","=",$type]; } $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0; $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10; $count = Db::name("supplier_info")->alias("a") ->leftJoin("company_info b","a.code=b.companyNo and b.is_del=0") ->where($condition)->count(); $total = ceil($count/$size)>1 ? ceil($count/$size) : 1; $page = $page>=$total?intval($total):$page; $list = Db::name("supplier_info")->alias("a") ->leftJoin("company_info b","a.code=b.companyNo and b.is_del=0") ->where($condition) ->page($page,$size)->order("a.id desc") ->field("a.*,b.company_name,company_address,company_license,bankNo,bank_name, b.contector as company_contector,b.mobile as company_mobile,company_img") ->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } /**获取供应商列表 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function SupplierAll() { $post = $this->post; $condition = []; $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :""; if($companyNo!=""){ $condition []=["code","=",$companyNo]; } $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :""; if($name!=""){ $condition []=["name","like","%{$name}%"]; } $type=isset($post['type'])&&$post['type']!="" ? trim($post['type']) :""; if($type!=""){ $condition []=["type","=",$type]; } $list = Db::name("supplier_info")->where($condition)->field("id,code,name,contector,nature,type,mobile,address,post,addtime,LENGTH(name) as weight")->limit(20)->order("weight asc")->select(); return app_show(0,"获取成功",$list); } /** * 获取供应商信息 * * @return \think\Response */ public function SupplierInfo() { $post = $this->post; $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :""; if($sid==""){ return error_show(1002,"参数d不能为空"); } $supplier = Db::name("supplier_info")->where("id","=",$sid)->find(); if($supplier==false){ return error_show(1003,"供应商信息不存在"); } $cgd = Db::name("pay")->where([["supplierNo","=",$supplier['code']],["status","<>",0]]) ->field("id,payNo,pay_fee,wait_fee,status")->select(); $list=["payment"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]],"invoice"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]]]; foreach ($cgd as $key=>$value){ $list['payment']['wait']['total']+= $value['wait_fee']*100; $list['payment']['already']['total']+= $value['pay_fee']*100; $paystage = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',">","4"],['status',"<>","9"]]) ->sum('pay_fee'); $paywait = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',"<","4"], ['status',"<>","9"]]) ->sum('pay_fee'); $list['invoice']['wait']['total']+= $paywait*100; $list['invoice']['already']['total']+= $paystage*100; if($value['status']==2){ $list['payment']['already']["num"]++; }else{ $list['payment']['wait']["num"]++; } } array_walk($list,function (&$v){ $v['wait']['total'] = $v['wait']['total']/100; $v['already']['total'] = $v['already']['total']/100; }); return app_show(0,"获取成功",$list); } /** * 修改供应商信息 * * @param \think\Request $request * @return \think\Response */ public function SupplierSave() { $post = $this->post; $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :""; if($sid==""){ return error_show(1002,"参数d不能为空"); } $supplier = Db::name("supplier_info")->where("id","=",$sid)->find(); if($supplier==false){ return error_show(1003,"供应商信息不存在"); } $name= isset($post['name'])&& $post['name']!="" ? trim($post['name']) :""; if($name==""){ return error_show(1002,"供货商名称不能为空"); } $contector= isset($post['contector'])&& $post['contector']!="" ? trim($post['contector']) :""; if($contector==""){ return error_show(1002,"联系人名称不能为空"); } $mobile= isset($post['mobile'])&& $post['mobile']!="" ? trim($post['mobile']) :""; if($mobile==""){ return error_show(1002,"联系人手机号不能为空"); } if(!checkMobile($mobile)){ return error_show(1002,"联系人手机号格式错误"); } $pay_method= isset($post['pay_method'])&& $post['pay_method']!="" ? trim($post['pay_method']) :""; if($pay_method==""){ return error_show(1002,"结账方式不能为空"); } $paydays= isset($post['paydays'])&& $post['paydays']!="" ? trim($post['paydays']) :""; $return_ticket= isset($post['return_ticket'])&& $post['return_ticket']!="" ? trim($post['return_ticket']) :""; $data=[ "id"=>$supplier['id'], "name"=>$name, "contector"=>$contector, "mobile"=>$mobile, "pay_method"=>$pay_method, "paydays"=>$paydays, "return_ticket"=>$return_ticket, "updatetime"=>date("Y-m-d H:i:s"), ]; $save = Db::name("supplier_info")->save($data); return $save ? app_show(0,"修改成功") :error_show(1003,"修改失败"); } /** * 供应商状态修改 * * @param int $id * @return \think\Response */ public function SupplierStatus() { $post = $this->post; $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :""; if($sid==""){ return error_show(1002,"参数d不能为空"); } $supplier = Db::name("supplier_info")->where("id","=",$sid)->find(); if($supplier==false){ return error_show(1003,"供应商信息不存在"); } $status= isset($post['status'])&& $post['status']!="" ? intval($post['status']) :""; if($status==""){ return error_show(1002,"参数status不能为空"); } $data=[ "id"=>$sid, "status"=>$status, "updatetime"=>date("Y-m-d H:i:s") ]; $udap = DB::name("supplier_ifno")->save($data); return $udap ? app_show(0,"修改成功") :error_show(1003,"修改失败"); } }