12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- use app\admin\model\DataGroup as DataGroupModel;
- class SupplierClient extends Base {
- public function __construct(App $app) {parent::__construct($app);}
- /**供应商销售单列表
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function cgdlist(){
- $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 = [['po.is_del', "=", 0]];
- $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
- if($bkcode!==""){
- $where[]=['po.bkcode',"like", "%{$bkcode}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]=['po.status',"=", $status];
- }
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']) :"";
- if($cgdNo!==""){
- $where[]=['po.cgdNo',"like", "%{$cgdNo}%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
- if($apply_name!==""){
- $where[]=['po.cgder',"like", "%{$apply_name}%"];
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!==""){
- $where[]=['po.wsm_code',"=", $wsm_code];
- }
- $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
- if($wsm_in_code!==""){
- $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
- if(empty($incode)){
- return error_show(1004,"未找到有关入库单信息");
- }
- $where[]=['po.cgdNo',"in", $incode];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
- if($good_name!==""){
- $where[]=['po.good_name',"like", "%{$good_name}%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']) :"";
- if($good_code!==""){
- $where[]=['po.spuCode',"like", "%{$good_code}%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo']) :"";
- if($supplierNo!==""){
- $where[]=['po.supplierNo',"=", $supplierNo];
- }
- $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo']) :"";
- if($wsm_supplierNo!==""){
- $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$wsm_supplierNo])->column("wsm_code");
- $where[]=['po.wsm_code',"in", $wsmcode];
- }
- $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
- if($start!==""){
- $where[]=['po.addtime',">=", $start." 00:00:00"];
- }
- $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
- if($end!==""){
- $where[]=['po.addtime',"<=", $end." 23:59:59"];
- }
- $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
- if($last_start!==""){
- $where[]=['po.lasttime',">=", $last_start." 00:00:00"];
- }
- $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
- if($last_end!==""){
- $where[]=['po.lasttime',"<=", $last_end." 23:59:59"];
- }
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ?$this->post['orderCode']:"";
- if($orderCode!==""){
- $where[]=['on.orderCode',"like", '%'.$orderCode.'%'];
- }
- //筛选供应商名称
- $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] != "" ? $this->post['supplier_name'] : "";
- if ($supplier_name != '') $where[] = ['po.supplier_name', 'like', '%' . $supplier_name . '%'];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo !== "") $where[] = ['po.companyNo', '=', $relaComNo];
- $companyNo = $this->post['companyNo']??'';
- if($companyNo!='') $where[]=['po.companyNo','like','%'.$this->post['companyNo']. '%'];
- $userCommon = \app\admin\common\User::getIns();
- // //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $supplierNos = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $where[] = ['po.supplierNo', 'in', $supplierNos];
- }
- if ($relaComNo !== "") $where[] = ['po.companyNo', '=', $relaComNo];
- }
- if ($this->level == 3) {
- if ($relaComNo !== "") $where[] = ['po.supplierNo', '=', $relaComNo];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["po.cgder_id", 'in', get_company_item_user_by_name($company_name)];
- $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "";
- if ($order_type !== "") $where[] = ["po.order_type", '=', $order_type];
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ["po.order_source", '=', $order_source];
- $count = Db::name("purchease_order")
- ->alias('po')
- ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
- // ->leftJoin("depart_user u", "u.uid=po.cgder_id AND u.is_del=0")
- ->where($where)
- ->where(function ($query) use ($where) {
- $query->whereOr([['po.order_type', '<>', 1], ['po.order_source', '=', 0]]);
- })->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name("purchease_order")
- ->alias('po')
- ->leftJoin('order_num on','on.cgdNo=po.cgdNo')
- ->field('po.*,on.orderCode,"" supplier_cgderid,"" supplier_cgder')
- ->where($where)
- ->where(function($query) use ($where){$query->whereOr([['po.order_type', '<>', 1],['po.order_source', '=', 0]]);})
- ->page($page,$size)
- ->order("po.addtime desc")
- ->select()
- ->toArray();
- $account = checkHasAccountBySupplierNos(array_column($list,'supplierNo'));
- $all_createrid = array_column($list,'cgder_id');
- $item = get_company_name_by_uid($all_createrid);
- $data=[];
- $wsmCodes = array_column($list, 'wsm_code');
- $wsmcode = Db::name("warehouse_info")
- ->alias("a")
- ->where(["a.wsm_code" => $wsmCodes])
- ->column("a.name as wsm_name,a.supplierNo as code", "wsm_code");
- $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($wsmcode,"code"),array_column($list,"companyNo")))]);
- $person_list = $userCommon->handle('sGetList', ['more_code' => array_unique(array_column($list, 'supplierNo')), 'size' => $size]);
- $person_list = array_column($person_list['data']['list'], null, 'code');
- foreach ($list as $value){
- $value['wsm_name'] = $value['wsm_code'] != '' ? $wsmcode[$value['wsm_code']]['wsm_name'] ?? '' : "";
- $value['wsm_supplier'] = $value['wsm_code'] != '' ? $person_list[$wsmcode[$value['wsm_code']]['code']]['name'] ?? "" : '';
- $value['wsm_supplierNo'] = $value['wsm_code'] != '' ? $wsmcode[$value['wsm_code']]['code'] ?? "" : '';
- $value['supplier_cgderid'] = $person_list[$value['supplierNo']]['personid'] ?? '';
- $value['supplier_cgder'] = $person_list[$value['supplierNo']]['person'] ?? '';
- $value['companyName'] = $names['data'][$value['companyNo']] ?? '';
- if($value['order_type']==3 || $value['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
- $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
- //为了格式统一,缺了一个spec_value
- if ($value['speclist'] != '') {
- foreach ($value['speclist'] as &$v) {
- $v['spec_value'] = $v['spec_value_name'];
- }
- }
- }else {
- $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
- $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
- $speclist=[];
- if(!empty($spec)){
- foreach ($spec as $val){
- $temp=[];
- $temp['id']=$val['id'];
- $temp['spuCode']=$val['spuCode'];
- $temp['spec_id']=$val['spec_id'];
- $temp['spec_value_id']=$val['spec_value_id'];
- $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
- $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
- $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
- $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
- $speclist[]=$temp;
- }
- }
- $value["speclist"]=empty($speclist)?[]:$speclist;
- }
- $inorder= Db::name("purchease_in")
- ->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])
- ->select()
- ->toArray();
- $value['child']=empty($inorder)? [] : $inorder;
- $value['send_num'] -=$value['th_num'];
- $value['total_fee'] =round($value['total_fee']-$value['th_fee'],2);
- $value['company_name'] = $item[$value['cgder_id']]??'';
- $value['has_account'] = (int)isset($account[$value['supplierNo']]);
- $data[]=$value;
- }
- return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
- }
- /**供应商入库单
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function cgdInList(){
- $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],['b.is_del',"=",0]];
- $wsm_in_code=isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!==""? trim($this->post['wsm_in_code']) :"";
- if($wsm_in_code!==""){
- $where[]=["a.wsm_in_code",'like',"%$wsm_in_code%"];
- }
- $cgdNo= isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :"";
- if($cgdNo!==""){
- $where[]=['a.cgdNo','like',"%$cgdNo%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? trim($this->post['apply_name']):"";
- if($apply_name!==""){
- $where[]=['a.apply_name','like',"%$apply_name%"];
- }
- $apply_id= isset($this->post['apply_id']) && $this->post['apply_id'] !==""? trim($this->post['apply_id']):"";
- if($apply_id!==""){
- $where[]=['a.apply_id','=',$apply_id];
- }
- $status= isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"";
- if($status!==""){
- $where[]=['a.status','=',$status];
- }
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !=="") {
- $where[]= ["a.sendtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !==""){
- $where[]= ["a.sendtime",'<=',$end];
- }
- $order_type=isset($this->post['order_type']) && $this->post['order_type']!==""? intval($this->post['order_type']):"";
- if($order_type !==""){
- $where[]= ["b.order_type",'=',$order_type];
- }
- $order_source=isset($this->post['order_source']) && $this->post['order_source']!==""? intval($this->post['order_source']):"";
- if($order_source !=="") $where[]= ["b.order_source",'=',$order_source];
- $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
- if($good_type_code !==""){
- $where[]= ["b.spuCode",'like',"%$good_type_code%"];
- }
- $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
- if($good_name !==""){
- $where[]= ["b.good_name",'like',"%$good_name%"];
- }
- $supplie=isset($this->post['supplier']) && $this->post['supplier']!==""? trim($this->post['supplier']):"";
- if($supplie !==""){
- $where[]= ["b.supplier_name",'like',"%$supplie%"];
- }
- $wsm_code=isset($this->post['wsm_code']) && $this->post['wsm_code']!==""? trim($this->post['wsm_code']):"";
- if($wsm_code !==""){
- $where[]= ["a.wsm_code",'=',$wsm_code];
- }
- $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($supplierNo!==""){
- $where[]= ["b.supplierNo",'=',$supplierNo];
- }
- $condition=[];
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if($this->level==2){
- if($relaComNo!=='') $where[]=['b.companyNo','=', $relaComNo];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- if($arr){
- $sys_supplier = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del'=>0,'personid'=>$arr])
- ->column('code');
- $condition[] = ["b.supplierNo", "in", $sys_supplier];
- }
- $condition[] = ["a.apply_id", "in", $hand];
- $condition[] = ["c.contactor", "in", $hand];
- }
- }
- if($this->level==3){
- if($relaComNo!=='') $where[]=['b.supplierNo','=', $relaComNo];
- }
- $companyNo = $this->post['companyNo']??'';
- if($companyNo!='') $where[]=['b.companyNo','like','%'.$this->post['companyNo']. '%'];
- $count = Db::name('purchease_in')
- ->alias('a')
- ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
- ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code")
- ->where($where)
- ->where(function ($query)use ($condition){$query->whereOr($condition);})
- ->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('purchease_in')
- ->alias('a')
- ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
- ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code")
- ->where($where)
- ->where(function ($query)use ($condition){$query->whereOr($condition);})
- ->page($page,$size)
- ->field("a.apply_name,a.sendtime,b.order_type,b.order_source,a.status,a.cgdNo,a.wsm_in_code,a.send_num,a.wsm_code,b.good_name,b.spuCode,a.post_company,a.post_code,a.post_fee,a.apply_id,a.wsm_num,a.error_num,a.wait_num,a.status,a.check_name,a.checkid,b.bkcode,b.supplierNo,'' cgder_id,'' cgder,b.good_createrid,b.good_creater,c.name wsm_name,b.supplierNo,b.supplier_name,c.supplierNo wsm_supplierNo,b.companyNo")
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- //获取采购单供应商和仓库供应商的名称
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_merge(array_column($list,'companyNo'),array_column($list,'wsm_supplierNo')))]);
- $all_supplier = $userCommon->handle('sGetList',['more_code'=>array_column($list,'supplierNo'),'page'=>1,'size'=>$size]);
- $all_supplier_list = array_column($all_supplier['data']['list'],null,'code');
- $data=[];
- foreach ($list as $value){
- $value['cgder_id'] = $all_supplier_list[$value['supplierNo']]['personid']??'';
- $value['cgder'] = $all_supplier_list[$value['supplierNo']]['person']??'';
- //获取规格、品牌信息
- if ($value['order_type'] == 3 ||$value['order_type']==4) {
- $temp = Db::name('good_zixun')
- ->alias('gz')
- ->field('gz.specinfo,b.brand_name')
- ->join('brand b', 'b.id=gz.brand_id')
- ->where(['gz.spuCode' => $value['spuCode'], 'gz.is_del' => 0])
- ->find();
- $value["brand_name"] = $temp['brand_name'];
- $value["speclist"] = json_decode($temp['specinfo'], true);
- } else {
- $value['brand_name'] = Db::name('good_basic')
- ->alias('gb')
- ->join('brand b', 'b.id=gb.brand_id')
- ->where(['gb.spuCode' => $value['spuCode']])
- ->value('b.brand_name');
- $spec = Db::name("good_spec")
- ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
- ->select()
- ->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $temp = [];
- $temp['id'] = $val['id'];
- $temp['spuCode'] = $val['spuCode'];
- $temp['spec_id'] = $val['spec_id'];
- $temp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $temp;
- }
- }
- $value["speclist"] = empty($speclist) ? [] : $speclist;
- }
- $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']]??'';
- $value['companyName'] = $names['data'][$value['companyNo']]??'';
- $value['company_name'] = $item[$value['apply_id']]??'';
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- /** 采购端退货列表
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function returnList(){
- $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],['b.is_del',"=",0]];
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
- if($cgdNo!=""){
- $where[]=['a.cgdNo',"like", "%$cgdNo%"];
- }
- $returnCode= isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($returnCode!=""){
- $where[]=['a.returnCode',"like", "%$returnCode%"];
- }
- $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
- if($good_type_code !=""){
- $where[]= ["b.spuCode",'like',"%$good_type_code%"];
- }
- $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
- if($good_name !=""){
- $where[]= ["b.good_name",'like',"%$good_name%"];
- }
- $status=isset($this->post['status']) && $this->post['status']!==""? trim($this->post['status']):"";
- if($status!=""){
- $where[]= ["a.status",'=',$status];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo != '') $where[] = ['b.supplierNo', '=', $supplierNo];
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
- if ($companyNo != '') $where[] = ['b.companyNo', '=', $companyNo];
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
- if ($order_source != '') $where[] = ['b.order_source', '=', $order_source];
- $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
- if ($is_stock != '') $where[] = ['c.is_stock', '=', $is_stock];
- // $role = $this->checkDataShare();
- // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["a.apply_id", "in", $role[DataGroupModel::$type_全部]];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $where[] = ['a.apply_id', 'in', $arr];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del'=>0,'personid'=>$arr])
- ->column('code');
- $condition[] = ["b.supplierNo", "in", $code];
- }
- if($relaComNo!='') $where[]=['b.companyNo','=', $relaComNo];
- }
- if($this->level==3){
- if($relaComNo!='') $where[]=['b.supplierNo','=', $relaComNo];
- }
- $count = Db::name('purchease_return')
- ->alias('a')
- ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
- ->leftJoin("good_basic c","c.spuCode=b.spuCode")
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('purchease_return')
- ->alias('a')
- ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
- ->leftJoin("good_basic c","c.spuCode=b.spuCode")
- ->where($where)
- ->page($page,$size)
- ->field("a.*,b.spuCode,b.good_price,b.order_type,b.good_price,b.total_fee,b.good_name,b.order_source,c.is_stock,b.supplierNo,b.supplier_name,b.companyNo")
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- $data=[];
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_column($list,'companyNo'))]);
- foreach ($list as $value){
- if($value['order_type']==3 ||$value['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
- }else {
- $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
- }
- $value['can']= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- $value['return_fee']= round($value['good_price']*$value['return_num'],2);
- $value['companyName'] = $names['data'][$value['companyNo']]??'';
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- /**供应商端公差单列表
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function difflist(){
- $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]];
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
- if($cgdNo!=""){
- $where[]=['a.cgdNo',"like", "%$cgdNo%"];
- }
- $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];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
- if($apply_name!==""){
- $where[]=['a.apply_name',"like","%$apply_name%"];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
- $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ['c.order_source', "=", $order_source];
- $is_stock = $order_source = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
- if ($is_stock !== "") $where[] = ['b.is_stock', "=", $is_stock];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if ($this->level == 2) {
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $where[] = ['a.apply_id', 'in', $arr];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del'=>0,'personid'=>$arr])
- ->column('code');
- $condition[] = ["a.supplierNo", "in", $code];
- }
- if($relaComNo!='') $where[]=['c.companyNo','=', $relaComNo];
- }
- if($this->level==3){
- if($relaComNo!='') $where[]=['c.supplierNo','=', $relaComNo];
- }
- $companyNo = $this->post['companyNo']??'';
- if($companyNo!='') $where[]=['a.companyNo','like', '%'.$this->post['companyNo']. '%'];
- $count = Db::name('purchease_diff')
- ->alias('a')
- ->leftJoin("good b","b.spuCode=a.good_code")
- ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
- ->where($where)
- ->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('purchease_diff')
- ->alias('a')
- ->leftJoin("good b","b.spuCode=a.good_code")
- ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
- ->where($where)
- ->page($page,$size)
- ->order("a.addtime desc")
- ->field("a.*,b.cat_id,c.order_source,b.is_stock")
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $value['company_name'] = $item[$value['apply_id']]??'';
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- //发货申请单列表
- public function orderOut()
- {
- $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]];
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode !== "") {
- $where[] = ['a.orderCode', "like", "%$orderCode%"];
- }
- $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
- if ($order_type !== "") {
- $where[] = ['a.order_type', "=", $order_type];
- }
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if ($outCode !== "") {
- $where[] = ['a.outCode', "like", "%$outCode%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
- if ($apply_name !== "") {
- $where[] = ['a.apply_name', "like", "%$apply_name%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code !== "") {
- $where[] = ['b.good_code', "like", "%$good_code%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name !== "") {
- $where[] = ['b.good_name', "like", "%$good_name%"];
- }
- $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
- if ($supplier_name !== "") {
- $where[] = ['wpo.supplier_name', "like", "%$supplier_name%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($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 . " 00:00:00"];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo != "") {
- $where[] = ['b.supplierNo', "like", "%$companyNo%"];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo != '') {
- //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
- //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
- // $spuCode = Db::name('good_basic')
- // ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
- // ->column('spuCode');
- $where[] = ['b.supNo', 'like', "%$supplierNo%"];
- }
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
- if ($cgdNo != "") {
- $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
- }
- $condition = '';
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $uidarr = implode(",", $hand);
- //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
- if (!in_array($this->roleid, [1, 33])) {
- //库管看到所有的库存品发货申请单
- if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
- else {
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- if ($condition != '') $condition .= " or ";
- $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
- }
- }
- if (!empty($hand)) {
- if ($condition != '') $condition .= " or ";
- $person_supplier = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del'=>0,'personid'=>$uidarr])
- ->column('code');
- $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
- }
- }
- if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
- }
- //供应商账号只能看到非库存品的订单
- if ($this->level == 3){
- $where[] = ['b.supNo', '=', $relaComNo];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
- //发货时间筛选
- $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
- $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
- if ($start_sendtime != "" && $end_sendtime != "") {
- $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
- $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
- }
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
- $use_type = $this->post['use_type']??'';
- if($use_type!=='') $where[]=['p.use_type','=',$use_type];
- $count = Db::name('order_out')
- ->alias('a')
- ->join("sale b", "b.orderCode=a.orderCode", "left")
- ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
- ->leftJoin("order_send os", "os.outCode=a.outCode")
- ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
- ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
- ->where($where)
- ->where($condition)
- ->count('a.id');
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('order_out')
- ->alias('a')
- ->join("sale b", "b.orderCode=a.orderCode", "left")
- ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
- ->leftJoin("order_send os", "os.outCode=a.outCode")
- ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
- ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
- ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.customer_code,b.supplierNo companyNo,b.supplierName companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,wpo.supplierNo,n.supplierNo wsm_supplierNo,p.use_type")
- ->where($where)
- ->where($condition)
- ->order(["addtime" => "desc", 'id' => 'desc'])
- ->page($page, $size)
- ->select()
- ->toArray();
- $all_createrid = array_column($list, 'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- $user = \app\admin\common\User::getIns();
- $names = $user->handle("getCodeAndName", ["code" => array_merge(array_column($list, "supplierNo"), array_column($list, "customer_code"), array_column($list, "wsm_supplierNo"))]);
- $data = [];
- foreach ($list as $value) {
- // $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
- if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
- $value['wsm_supplierNo'] = $value['supplierNo'];
- $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
- } else {
- $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
- }
- $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
- if ($addr) {
- $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
- if (is_string($addinfo) && $addinfo != '') {
- $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
- list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
- }
- $addr['addr_cn'] = GetAddr(json_encode($addinfo));
- }
- if (in_array($value['order_type'], [3, 4])) {
- $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
- } else {
- $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
- }
- $value['wsm_has_account'] = 0;
- $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
- $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $value['company_name'] = $item[$value['apply_id']] ?? '';
- $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- //售后申请单列表
- public function afterList()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 10,
- 'relaComNo' => '',
- 'returnCode' => '',
- 'outCode' => '',
- 'status' => '',
- 'order_type' => '',
- 'orderCode' => '',
- 'good_code' => '',
- 'good_name' => '',
- 'except_code' => '',
- 'apply_name' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',//部门名称
- 'supplierNo' => '',
- 'customer_code' => '',
- 'companyNo' => '',
- 'order_source' => '',
- 'use_type' => '',
- ], 'post', 'trim');
- $where = [['a.is_del', "=", 0]];
- if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
- if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
- if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
- if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
- if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
- if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
- if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
- if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
- if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
- if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
- if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
- if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
- if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['relaComNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['use_type'] !== "") $where[] = ['p.use_type', "=", $param['use_type']];
- $condition = [];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ["a.person_id", "in", $hand];
- $condition[] = ["a.apply_id", "in", $arr];
- $condition[] = ["a.cgderid", "in", $hand];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $where[] = ['a.supplierNo', 'in', $code];
- }
- // if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
- }
- //level3账号不允许看到库存品订单,暂时该过滤条件废弃
- if ($this->level == 3){
- // $where[] = ['c.supNo', '=', $param['relaComNo']];
- }
- // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
- // .implode(',',$role[DataGroupModel::$type_全部]).")";
- if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
- $count = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->count('a.id');;
- $list = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,c.order_source,p.use_type")
- ->page($param['page'], $param['size'])
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- $all_createrid = array_column($list, 'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- $data = [];
- foreach ($list as $value) {
- $value['company_name'] = $item[$value['apply_id']] ?? '';
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
- }
- /** 售后退货单
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function backlist()
- {
- $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]];
- $thNo = isset($this->post['thNo']) && $this->post['thNo'] != "" ? trim($this->post['thNo']) : "";
- if ($thNo != "") {
- $where[] = ['a.thNo', "like", "%{$thNo}%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- // $where['status'] = $status;
- $where[] = ['a.status', "=", $status];
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
- if ($post_code != "") {
- $where[] = ['a.post_code', "like", "%{$post_code}%"];
- }
- $post_compay = isset($this->post['post_compay']) && $this->post['post_compay'] != "" ? trim($this->post['post_compay']) : "";
- if ($post_compay != "") {
- $where[] = ['a.post_company', "=", $post_compay];
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
- if ($customer_code != "") {
- $where[] = ['a.customer_code', "like", "%{$customer_code}%"];
- }
- $order_code = isset($this->post['order_code']) && $this->post['order_code'] != "" ? trim($this->post['order_code']) : "";
- if ($order_code != "") {
- $where[] = ['a.orderCode', "like", "%{$order_code}%"];
- }
- $out_code = isset($this->post['out_code']) && $this->post['out_code'] != "" ? trim($this->post['out_code']) : "";
- if ($out_code != "") {
- $where[] = ['a.outCode', "like", "%{$out_code}%"];
- }
- $return_code = isset($this->post['return_code']) && $this->post['return_code'] != "" ? trim($this->post['return_code']) : "";
- if ($return_code != "") {
- $where[] = ['a.returnCode', "like", "%{$return_code}%"];
- }
- $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];
- }
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
- if ($order_source !== "") {
- $where[] = ['b.order_source', "=", $order_source];
- }
- $supplierNo = trim($this->post['supplierNo'] ?? '');
- if ($supplierNo !== '') $where[] = ['a.supplierNo', 'like', '%'.$supplierNo.'%'];
- $companyNo = trim($this->post['companyNo'] ?? '');
- if ($companyNo !== '') $where[] = ['a.companyNo', 'like', '%'.$companyNo.'%'];
- $relaComNo = trim($this->post['relaComNo'] ?? '');
- if ($relaComNo !== '') $where[] = ['a.companyNo', 'like', '%'.$relaComNo.'%'];
- $condition = [];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ['a.apply_id', 'in', $arr];
- $condition[] = ['a.cgderid', 'in', $hand];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $where[] = ['a.supplierNo', 'in', $code];
- }
- // if ($relaComNo != "") $where[] = ['b.supplierNo', '=', $relaComNo];
- }
- //供应商账号不允许看到库存品数据
- // if ($this->level == 3) {
- // $where[] = ['b.supNo', '=', $relaComNo];
- // }
- $count = Db::name("order_back")
- ->alias('a')
- ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->count('a.id');
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name("order_back")
- ->alias('a')
- ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->field('a.*,b.order_source')
- ->page($page, $size)
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- $data = [];
- $all_wsm = Db::name("warehouse_info")
- ->alias("a")
- ->where(["a.wsm_code" => array_column($list, 'return_wsm')])
- ->column("a.name,a.supplierNo", 'a.wsm_code');//b.name,b.code
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($all_wsm, 'supplierNo'))]);
- foreach ($list as $value) {
- $value['wsm_name'] = "";
- $value['wsm_supplier'] = '';
- $value['wsm_supplierNo'] = '';
- if ($value['return_wsm'] != "") {
- $value['wsm_name'] = $all_wsm[$value['return_wsm']]['name'] ?? '';//isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $value['wsm_supplier'] = $names['data'][$all_wsm[$value['return_wsm']]['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name']:"";
- $value['wsm_supplierNo'] = $all_wsm[$value['return_wsm']]['supplierNo'];//isset($wsmcode['code']) ? $wsmcode['code']:"";
- }
- $inorder = Db::name("order_backinfo")
- ->where(['thNo' => $value['thNo'], "is_del" => 0])
- ->select()
- ->toArray();
- $value['child'] = empty($inorder) ? [] : $inorder;
- $data[] = $value;
- }
- return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
- }
- //退货单列表
- public function reorderlist(){
- $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 =[['sr.is_del',"=",0]];
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode!=""){
- $where[]=['sr.returnCode',"like", "%{$bkcode}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]=['sr.status',"=", $status];
- }
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']) :"";
- if($orderCode!=""){
- $where[]=['sr.orderCode',"like", "%{$orderCode}%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']) :"";
- if($apply_name!=""){
- $where[]=['sr.apply_name',"like", "%{$apply_name}%"];
- }
- $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
- if($start!==""){
- $where[]=['sr.addtime',">=", $start.' 00:00:00'];
- }
- $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
- if($end!==""){
- $where[]=['sr.addtime',"<=", $end.' 23:59:59'];
- }
- //商品成本编码搜索
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] != "" ? trim($this->post['good_code']) : "";
- if ($good_code != "") {
- $where[] = ['sr.good_code', "like", "%{$good_code}%"];
- }
- //商品上线编码搜索
- $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
- if ($skuCode != "") {
- $where[] = ['b.skuCode', "like", "%{$skuCode}%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo !== "") $where[] = ['b.supNo', "like", '%' . $supplierNo . '%'];
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") $where[] = ['sr.companyNo', "like", '%' . $companyNo . '%'];
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
- if ($customer_code !== "") $where[] = ['sr.customer_code', "like", '%' . $customer_code . '%'];
- $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ['b.order_source', "=", $order_source];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
- $condition=[];
- //只有level2的账号过滤数据权限
- if ($this->level == 2) {
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- // $uidim =implode(",",$hand);
- // $condition .= "sr.cgderid in ($uidim) or sr.person_id in ($uidim) or sr.apply_id in (" . implode(',',$arr) .
- // ")";
- $condition[] = ["sr.apply_id", "in", $arr];
- $condition[] = ["sr.cgderid", "in", $hand];
- $condition[] = ["sr.person_id", "in", $hand];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $where[] = ['sr.supplierNo', 'in', $code];
- }
- // if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
- }
- //供应商账号不允许看到库存品数据
- // if ($this->level == 3){
- // $where[] = ['b.supNo', '=', $relaComNo];
- // }
- if(in_array($this->roleid,config('app.wsm_cgder_role'))){
- $where[]=["b.order_type","=",1];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["sr.apply_id", 'in', get_company_item_user_by_name($company_name)];
- $use_type = $this->post['use_type']??'';
- if($use_type!=='') $where[]=['p.use_type','=',$use_type];
- $count=Db::name("sale_return")
- ->alias('sr')
- ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
- ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query)use ($condition){$query->whereOr($condition);})
- ->count('sr.id');
- $total = ceil($count/$size);
- $page = $total>=$page ? $page :$total;
- $list = Db::name("sale_return")
- ->alias('sr')
- ->field('sr.*,b.skuCode,b.sale_price,b.good_num total_num,b.order_source,p.use_type')
- ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
- ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query)use ($condition){$query->whereOr($condition);})
- ->order("sr.addtime desc")
- ->page($page,$size)
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- $data=[];
- foreach ($list as $value){
- $value['error_msg']='';
- if($value['error_code']!=''){
- $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
- $value['error_msg']= isset($error['result'])?$error['result']:"";
- }
- $value['return_total'] =$value['sale_price']*$value['num'] ;
- $value['company_name'] = $item[$value['apply_id']]??'';
- $data[]=$value ;
- }
- return app_show(0,"获取成功",["count"=>$count,'list'=>$data]);
- }
- }
|