Index.php 8.5 KB
<?php

namespace app\api\controller;

use addons\epay\library\OrderException;
use app\api\model\Banner;
use app\api\model\Description;
use app\api\model\goods\Goods;
use app\api\model\goods\GoodsSku;
use app\api\model\service\ServiceCase;
use app\api\validate\IndexValidate;
use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页Banner
     * @ApiTitle (轮播图)
     * @ApiReturnParams   (name="id", type="integer", description="id")
     * @ApiReturnParams   (name="image", type="string", description="图片")
     * @ApiReturnParams   (name="url", type="string", description="跳转链接地址")
     */
    public function banner()
    {
        $model = new Banner();
        $list  = $model->field('id,image,url')->select();
        $this->success('请求成功', $list);
    }

    /**
     * 首页信息
     * @ApiTitle (首页信息)
     * @ApiReturnParams   (name="case_name", type="integer", description="服务案例名称")
     * @ApiReturnParams   (name="service_case", type="string", description="服务案例跳转  1=跳转内链,2=显示富文本")
     * @ApiReturnParams   (name="introduction_name", type="string", description="服务介绍名称")
     * @ApiReturnParams   (name="service_introduction", type="string", description="服务介绍跳转  1=跳转内链,2=显示富文本")
     * @ApiReturnParams   (name="repair_call", type="string", description="一键报修")
     * @ApiReturnParams   (name="repair_description", type="string", description="保修服务说明")
     * @ApiReturnParams   (name="hedging_description", type="string", description="全损保值服务说明")
     *
     * @ApiReturnParams   (name="epair", type="string", description="燃油车、新能源车说明")
     * @ApiReturnParams   (name="hedging", type="string", description="燃油车、新能源车说明")
     * @ApiReturnParams   (name="type", type="string", description="说明类型:epair=报修服务,hedging=全损保值服务")
     * @ApiReturnParams   (name="fuel_car_description", type="string", description="燃油车说明")
     * @ApiReturnParams   (name="new_energy_car_description", type="string", description="新能源车说明")
     *
     * @ApiReturnParams   (name="report_repair", type="string", description="报案及维修理赔流程")
     * @ApiReturnParams   (name="common_problem", type="string", description="常见问题答疑")
     */
    public function index_config()
    {
        $case_name            = config('site.case_name');//服务案例名称
        $service_case         = config('site.service_case');//服务案例跳转  1=跳转内链,2=显示富文本
        $introduction_name    = config('site.introduction_name'); //服务介绍名称
        $service_introduction = config('site.service_introduction');  //服务介绍跳转  1=跳转内链,2=显示富文本
        $repair_call          = config('site.repair_call');  //一键报修
        $repair_description   = config('site.repair_description');  //保修服务说明
        $hedging_description  = config('site.hedging_description');  //全损保值服务说明
        $repair               = (new Description())->field('type,fuel_car_description,new_energy_car_description')->find();
        $hedging              = (new Description())->field('type,fuel_car_description,new_energy_car_description')->find();
        $report_repair        = set_img_style(config('site.report_repair'));//报案及维修理赔流程
        $common_problem       = set_img_style(config('site.common_problem'));//常见问题答疑
        $this->success('金刚区', [
            'case_name'            => $case_name,
            'service_case'         => $service_case,
            'introduction_name'    => $introduction_name,
            'service_introduction' => $service_introduction,
            'repair_call'          => $repair_call,
            'hedging_description'  => $hedging_description,
            'repair_description'   => $repair_description,
            'report_repair'        => $report_repair,
            'common_problem'       => $common_problem,
            'hedging'              => $hedging,
            'repair'               => $repair,
        ]);
    }

    /**
     * 服务介绍
     * @ApiTitle (服务介绍)
     * @ApiReturnParams   (name="service_introduction", type="string", description="服务介绍跳转  1=跳转内链,2=显示富文本")
     * @ApiReturnParams   (name="introduction_content", type="string", description="富文本")
     * @ApiReturnParams   (name="service_introduction_url", type="string", description="跳转链接地址")
     */
    public function service_introduction()
    {
        $service_introduction = config('site.service_introduction');  //服务介绍跳转  1=跳转内链,2=显示富文本
        if ($service_introduction == 2) {
            $introduction_content = config('site.introduction_content');
            $data                 = [
                'service_introduction' => $service_introduction,
                'introduction_content' => set_img_style($introduction_content),
            ];
            $this->success('服务介绍', $data);
        }
        $service_introduction_url = config('site.service_introduction_url');
        $data                     = [
            'service_introduction'     => $service_introduction,
            'service_introduction_url' => $service_introduction_url,
        ];
        $this->success('服务介绍', $data);

    }

    /**
     * 服务案例
     * @ApiTitle (服务案例)
     * @ApiReturnParams   (name="service_case", type="string", description="服务介绍跳转  1=跳转内链,2=显示富文本")
     * @ApiReturnParams   (name="service_case_url", type="string", description="跳转链接")
     * @ApiReturnParams   (name="list", type="string", description="案例列表")
     */
    public function service_case()
    {
        $service_case = config('site.service_case');//服务案例跳转  1=跳转内链,2=显示富文本
        if ($service_case == 2) {
            $list = (new ServiceCase())->field('id,title')->order('id', 'desc')->select();
            $data = [
                'service_case' => $service_case,
                'list'         => $list,
            ];
            $this->success('服务案例', $data);
        }
        $service_case_url = config('site.service_case_url');
        $data             = [
            'service_case'     => $service_case,
            'service_case_url' => $service_case_url,
        ];
        $this->success('服务介绍', $data);

    }

    /**
     * 服务案例详情
     * @ApiTitle (服务案例详情)
     * @ApiParams   (name="id", type="string", description="案例id")
     * @ApiReturnParams   (name="content", type="string", description="案例详情")
     */
    public function case_detail()
    {
        $case_id = $this->request->param('id', '', 'intval');
        if (empty($case_id)) {
            $this->error('参数缺失');
        }
        $detail = (new ServiceCase())->where('id', $case_id)->field('content')->find();

        $this->success('案例详情', $detail);
    }

    /**
     * 首页筛选产品列表
     * @ApiTitle (首页筛选产品列表)
     * @ApiParams   (name="service_type", type="string", description="服务类型:1=报修服务,2=全损保值服务")
     * @ApiParams   (name="cart_type", type="string", description="汽车类型:1=燃油车,2=新能源车")
     * @ApiReturnParams   (name="id", type="string", description="产品id")
     * @ApiReturnParams   (name="title", type="string", description="产品标题")
     * @ApiReturnParams   (name="brief_introduction", type="string", description="产品简介")
     * @ApiReturnParams   (name="price", type="string", description="产品最低价格")
     */
    public function goods_list()
    {
        $validate = new IndexValidate();
        if (!$validate->scene('select_goods')->check($this->param)) {
            $this->error($validate->getError());
        }
        $where['cart_type']    = ['=', $this->param['cart_type']];
        $where['service_type'] = ['=', $this->param['service_type']];
        $where['goods_status'] = ['=', '10'];
        $goods_list            = (new Goods())->field('id,title,brief_introduction')
            ->where($where)->order('weigh', 'desc')->paginate()->each(function (&$item) {
                $item['price'] = (new GoodsSku())->where('goods_id', $item['id'])
                    ->order('price', 'asc')->value('price');
            });
        $this->success('产品列表', $goods_list);
    }
}