zoukankan      html  css  js  c++  java
  • laravel 循环中子元素使用&符号嵌入到父级,经典版

       /**ajax 获取企业名称
         *
         * @param Request $request
         *
         * @return IlluminateHttpJsonResponse
         * @author lxw
         */
        public function getCompanyName( Request $request )
        {
            $keyword = $request->query->get('q', '');
    
            $allCompany = Company::query();
            $allCompany = $allCompany->select('id', 'username');
            if ( $keyword ) {
                $allCompany = $allCompany->where('username', 'like', '%' . $keyword . '%');
            }
            $allCompany = $allCompany->orderBy('created_at', 'desc');
            $allCompany = $allCompany->limit(5);
            $allCompany = $allCompany->get();
            if ( empty($allCompany) ) {
                return response()->json(['status' => 500, 'data' => new ArrayObject(), 'msg' => '搜索关键字不存在']);
            }
            $data = [];
            foreach ( $allCompany->toArray() as $item ) {
                $data[] = [
                    'id' => $item['id'],
                    'text' => $item['username'],
                ];
            }
            return response()->json(['status' => 200, 'data' => $data, 'msg' => '搜索成功']);
        }
    
        /**ajax请求该企业下的所有楼宇
         * 执行中的显示其他订单已开通
         *
         * @param $companyId
         *
         * @return IlluminateHttpJsonResponse
         * @author lxw
         */
        public function getCompanyBuildings( $companyId )
        {
            //该企业下已经被创建过订单且处于执行中的的楼宇id
            $doingBuilds = BuildingPayment::query()
                ->where('company_id', $companyId)
                ->whereDate('duetime', '>', date('Y-m-d', time()))
                ->groupBy('building_id')
                ->get(['building_id']);
    
            $doingBuildArr = $doingBuilds ? $doingBuilds->toArray() : [];
            $doingBuildIds = array_column($doingBuildArr, 'building_id');
    
            //该企业下所有的楼宇
            $allBuildings = Building::query()
                ->where('company_id', $companyId)
                ->orderBy('sort', 'asc')
                ->get(['id', 'name']);
            $allBuildings = $allBuildings ? $allBuildings->toArray() : [];
            foreach ( $allBuildings as &$building ) {
                if( in_array($building['id'], $doingBuildIds)){
                    $building['isPayment'] = true;
                }else{
                    $building['isPayment'] = false;
                }
            }
    
            return response()->json(['status' => 200, 'data' => $allBuildings, 'msg' => '搜索成功']);
        }
    

      

  • 相关阅读:
    度度熊学队列
    Wannafly挑战赛21
    C. Vasya And The Mushrooms
    D. Vasya And The Matrix
    B. Segment Occurrences
    Codeforces Round #501 (Div. 3)(ABCDE)
    2018 Multi-University Training Contest 4
    1068 : RMQ-ST算法
    Nordic Collegiate Programming Contest 2015​
    Hack It
  • 原文地址:https://www.cnblogs.com/lxwphp/p/10769960.html
Copyright © 2011-2022 走看看