首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >laravel 循环中子元素使用&符号嵌入到父级,经典版

laravel 循环中子元素使用&符号嵌入到父级,经典版

作者头像
全栈程序员站长
发布2022-07-08 12:26:16
发布2022-07-08 12:26:16
5850
举报
代码语言:javascript
复制
   /**ajax 获取企业名称
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     * @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 \Illuminate\Http\JsonResponse
     * @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' => '搜索成功']);
    }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/112365.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年11月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档