146 lines
3.6 KiB
PHP
Executable File
146 lines
3.6 KiB
PHP
Executable File
<?php
|
|
|
|
use think\response\Json;
|
|
use app\common\model\Slide;
|
|
use app\common\model\ShopConfig;
|
|
use tools\Crypt;
|
|
if(!function_exists('success')){
|
|
/**
|
|
* 操作成功
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function success($data = '', $msg = 'success', $code = 200)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('error')){
|
|
/**
|
|
* 操作失败
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function error($msg = 'fail', $data = '', $code = 500)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('result')){
|
|
/**
|
|
* 返回json结果
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function result($msg = 'fail', $data = '', $code = 500)
|
|
{
|
|
$header = [];
|
|
//处理跨域请求问题
|
|
if (config('api.cross_domain.allow')) {
|
|
$header = ['Access-Control-Allow-Origin' => '*'];
|
|
if (request()->isOptions()) {
|
|
$header = config('api.cross_domain.header');
|
|
return json('',200,$header);
|
|
}
|
|
}
|
|
|
|
return json([
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
], $code, $header);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('unauthorized')){
|
|
/**
|
|
* 未授权
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function unauthorized($msg = 'unauthorized', $data = '', $code = 401)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('client_error')){
|
|
/**
|
|
* 客户端错误
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function client_error($msg = 'client error', $data = '', $code = 400)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('server_error')){
|
|
/**
|
|
* 服务端错误
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function server_error($msg = 'server error', $data = '', $code = 500)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('error_404')){
|
|
/**
|
|
* 资源或接口不存在
|
|
* @param string $msg
|
|
* @param string $data
|
|
* @param int $code
|
|
* @return Json
|
|
*/
|
|
function error_404($msg = '404 not found', $data = '', $code = 404)
|
|
{
|
|
return result($msg, $data, $code);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_ad')) {
|
|
/**
|
|
* 广告列表
|
|
* @param string $alias 广告别名
|
|
* @param string $num。显示数量
|
|
* @return li
|
|
*/
|
|
function get_ad($alias, $num = '999')
|
|
{
|
|
$_malladviceModel = new Slide();
|
|
$where = 'alias="'.$alias.'"';
|
|
$malladvice_list = $_malladviceModel->where($where)->limit($num)->order('sort_number desc')->select();
|
|
$ad = array();
|
|
$web_url = ShopConfig::get('website', 'img_url');
|
|
foreach ($malladvice_list as $key => $row) {
|
|
$ad[$key]['id'] = $row['id'];
|
|
if($row['jump_type']==1){
|
|
$ad[$key]['unionid'] = Crypt::encrypt($row['jump_target']);
|
|
}else{
|
|
$ad[$key]['url'] = $row['jump_target'];
|
|
}
|
|
$ad[$key]['type'] = $row['jump_type'];
|
|
$ad[$key]['img'] = $web_url . $row['img'];
|
|
}
|
|
return $ad;
|
|
}
|
|
}
|