Explorar o código

优化GetPart方法,第二阶段

wufeng %!s(int64=2) %!d(string=hai) anos
pai
achega
018b5211c4

+ 1 - 0
app/admin/common/User.php

@@ -71,6 +71,7 @@ class User
         'userp'=>'userp',
         'get_part'=>'get_part',//获取部门名称
         'get_company_name_by_uid'=>'get_company_name_by_uid',//获取某个用户所属部门名称
+        'ciinfo'=>'ciinfo',//获取部门详情
 
     ];
 

+ 9 - 7
app/admin/controller/Activity.php

@@ -81,7 +81,6 @@ class Activity extends Base
 
         $count = Db::name('good_activity')
             ->alias('ga')
-            ->leftJoin("depart_user u", "u.uid=ga.createrid AND u.is_del=0")
             ->leftJoin("platform p", "p.id=ga.platform_code")
             ->where($where)
             ->count();
@@ -89,19 +88,22 @@ class Activity extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('good_activity')
             ->alias('ga')
-            ->field('ga.*,p.platform_name,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=ga.createrid AND u.is_del=0")
+            ->field('ga.*,p.platform_name')
             ->leftJoin("platform p", "p.id=ga.platform_code")
-            ->append(['company_name','is_allow_update'])
-            ->withAttr('company_name',function($val,$data){
-                return implode('/', array_column(GetPart($data['itemid']), 'name'));
-            })->withAttr('is_allow_update',function($val,$data)use($role){
+            ->withAttr('is_allow_update',function($val,$data)use($role){
                 return (in_array($this->roleid, [1, 33]) || in_array($data['createrid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0;//是否具有编辑权限
             })->where($where)
             ->page($page,$size)
             ->order("ga.addtime desc")
             ->select()
             ->toArray();
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
+        foreach ($list as &$value){
+            $value['company_name']=$item[$value['createrid']]??'';
+        }
+
         return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
     }
 

+ 8 - 4
app/admin/controller/After.php

@@ -263,16 +263,20 @@ class After extends Base
             ->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
             ->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,u.itemid,a.orderCode")
+            ->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,a.orderCode")
             ->page($page,$size)
-            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->order("addtime desc")
-            ->cursor();
+            ->select()
+            ->toArray();
+
+        $all_createrid = array_column($list,'apply_id');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data=[];
         foreach ($list as $value){
             $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
             $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['apply_id']]??'';
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;

+ 12 - 7
app/admin/controller/Allot.php

@@ -107,13 +107,16 @@ class Allot extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('allot_stock')
             ->alias('a')
-            ->field('a.*,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->where($where)
             ->order("a.addtime desc")
             ->page($page,$size)
-            ->cursor();
+            ->select()
+            ->toArray();
       // var_dump(Db::name('allot_stock')->getLastSql());
+
+        $all_createrid = array_column($list,'apply_id');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data=[];
         foreach ($list as $value){
             $db = Db::name('warehouse_info')
@@ -140,7 +143,7 @@ class Allot extends Base
             $value['tname'] =isset($dc['tname']) ? $dc['tname']:"";
             $value['rcode'] =isset($dc['code']) ? $dc['code']:"";
             $value['in_company_name'] =isset($dc['company']) ? $dc['company']:"";
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['apply_id']]??'';
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;
@@ -863,13 +866,15 @@ public function vesio(){
             ->alias("b")
             ->leftJoin("good_stock c", "c.spuCode=b.spuCode")
             ->join("good_stock_info d", "c.id=d.stockid", "left")
-            ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
             ->where($condtion)
-            ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code,u.uid,u.nickname,u.itemid,d.bnCode,d.balance_num,d.origin_price")
+            ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code,0 uid,'待处理wf' nickname,d.bnCode,d.balance_num,d.origin_price")
             ->page($page, $size)
             ->select()
             ->toArray();
 
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data = [];
         if ($list) {
             //品牌信息
@@ -906,7 +911,7 @@ public function vesio(){
                 }
                 $value['specinfo'] = $speclist;
                 $value['cgder'] = isset($supplier['person']) ? $supplier['person'] : '';
-                $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+                $value['company_name'] = $item[$value['createrid']]??'';
                 $data[] = $value;
             }
 

+ 15 - 9
app/admin/controller/Consult.php

@@ -388,7 +388,9 @@ class Consult extends Base
             $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
         }
         if($zxorder['depart']>0){
-            $zxinfo['departinfo']=GetPart($zxorder['depart']);
+            $userCommon = new \app\admin\common\User();
+            $tmp = $userCommon->handle('ciinfo',['id'=>$zxorder['depart']]);
+            $zxinfo['departinfo']=$tmp['data'];
         }
         if($zxorder['platform_code']>0){
             $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
@@ -2122,12 +2124,15 @@ class Consult extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('bargain_order')
             ->alias('bo')
-            ->field('bo.*,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
             ->where($where)
             ->page($page, $size)
             ->order('bo.addtime', 'desc')
-            ->cursor();
+            ->select()
+            ->toArray();
+
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data=[];
         foreach ($list as $value){
            $bidinfos =   Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
@@ -2173,7 +2178,7 @@ class Consult extends Base
             $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
 
             $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['createrid']]??'';
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;
@@ -2327,14 +2332,14 @@ class Consult extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('consult_bids')
             ->alias('cb')
-            ->field('cb.*,u.itemid,s.name supplierName')
-            ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
+            ->field('cb.*,s.name supplierName')
             ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
             ->leftJoin('supplier s', 's.code=cb.supplierNo')
             ->where($where)
             ->page($page, $size)
             ->order('cb.addtime', 'desc')
-            ->cursor();
+            ->select()
+            ->toArray();
         $data = [];
         foreach ($list as $value) {
             $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
@@ -2403,7 +2408,8 @@ class Consult extends Base
 //                $addr= GetAddr(json_encode($temp));
 //                $value['origin_addr'] = $addr;
 //            }
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['createrid']]??'';
+
             $data[] = $value;
         }
         return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);

+ 12 - 6
app/admin/controller/Customer.php

@@ -97,8 +97,11 @@ class Customer extends Base
             ->alias('co')
             ->where($condition)
             ->order("co.addtime",'desc')
-            ->leftJoin("depart_user u", "u.uid=co.createrid AND u.is_del=0")
-            ->column("co.id,co.pid,co.name,co.level,co.depart_link,co.creater,co.addtime,co.status,u.itemid");
+            ->column("co.id,co.pid,co.name,co.level,co.depart_link,co.creater,co.addtime,co.status");
+
+        $all_createrid = array_column($list,'createrid');
+        $all_item = get_company_name_by_uid($all_createrid);
+
         $var=[];
         foreach ($list as $item) {
             $iten=[];
@@ -109,17 +112,20 @@ class Customer extends Base
             $iten['status']=$item['status'];
             $iten['addtime']=$item['addtime'];
             $iten['kh']=0;//组织架构
-            $iten['company_name'] = implode('/', array_column(GetPart($item['itemid']), 'name'));
+            $iten['company_name'] = $all_item[$item['createrid']]??'';
+
             $var[]=$iten;
         }
         $itm = Db::name('customer_info')
             ->alias('ci')
-            ->field('ci.*,u.itemid')
-            ->leftJoin("depart_user u", "u.nickname=ci.creater AND u.is_del=0")
+//            ->leftJoin("depart_user u", "u.nickname=ci.creater AND u.is_del=0")
             ->where($where)
             ->order("ci.addtime desc")
             ->select()
             ->toArray();
+
+        //同理,这个表里只存了创建人名称,没有id
+
         foreach ($itm as $vat){
             $inm=[];
             $inm['name']=$vat['companyName'];
@@ -140,7 +146,7 @@ class Customer extends Base
             $inm['creater']=$vat['creater'];
             $inm['addtime']=$vat['addtime'];
             $inm['kh']=1;//客户
-            $inm['company_name'] = implode('/', array_column(GetPart($vat['itemid']), 'name'));
+            $inm['company_name'] = '待处理';
             $var[]=$inm;
         }
         return app_show(0,"获取成功",$var);

+ 10 - 7
app/admin/controller/Exclusive.php

@@ -41,15 +41,18 @@ class Exclusive extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('exclusive')
             ->alias('e')
-            ->field('e.*,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=e.createrid AND u.is_del=0")
-            ->append(['company_name'])
-            ->withAttr('company_name',function ($val,$data){
-                return implode('/', array_column(GetPart($data['itemid']), 'name'));
-            })
             ->where($where)
             ->page($page, $size)
-            ->select();
+            ->select()
+            ->toArray();
+
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
+        foreach ($list as &$value){
+            $value['company_name']=$item[$value['createrid']]??'';
+        }
+
         return app_show(0, "获取成功", ['list' =>$list, 'count' => $count]);
     }
 

+ 14 - 11
app/admin/controller/Good.php

@@ -1013,13 +1013,14 @@ class Good extends Base
 
         $action_uids = array_column($list, 'action_uid');
         $action_uids = array_unique($action_uids);
-        $item = [];
-        foreach ($action_uids as $action_uid) {
-            $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
-            foreach ($items as $it) {
-                $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
-            }
-        }
+        $item = get_company_name_by_uid($action_uids);
+//        $item = [];
+//        foreach ($action_uids as $action_uid) {
+//            $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
+//            foreach ($items as $it) {
+//                $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
+//            }
+//        }
 
         foreach ($list as &$value){
             $wsm = Db::name("warehouse_info")
@@ -1040,7 +1041,7 @@ class Good extends Base
             $value['code'] =$wsm['code'];
             $value['name'] =$wsm['name'];
             $value['action_type_cn'] =$this->acton[$value['action_type']];
-            $value['item'] = isset($item[$value['action_uid']]) ? $item[$value['action_uid']] : '';
+            $value['item'] = $item[$value['action_uid']] ?? '';
             $value['can'] =$int;
             $value['company'] =$wsm['company']??'';
             $value['companyNo'] =$wsm['companyNo']??'';
@@ -1206,17 +1207,19 @@ class Good extends Base
 
         $list = Db::name('good_ladder')
             ->alias('gl')
-            ->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num moq,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo,u.itemid')
+            ->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num moq,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo')
             ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
             ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
-            ->leftJoin("depart_user u", "u.uid=gb.createrid AND u.is_del=0")
             ->where($where)
             ->page($param['page'], $param['size'])
             ->order(['gl.skuCode' => 'asc', 'gl.addtime' => 'desc', 'gl.id' => 'desc'])
             ->select()
             ->toArray();
 
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
         //6.补充数据,照搬list方法
         $all_brand = Db::name('brand')
             ->where('is_del', 0)
@@ -1235,7 +1238,7 @@ class Good extends Base
             $value['stock_total'] = Db::name("good_stock")
                 ->where(['spuCode' => $value['spuCode'], "is_del" => 0])
                 ->sum("usable_stock");
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['createrid']]??'';
         }
 
         return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);

+ 7 - 7
app/admin/controller/OrderImport.php

@@ -105,26 +105,26 @@ class OrderImport extends Base
             ->leftJoin('good_platform gp', 'gp.plat_code=c.plat_code AND gp.platform_code=c.platform_id AND gp.is_del=0 AND gp.exam_status=6')
             ->leftJoin('good g', 'g.spuCode=gp.spuCode AND g.is_del=0')
             ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
-            ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
             ->where($where)
             ->count('c.id');
 
         $list = OIFCModel::alias('c')
-            ->field('c.*,g.good_name,p.platform_name platform_title,u.itemid')
+            ->field('c.*,g.good_name,p.platform_name platform_title')
             ->leftJoin('good_platform gp', 'gp.plat_code=c.plat_code AND gp.platform_code=c.platform_id AND gp.is_del=0 AND gp.exam_status=6')
             ->leftJoin('good g', 'g.spuCode=gp.spuCode AND g.is_del=0')
             ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
-            ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
             ->where($where)
-            ->append(['company_name'])
-            ->withAttr('company_name', function ($val, $data) {
-                return implode('/', array_column(GetPart($data['itemid']), 'name'));
-            })
             ->page($param['page'], $param['size'])
             ->order('id', 'desc')
             ->select()
             ->toArray();
 
+        $all_createrid = array_column($list,'createrid');
+        $item = get_company_name_by_uid($all_createrid);
+
+        foreach ($list as &$value){
+            $value['company_name']=$item[$value['createrid']]??'';
+        }
         return app_show(0, "获取成功", ['list' => $list, 'count' => $total]);
     }
 

+ 1 - 1
app/admin/controller/Project.php

@@ -422,7 +422,7 @@ class Project extends Base
             $value['khName'] = $headquarters[$value['khNo']] ?? '';//isset($khinfo['companyName'])?$khinfo['companyName']:"";
 //            $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
             $value['company'] = $headquarters[$value['companyNo']] ?? '';//isset($company['company'])?$company['company']:"";
-            $value['company_name'] = $item[$value['createrid']];//implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['createrid']];
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;

+ 8 - 4
app/admin/controller/Reorder.php

@@ -478,15 +478,19 @@ class Reorder extends Base
         $page = $total>=$page ? $page :$total;
         $list = Db::name("sale_return")
             ->alias('sr')
-            ->field('sr.*,u.itemid,b.skuCode,b.sale_price,b.good_num total_num ')
-            ->leftJoin("depart_user u", "u.uid=sr.apply_id AND u.is_del=0")
+            ->field('sr.*,b.skuCode,b.sale_price,b.good_num total_num ')
             ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
             ->where($where)
             ->where(function ($query)use ($condition){$query->whereOr($condition);})
             ->order("addtime desc")
             ->page($page,$size)
-            ->cursor();
+            ->select()
+            ->toArray();
        // echo Db::name("sale_return")->getLastSql();
+
+        $all_createrid = array_column($list,'apply_id');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data=[];
         foreach ($list as $value){
             $value['error_msg']='';
@@ -498,7 +502,7 @@ class Reorder extends Base
 //            $value['sale_price'] = isset($order['sale_price']) ?$order['sale_price']:0;
             $value['return_total'] =$value['sale_price']*$value['num'] ;
 //            $value['total_num'] =$order['good_num'] ;
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['apply_id']]??'';
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;

+ 14 - 8
app/admin/controller/Sale.php

@@ -2204,11 +2204,13 @@ class Sale extends Base
         $page = $page >= $total ? $total : $page;
         $list = Db::name('sale')
             ->alias('s')
-            ->field('s.*,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=s.apply_id AND u.is_del=0")->where($where)
             ->order("s.addtime desc")
             ->page($page, $size)
-            ->cursor();
+            ->select()
+            ->toArray();
+        $all_createrid = array_column($list,'apply_id');
+        $item = get_company_name_by_uid($all_createrid);
+
         $data = [];
         foreach ($list as $value) {
             if ($value['order_type'] == 3) {
@@ -2257,7 +2259,7 @@ class Sale extends Base
             $value['good_num'] -= $value['th_num'];
             $value['send_num'] -= $value['th_num'];
             $value['total_price'] = round($value['total_price'] - $value['th_fee'], 2);
-            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['apply_id']]??'';
 
             //是否具有编辑权限
             $value['is_allow_update'] = 0;
@@ -3572,14 +3574,17 @@ class Sale extends Base
             ->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("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
 	        ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
-            ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,u.itemid")
+            ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo")
             ->where($where)
             ->where($condition)
             ->order("addtime desc")
             ->page($page, $size)
-            ->cursor();
+            ->select()
+            ->toArray();
+
+        $all_createrid = array_column($list,'apply_id');
+        $item = get_company_name_by_uid($all_createrid);
 
         $data = [];
         foreach ($list as $value) {
@@ -3614,7 +3619,8 @@ class Sale extends Base
             $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'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['company_name'] = $item[$value['apply_id']]??'';
+
             $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
 
             //是否具有编辑权限

+ 3 - 3
app/admin/controller/Title.php

@@ -128,14 +128,14 @@ class Title extends BaseController
         $page = $page >= $total ? $total : $page;
         $list = Db::name('customer_title')
             ->alias("a")
-            ->field("a.*,b.companyName,b.creater,u.itemid")
+            ->field("a.*,b.companyName,b.creater")
             ->join("customer_info b","b.companyNo=a.companyNo","left")
-            ->leftJoin("depart_user u", "u.nickname=b.creater AND u.is_del=0")
+//            ->leftJoin("depart_user u", "u.nickname=b.creater AND u.is_del=0")
             ->where($where)
             ->page($page,$size)
             ->append(['company_name'])
             ->withAttr('company_name',function ($val,$data){
-                return implode('/', array_column(GetPart($data['itemid']), 'name'));
+                return '待处理';//此处customer_info表里创建人存的是名称,不是id,根据名称查询所属部门,尚待以后 2023-01-12 16:00 @wf
             })
             ->select()
             ->toArray();