Sundry.php 8.7 KB
<?php

namespace app\api\controller;

use app\api\model\Area;
use app\api\model\AreaExtend;
use app\api\model\KeywordLog;
use app\api\model\Slide;
use app\api\model\WeekTemplate;
use app\common\controller\Api;
use think\Db;
use think\Validate;

/**
 * 杂项接口
 */
class Sundry extends Api
{

    protected function _initialize()
    {
        parent::_initialize();

    }

    /**
     * @ApiTitle    (幻灯片)
     * @ApiSummary  (幻灯片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getSlide)
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",//幻灯片id
    "goods_id": "shop_id",//商品id(可跳转商品详情)
    "title": "title",//标题
    "image": "image",//图片
    },
    })
     */
    public function getSlide()
    {
        $slideModel = new Slide();
        $data = $slideModel->selectData([]);
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取用户搜索记录)
     * @ApiSummary  (获取用户搜索记录)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getUserKeyword)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams  (name=limit, type=string, required=false, description="显示条数 默认8条")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",//幻灯片id
    "goods_id": "shop_id",//商品id(可跳转商品详情)
    "title": "title",//标题
    "image": "image",//图片
    },
    })
     */
    public function getUserKeyword()
    {
        $limit = $this->request->param('limit') ? $this->request->param('limit') : 8;
        $model = new KeywordLog();
        $userId = $this->getUserId();
        $data = $model->selectData(['user_id' => $userId], $limit);
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取地区)
     * @ApiSummary  (获取地区)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getArea)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=province_id, type=string, required=false, description="省")
     * @ApiParams  (name=city_id, type=string, required=false, description="市")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getArea()
    {
        $areaModel = new Area();
        $params = $this->request->param();
        $where['pid'] = 0;
        if (!empty($params['province_id'])) $where['pid'] = $params['province_id'];
        if (!empty($params['city_id'])) $where['pid'] = $params['city_id'];

        $data = $areaModel->where($where)->field('id,name')->select();

        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取配送时间)
     * @ApiSummary  (获取配送时间)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getDeliveryTime)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=province_id, type=string, required=true, description="省")
     * @ApiParams  (name=city_id, type=string, required=false, description="市")
     * @ApiParams  (name=county_id, type=string, required=false, description="县")
     * @ApiParams  (name=type, type=string, required=true, description="类型:1=闪送,2=普通配送")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getDeliveryTime()
    {
        $model = new AreaExtend();
        $params = $this->request->param();

        if (empty($params['type'])) $this->error('缺少参数 type!');
        if (!empty($params['province_id'])) $where['province_id'] = $params['province_id'];
        else $this->error('缺少参数 province_id!');
        if (!empty($params['city_id'])) $where['city_id'] = $params['city_id'];
        if (!empty($params['county_id'])) $where['county_id'] = $params['county_id'];

        $data = $model->where($where)->field('is_special,starttime1,endtime1,starttime2,endtime2')->find();
        if (!$data) $data = $model->where(['province_id'=>$params['province_id']])->field('is_special,starttime1,endtime1,starttime2,endtime2')->find();
        if ($params['type'] == 1){
            $startDate = date("Y-m-d", strtotime('+' . $data['starttime2'] . ' days', time()));
            $endDate = date("Y-m-d", strtotime('+' . $data['endtime2'] . ' days', time()));
        }else{
            $startDate = date("Y-m-d", strtotime('+' . $data['starttime1'] . ' days', time()));
            $endDate = date("Y-m-d", strtotime('+' . $data['endtime1'] . ' days', time()));
        }

        $data['date'] = period_date($startDate, $endDate);
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取闪送配送时间)
     * @ApiSummary  (获取闪送配送时间)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getDeliveryFastTime)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=week, type=string, required=true, description="星期 getDeliveryTime接口返回的week字段")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getDeliveryFastTime()
    {
        $model = new WeekTemplate();
        $week = $this->request->param('week');
        if (isset($week) && $week == '' ) $this->error('缺少参数 week!');
        $data = $model->selectData(['type' => $week]);
        foreach ($data as $k => $v) {
            $data[$k] = $v['starttime'] . '-' . $v['endtime'];
        }
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取文本)
     * @ApiSummary  (获取文本)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getText)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=type, type=string, required=true, description="类型:1=会员特权文本,2=提现说明文本,3=配送详情文本")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getText()
    {
        $type = $this->request->param('type');
        if ($this->lang == 'ch'){
            switch ($type) {
                case 1:
                    $data = config('site.vip_text');
                    break;
                case 2:
                    $data = config('site.withdraw_deposit_text');
                    break;
                case 3:
                    $data = config('site.distribution_text');
                    break;
            }
        }else{
            switch ($type) {
                case 1:
                    $data = config('site.en_vip_text');
                    break;
                case 2:
                    $data = config('site.en_withdraw_deposit_text');
                    break;
                case 3:
                    $data = config('site.en_distribution_text');
                    break;
            }
        }
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取充值金额)
     * @ApiSummary  (获取充值金额)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getRecharge)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getRecharge()
    {
        $userModel = new \app\admin\model\User();
        $userId = $this->user['id'];
        if ($userId) {
            $data['money'] = '¥'.$userModel->where('id',$userId)->value('money');
        } else {
            $data['money'] = '¥0';
        }
        $data['list'] = explode(',', config('site.recharge'));
        $this->success('SUCCESS', $data);
    }

    /**
     * @ApiTitle    (获取充值会员金额)
     * @ApiSummary  (获取充值会员金额)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/sundry/getVipPrice)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {
    "id": "id",// 地区id
    "name": "name",// 名称
    },
    })
     */
    public function getVipPrice()
    {
       $this->success('SUCCESS', config('site.vip_price'));
    }
}