Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

施宇 / icsales

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • icsales
  • Application
  • Common
  • Controller
  • BaseController.class.php
BaseController.class.php 2.15 KB
朱继来's avatar
添加cms配置
36aa31cd
 
朱继来 committed 5 years ago
1
<?php
叶明星's avatar
拆分模块
8bed0325
 
叶明星 committed 5 years ago
2
namespace Common\Controller;
朱继来's avatar
添加cms配置
36aa31cd
 
朱继来 committed 5 years ago
3 4 5 6 7 8
use Think\Controller;

class BaseController extends Controller
{
	public function _initialize()
	{
朱继来's avatar
添加热门商品
676b5c8b
 
朱继来 committed 5 years ago
9 10 11
        $datas['logo']          = $this->apiBaseCache('pc_logo_set'); // logo
        $datas['bottom_qrcode'] = $this->apiBaseCache('pc_bottom_qrcode'); // 底部二维码
        $datas['hot_goods']     = $this->apiBaseCache('pc_hot_goods', '', 5); // 热门商品
朱继来's avatar
添加cms配置
36aa31cd
 
朱继来 committed 5 years ago
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

        foreach ($datas as $k => $v) {
            $this->assign($k, $v['data']);
        }
	}

	/**
     * 通过bcat_id获取CMS分类数据 --- 图片、文字等
     * @param  [type] $tags  [标签]
     * @param  [type] $where [搜索条件,用&连接,如:a=1&b=2]
     * @param  [type] $limit [数量]
     * @return [type]        [description]
     */
    public function apiBaseCache($tags, $where='', $limit=1)
    {
        $cms = D('Home/Scms');
        $datas = $cms->getBaseList($tags, $where, $limit);

        if (!empty($datas)) {
            return $this->apiReturn(0, '', $datas);
        } else {
            return $this->apiReturn(7004, '未找到数据');
        }
朱继来's avatar
热门商品接口
f7880a78
 
朱继来 committed 5 years ago
35
    } 
朱继来's avatar
添加cms配置
36aa31cd
 
朱继来 committed 5 years ago
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

	/**
     * 统一格式返回
     * @param  integer $code   [description]
     * @param  string  $msg    [description]
     * @param  array   $extend [description]
     * @return [type]          [description]
     */
    protected function apiReturn($code = 0, $msg = '', $extend = array())
    {
        $data = array(
            'err_code' => $code,
            'err_msg' => $msg,
            'data' => $extend,
        );
        if(isset($_GET['callback']) && !empty($_GET['callback'])){
            echo  $_GET['callback'].'('.json_encode($data).')';exit;
        }else{
            return $data;exit;
        }
    }
朱继来's avatar
添加接口校验
1eb0f136
 
朱继来 committed 5 years ago
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

    // 校验接口
    protected function checkApi($request)
    {
        $timestamp = I('request.timestamp', '');
        $random    = I('request.random', '');
        $signature = I('request.signature', '');

        if (!$timestamp && !$random && !$signature) return false;

        if ($timestamp < time() - 300) return false;

        $sign = createSignature($timestamp, $random);

        if ($signature != $sign) return false; 

        return true;
    }


朱继来's avatar
添加cms配置
36aa31cd
 
朱继来 committed 5 years ago
77
}