作者 lihan

我的资料、我的优惠券、我要充值

... ... @@ -17,6 +17,9 @@ class ActivityController extends HomeBaseController
* @url /activity/Activity/_list
* @method POST
*
* @param name:t_id type:int require:1 default:2 desc:活动分类id
* @param name:keyword type:char require:1 default:2 desc:关键词
*
* @return version:版本号
* @return code:错误码
*/
... ... @@ -28,13 +31,14 @@ class ActivityController extends HomeBaseController
$type = Db::name('type')->field('type_name,type_url,type_icon')->order('listorder')->select();
//活动
$model = new ActivityModel;
$activity = $model->activityList('', time(), session('user.id'));
$t_id = request()->param('t_id');
$keyword = request()->param('keyword');
$activity = $model->activityList($t_id, time(), session('user.id'), $keyword);
$result = [
'banner' => $banner,
'type' => $type,
'activity' => $activity
];
//
echo json_encode(['data' => $result, 'code' => 20000]);
exit();
}
... ...
... ... @@ -17,17 +17,21 @@ class ActivityModel extends Model
* @param null $tId
* @param $nowTime
* @param $userId
* @return false|\PDOStatement|string|\think\Collection
* @param null $keyword
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function activityList($tId = null, $nowTime, $userId)
public function activityList($tId = null, $nowTime, $userId, $keyword=null)
{
$where = [];
if ($tId != null) {
$where['t_id'] = ['eq', $tId];
}
if ($keyword != null) {
$where['name'] = ['like', "%$keyword%"];
}
$res = Db::name('activity')->field('id,name,thumb')->where($where)->select()->toArray();
//只显示还未到报名日期活动最近的一条行程
foreach ($res as $key => $item) {
... ... @@ -61,10 +65,18 @@ class ActivityModel extends Model
private function allSchedule($activityId)
{
$res = Db::name('activity_schedule')->field('start_time,end_time,price')->where(['activity_id' => $activityId])->select();
$res = Db::name('activity_schedule')
->field('id as schedule_id,start_time,end_time,price,maximum,real_join_num,addition_join_num')
->where(['activity_id' => $activityId])
->select();
foreach ($res as $k => $v) {
$v['start_time'] = date('Y-m-d', $v['start_time']);
$v['end_time'] = date('Y-m-d', $v['end_time']);
$v['sales_num'] = $v['real_join_num'] + $v['addition_join_num'];
$v['residue_num'] = $v['maximum'] - $v['sales_num'];
unset($v['real_join_num']);
unset($v['addition_join_num']);
unset($v['maximum']);
$res[$k] = $v;
}
return $res;
... ...
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/8/30
* Time: 14:29
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class DiscountCouponController extends AdminBaseController
{
public function add()
{
$request = request();
if ($request->isPost()) {
$post = $request->param();
if (empty($post['discount_coupon_name'])) {
$this->error('请输入优惠券名称');
}
if (empty($post['overflow']) || $post['overflow'] < 0) {
$this->error('请输入正确满减金额');
}
if (empty($post['reduce']) || $post['reduce'] < 0) {
$this->error('请输入正确满减金额');
}
if (empty($post['deadline'])) {
$this->error('请选择截止日期');
}
if (empty($post['user_id'])) {
$this->error('请匹配用户');
}
$n = count($post['user_id']);
$data = [];
for ($i = 0; $i < $n; $i++) {
$data[$i] = array(
'user_id' => $post['user_id'][$i],
'discount_coupon_name' => $post['discount_coupon_name'],
'overflow' => $post['overflow'],
'reduce' => $post['reduce'],
'deadline' => strtotime($post['deadline']),
'status' => 1
);
}
if (Db::name('discount_coupon')->insertAll($data)) {
$this->success('创建优惠券成功');
} else {
$this->error('创建优惠券失败');
}
} else {
return $this->fetch('', [
'user' => $this->getUserList()
]);
}
}
public function index()
{
$posts = Db::name('discount_coupon')->alias('d')->field('sami_discount_coupon.id,discount_coupon_name,deadline,user_nickname,status')
->join('sami_user u', 'u.id=d.user_id')
->order("id DESC")
->paginate(20);
return $this->fetch('', [
'posts' => $posts,
'page' => $posts->render()
]);
}
public function getUserList()
{
$keywords = request()->param('keywords');
$map = array();
$map['user_type'] = ['eq', 2];
if (!empty($keywords)) {
$map['user_nickname'] = array('like', "%$keywords%");
}
$user = Db::name('user')->field('id,user_nickname')->where($map)->select();
$html = '<tr>
<th><input type="checkbox" id="All" onclick="checkAll()"></th>
<th width="300"><input style="width: 200px; display: unset" class="form-control" type="text" placeholder="搜索" id="Search" value="' . $keywords . '" onchange="ajax()">&nbsp;&nbsp;&nbsp;搜索</th>
</tr>';
foreach ($user as $item) {
$html .= '<tr>
<td><input type="checkbox" name="user_id[]" value="' . $item['id'] . '"></td>
<td>' . $item['user_nickname'] . '</td>
</tr>';
}
if (request()->isAjax()) {
echo json_encode(['data' => $html]);
exit();
} else {
return $user;
}
}
public function edit()
{
$request = request();
$id = $request->param('id');
if ($request->isPost()) {
$post = $request->param();
if (empty($post['discount_coupon_name'])) {
$this->error('请输入优惠券名称');
}
if (empty($post['overflow']) || $post['overflow'] < 0) {
$this->error('请输入正确满减金额');
}
if (empty($post['reduce']) || $post['reduce'] < 0) {
$this->error('请输入正确满减金额');
}
if (empty($post['deadline'])) {
$this->error('请选择截止日期');
}
$post['id'] = $id;
$post['deadline'] = strtotime($post['deadline']);
if (Db::name('discount_coupon')->update($post)) {
$this->success('编辑优惠券成功');
} else {
$this->error('您未作出任何修改');
}
} else {
return $this->fetch('', [
'id' => $id,
'info' => Db::name('discount_coupon')->where(array('id' => $id))->find()
]);
}
}
public function del()
{
$id = request()->param('id');
if (Db::name('discount_coupon')->delete($id)) {
$this->success('销毁成功');
} else {
$this->error('销毁失败');
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/9/5
* Time: 15:03
*/
namespace app\coupons\model;
use think\Model;
use think\Db;
class CouponModel extends Model
{
public function getAllDiscountCouponByUniqueIdAndByStatus($status = null, $user_id)
{
if ($status == null) {
$status = 1;
}
$map['status'] = array('eq', $status);
$map['user_id'] = array('eq', $user_id);
$res = Db::name('discount_coupon')->field('id,reduce,discount_coupon_name,deadline')->where($map)->select()->toArray();
foreach ($res as $key => $item) {
$item['deadline'] = date('Y-m-d', $item['deadline']);
$res[$key] = $item;
}
return $res;
}
}
\ No newline at end of file
... ...
... ... @@ -11,8 +11,6 @@ class EscortController extends HomeBaseController
function _initialize()
{
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
if (empty(session('user.id'))) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
... ...
... ... @@ -23,6 +23,7 @@ class IndexController extends HomeBaseController
function __construct()
{
session('user.id', 2);
echo session('user.id');
}
/**
... ...
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/9/5
* Time: 10:48
*/
namespace app\user\controller;
use app\coupons\model\CouponModel;
use cmf\controller\HomeBaseController;
use Think\Db;
use app\coupons\model\DiscountCouponModel;
/**
* @title 个人中心模块
*/
class CenterController extends HomeBaseController
{
function __construct()
{
session('user.id', 2);
if (empty(session('user.id'))) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
}
/**
* @title 我的资料
* @description 默认访问接口(post方式更改用户信息需要填写参数,post以外是模板渲染用户信息)
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/myInfo
* @method GET
*
* @param name:realname type:char require:1 default:李涵 desc:真实姓名
* @param name:tel type:char require:1 default:15122554644 desc:手机号
* @param name:wechat type:char require:1 default:xxxxxx desc:微信号
* @param name:identity type:char require:1 default:12010319960501291X desc:身份证号
*
* @return version:版本号
* @return code:错误码
*/
public function myInfo()
{
$request = request();
if ($request->isPost()) {
$post = $request->param();
if ($post['realname'] == null) {
echo json_encode(['msg' => '请填写真实姓名', 'code' => 40000]);
exit();
}
if ($post['tel'] == null) {
echo json_encode(['msg' => '请填写手机号', 'code' => 40000]);
exit();
}
if ($post['wechat'] == null) {
echo json_encode(['msg' => '请填写微信号', 'code' => 40000]);
exit();
}
if ($post['identity'] == null) {
echo json_encode(['msg' => '请填写身份证信息', 'code' => 40000]);
exit();
}
$post['id'] = session('user.id');
if (Db::name('user')->update($post)) {
echo json_encode(['data' => '更改成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['data' => '您为做出任何修改', 'code' => 40000]);
exit();
}
} else {
$userInfo = Db::name('user')->field('avatar,user_nickname,realname,tel,wechat,identity')
->where(['id' => session('user.id')])
->find();
echo json_encode(['data' => $userInfo, 'code' => 20000]);
exit();
}
}
/**
* @title 我的优惠券
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/discountCoupon
* @method POST
*
* @param name:status type:char require:1 default:1 desc:1未使用2已使用3已过期
*
* @return version:版本号
* @return code:错误码
* @return id:优惠券id
* @return reduce:减
* @return discount_coupon_name:优惠券名称
* @return deadline:截止日期
*/
public function discountCoupon()
{
$request = request();
if ($request->isPost()) {
$post = $request->param();
$user_id = session('user.id');
$model = new CouponModel;
$data = $model->getAllDiscountCouponByUniqueIdAndByStatus($post['status'], $user_id);
if (empty($data)) {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
} else {
echo json_encode(['data' => $data, 'code' => 20000]);
exit();
}
}
}
/**
* @title 我要充值
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/charge
* @method POST
*
* @param name:is_bonus type:int require:1 default:0 desc:0普通充值1活动专享
*
* @return version:版本号
* @return code:错误码
* @return id:充值卡id
* @return denomination:面值
* @return bonus:赠送金额
*/
public function charge()
{
$is_bonus = request()->param('is_bonus');
$where['is_on_sale'] = ['eq', 1];
$is_bonus = (empty($is_bonus)) ? 0 : 1;
$where['is_bonus'] = ['eq', $is_bonus];
$field = 'id,denomination';
if ($is_bonus == 1) {
$field .= ',bonus';
}
$res = Db::name('charge')->field($field)->where($where)->select()->toArray();
echo json_encode(['data' => $res, 'code' => 20000]);
exit();
}
}
\ No newline at end of file
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="#A" data-toggle="tab">生成</a></li>
</ul>
<form class="form-horizontal margin-top-20" action="{:url('DiscountCoupon/add')}" method="post">
<div class="tabbable" style="float: left;">
<div class="tab-content">
<div class="tab-pane active" id="A">
<fieldset>
<div class="control-group">
<label class="control-label">优惠券名称</label>
<div class="controls">
<input class="form-control" type="text" name="discount_coupon_name" value="">
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<input class="form-control" type="number" name="overflow" value="">
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<input class="form-control" type="number" name="reduce" value="">
</div>
</div>
<div class="control-group">
<label class="control-label">截止日期</label>
<div class="controls">
<input type="text" name="deadline" class="form-control js-bootstrap-datetime" autocomplete="off">
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div class="user_list" style="float: left; margin-left: 100px; width: 350px; height:500px; overflow: scroll; overflow-x:hidden">
<table class="table table-hover table-bordered table-list" id="TABLE">
<tr>
<th><input type="checkbox" id="All" onclick="checkAll()"></th>
<th><input class="form-control" style="width: 200px; display: unset" type="text" placeholder="关键词" id="Search" onchange="ajax()">&nbsp;&nbsp;搜索</th>
</tr>
<volist name="user" id="vo">
<tr>
<td><input type="checkbox" name="user_id[]" value="{$vo.id}"></td>
<td>{$vo.user_nickname}</td>
</tr>
</volist>
</table>
</div>
<div style="clear: both">&nbsp;</div>
<div class="form-actions" style="clear: both">
<button class="btn btn-primary js-ajax-submit"type="submit">生成</button>
<a class="btn btn-default" href="javascript:history.back(-1);">返回</a>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script>
function ajax() {
$.ajax({
url:"{:url('DiscountCoupon/getUserList')}",
data:{
keywords:$("#Search").val()
},
type:"POST",
dataType:"JSON",
success:function (data) {
//alert(data.data);
$("#TABLE").html(data.data);
}
})
}
function checkAll() {
var input = $("#TABLE input[type='checkbox']");
var go = true;
if(input[0].checked === false) {
go = false;
}
for (var i = 1; i <= input.length; i++) {
input[i].checked = go;
}
}
</script>
</body>
</html>
\ No newline at end of file
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="#A" data-toggle="tab">编辑</a></li>
</ul>
<form class="form-horizontal margin-top-20" action="{:url('DiscountCoupon/edit')}" method="post">
<div class="tabbable" style="float: left">
<div class="tab-content">
<div class="tab-pane active" id="A">
<fieldset>
<div class="control-group">
<label class="control-label">优惠券名称</label>
<div class="controls">
<input class="form-control" type="text" name="discount_coupon_name" value="{$info.discount_coupon_name}">
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<input class="form-control" type="number" name="overflow" value="{$info.overflow}">
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<input class="form-control" type="number" name="reduce" value="{$info.reduce}">
</div>
</div>
<div class="control-group">
<label class="control-label">截止日期</label>
<div class="controls">
<input class="form-control js-bootstrap-datetime" type="text" name="deadline" value="{$info.deadline|date='Y-m-d H:i',###}" autocomplete="off">
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div style="clear: both">&nbsp;</div>
<div class="form-actions" style="clear: both">
<input type="hidden" name="id" value="{$id}">
<button class="btn btn-primary js-ajax-submit"type="submit">编辑</button>
<a class="btn btn-default" href="javascript:history.back(-1);">返回</a>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="javascript:;">优惠券列表</a></li>
<li><a href="{:url('DiscountCoupon/add')}">生成优惠券</a></li>
</ul>
<form class="js-ajax-form" action="" method="post">
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
<th>序号</th>
<th>所属人员</th>
<th>优惠券名称</th>
<th>截止日期</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<volist name="posts" id="vo" key="k">
<tr>
<td>{$k}</td>
<td>{$vo.user_nickname}</td>
<td>{$vo.discount_coupon_name}</td>
<td><if condition="$vo.deadline eq '2147483647'">永久<else/>{$vo.deadline|date='Y-m-d',###}</if></td>
<td>
<if condition="$vo.status eq '1'">
<font color="red">未使用</font>
</if>
<if condition="$vo.status eq '2'">
<font color="green">已使用</font>
</if>
<if condition="$vo.status eq '3'">
<font color="#808080">已过期</font>
</if>
</td>
<td>
<a href="{:url('DiscountCoupon/edit',array('id'=>$vo['id']))}"><font color="#1e90ff">编辑</font></a> |
<a href="{:url('DiscountCoupon/del',array('id'=>$vo['id']))}" onclick="return isDel()"><font color="red">销毁</font></a>
</td>
</tr>
</volist>
</table>
<ul class="pagination">{$page|default=''}</ul>
</form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script>
function isDel() {
if(!window.confirm('是否确认销毁优惠券')) {
return false;
}else{
return true;
}
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -3,24 +3,25 @@ namespace Api\Doc;
class Doc
{
protected $config = [
'title'=>'APi接口文档',
'version'=>'1.0.0',
'copyright'=>'银河百荣科技',
protected $config = [
'title' => 'APi接口文档',
'version' => '1.0.0',
'copyright' => '银河百荣科技',
'controller' => [
'app\portal\controller\IndexController',
'app\escort\controller\EscortController',
'app\activity\controller\ActivityController'
'app\activity\controller\ActivityController',
'app\user\controller\CenterController'
],
'password'=>'bronet',
'static_path'=>'',
'filter_method'=>['_empty'],
'password' => 'bronet',
'static_path' => '',
'filter_method' => ['_empty'],
'return_format' => [
'code' => "状态码20000/40000+",
'msg' => "提示信息",
],
'public_header'=>[],
'public_param'=>[]
'public_header' => [],
'public_param' => []
];
/**
... ... @@ -47,7 +48,7 @@ class Doc
/**
* 设置验证码配置
* @access public
* @param string $name 配置名称
* @param string $name 配置名称
* @param string $value 配置值
* @return void
*/
... ... @@ -77,52 +78,48 @@ class Doc
{
$controller = $this->config['controller'];
$list = [];
foreach ($controller as $class)
{
if(class_exists($class))
{
foreach ($controller as $class) {
if (class_exists($class)) {
$module = [];
$reflection = new \ReflectionClass($class);
$doc_str = $reflection->getDocComment();
$doc = new DocParser();
$class_doc = $doc->parse($doc_str);
$module = $class_doc;
$module = $class_doc;
$module['class'] = $class;
$method = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
$filter_method = array_merge(['__construct'], $this->config['filter_method']);
$module['actions'] = [];
foreach ($method as $action){
if(!in_array($action->name, $filter_method))
{
foreach ($method as $action) {
if (!in_array($action->name, $filter_method)) {
$doc = new DocParser();
$doc_str = $action->getDocComment();
if($doc_str)
{
if ($doc_str) {
$action_doc = $doc->parse($doc_str);
$action_doc['name'] = $class."::".$action->name;
if(array_key_exists('title', $action_doc)){
if(array_key_exists('module', $action_doc)){
$action_doc['name'] = $class . "::" . $action->name;
if (array_key_exists('title', $action_doc)) {
if (array_key_exists('module', $action_doc)) {
$key = array_search($action_doc['module'], array_column($module['actions'], 'title'));
if($key === false){
if ($key === false) {
$action = $module;
$action['title'] = $action_doc['module'];
$action['module'] = $action_doc['module'];
$action['actions'] = [];
array_push($action['actions'], $action_doc);
array_push($module['actions'], $action);
}else{
} else {
array_push($module['actions'][$key]['actions'], $action_doc);
}
}else{
} else {
array_push($module['actions'], $action_doc);
}
}
}
}
}
if(array_key_exists('group', $module)){
if (array_key_exists('group', $module)) {
$key = array_search($module['group'], array_column($list, 'title'));
if($key === false){ //创建分组
if ($key === false) { //创建分组
$floder = [
'title' => $module['group'],
'description' => '',
... ... @@ -132,10 +129,10 @@ class Doc
];
array_push($floder['actions'], $module);
array_push($list, $floder);
}else{
} else {
array_push($list[$key]['actions'], $module);
}
}else{
} else {
array_push($list, $module);
}
}
... ... @@ -157,21 +154,19 @@ class Doc
$doc_str = $reflection->getDocComment();
$doc = new DocParser();
$class_doc = $doc->parse($doc_str);
if(array_key_exists('group', $class_doc)){
if (array_key_exists('group', $class_doc)) {
$key = array_search($class_doc['group'], array_column($list, 'title'));
if($key === false){ //创建分组
if ($key === false) { //创建分组
$floder = [
'title' => $class_doc['group'],
'children' => []
];
array_push($floder['children'], $class_doc);
array_push($list, $floder);
}
else
{
} else {
array_push($list[$key]['children'], $class_doc);
}
}else{
} else {
array_push($list, $class_doc);
}
}
... ... @@ -188,18 +183,18 @@ class Doc
public function getInfo($class, $action)
{
$action_doc = [];
if($class && class_exists($class)){
if ($class && class_exists($class)) {
$reflection = new \ReflectionClass($class);
$doc_str = $reflection->getDocComment();
$doc = new DocParser();
$class_doc = $doc->parse($doc_str);
$class_doc['header'] = isset($class_doc['header'])? $class_doc['header'] : [];
$class_doc['header'] = isset($class_doc['header']) ? $class_doc['header'] : [];
$class_doc['param'] = isset($class_doc['param']) ? $class_doc['param'] : [];
if($reflection->hasMethod($action)) {
if ($reflection->hasMethod($action)) {
$method = $reflection->getMethod($action);
$doc = new DocParser();
$action_doc = $doc->parse($method->getDocComment());
$action_doc['name'] = $class."::".$method->name;
$action_doc['name'] = $class . "::" . $method->name;
$action_doc['header'] = isset($action_doc['header']) ? array_merge($class_doc['header'], $action_doc['header']) : $class_doc['header'];
$action_doc['param'] = isset($action_doc['param']) ? array_merge($class_doc['param'], $action_doc['param']) : $class_doc['param'];
}
... ... @@ -216,27 +211,22 @@ class Doc
{
$controller = $this->config['controller'];
$list = [];
foreach ($controller as $class)
{
if(class_exists($class))
{
foreach ($controller as $class) {
if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
$method = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
$filter_method = array_merge(['__construct'], $this->config['filter_method']);
foreach ($method as $action){
if(!in_array($action->name, $filter_method))
{
foreach ($method as $action) {
if (!in_array($action->name, $filter_method)) {
$doc = new DocParser();
$doc_str = $action->getDocComment();
if($doc_str)
{
if ($doc_str) {
$action_doc = $doc->parse($doc_str);
$action_doc['name'] = $class."::".$action->name;
if((isset($action_doc['title']) && strpos($action_doc['title'], $keyword) !== false)
|| (isset($action_doc['description']) && strpos($action_doc['description'], $keyword) !== false)
|| (isset($action_doc['author']) && strpos($action_doc['author'], $keyword) !== false)
|| (isset($action_doc['url']) && strpos($action_doc['url'], $keyword) !== false))
{
$action_doc['name'] = $class . "::" . $action->name;
if ((isset($action_doc['title']) && strpos($action_doc['title'], $keyword) !== false)
|| (isset($action_doc['description']) && strpos($action_doc['description'], $keyword) !== false)
|| (isset($action_doc['author']) && strpos($action_doc['author'], $keyword) !== false)
|| (isset($action_doc['url']) && strpos($action_doc['url'], $keyword) !== false)) {
array_push($list, $action_doc);
}
}
... ... @@ -256,17 +246,16 @@ class Doc
{
$json = '{<br>';
$data = $this->config['return_format'];
foreach ($data as $name=>$value) {
$json .= '&nbsp;&nbsp;"'.$name.'":'.$value.',<br>';
foreach ($data as $name => $value) {
$json .= '&nbsp;&nbsp;"' . $name . '":' . $value . ',<br>';
}
$json .= '&nbsp;&nbsp;"data":{<br/>';
$returns = isset($doc['return']) ? $doc['return'] : [];
foreach ($returns as $val)
{
list($name, $value) = explode(":", trim($val));
if(strpos($value, '@') != false){
foreach ($returns as $val) {
list($name, $value) = explode(":", trim($val));
if (strpos($value, '@') != false) {
$json .= $this->string2jsonArray($doc, $val, '&nbsp;&nbsp;&nbsp;&nbsp;');
}else{
} else {
$json .= '&nbsp;&nbsp;&nbsp;&nbsp;' . $this->string2json(trim($name), $value);
}
}
... ... @@ -281,11 +270,12 @@ class Doc
* @param $val
* @return string
*/
private function string2json($name, $val){
if(strpos($val,'#') != false){
return '"'.$name.'": ["'.str_replace('#','',$val).'"],<br/>';
}else {
return '"'.$name.'":"'.$val.'",<br/>';
private function string2json($name, $val)
{
if (strpos($val, '#') != false) {
return '"' . $name . '": ["' . str_replace('#', '', $val) . '"],<br/>';
} else {
return '"' . $name . '":"' . $val . '",<br/>';
}
}
... ... @@ -296,28 +286,29 @@ class Doc
* @param $space
* @return string
*/
private function string2jsonArray($doc, $val, $space){
list($name, $value) = explode(":", trim($val));
private function string2jsonArray($doc, $val, $space)
{
list($name, $value) = explode(":", trim($val));
$json = "";
if(strpos($value, "@!") != false){
$json .= $space.'"'.$name.'":{//'.str_replace('@!','',$value).'<br/>';
}else{
$json .= $space.'"'.$name.'":[{//'.str_replace('@','',$value).'<br/>';
if (strpos($value, "@!") != false) {
$json .= $space . '"' . $name . '":{//' . str_replace('@!', '', $value) . '<br/>';
} else {
$json .= $space . '"' . $name . '":[{//' . str_replace('@', '', $value) . '<br/>';
}
$return = isset($doc[$name]) ? $doc[$name] : [];
if(preg_match_all('/(\w+):(.*?)[\s\n]/s', $return." ", $meatchs)){
foreach ($meatchs[0] as $key=>$v){
if(strpos($meatchs[2][$key],'@') != false){
$json .= $this->string2jsonArray($doc,$v,$space.'&nbsp;&nbsp;');
} else{
$json .= $space.'&nbsp;&nbsp;'. $this->string2json(trim($meatchs[1][$key]), $meatchs[2][$key]);
if (preg_match_all('/(\w+):(.*?)[\s\n]/s', $return . " ", $meatchs)) {
foreach ($meatchs[0] as $key => $v) {
if (strpos($meatchs[2][$key], '@') != false) {
$json .= $this->string2jsonArray($doc, $v, $space . '&nbsp;&nbsp;');
} else {
$json .= $space . '&nbsp;&nbsp;' . $this->string2json(trim($meatchs[1][$key]), $meatchs[2][$key]);
}
}
}
if(strpos($value, "@!") != false){
$json .= $space."}<br/>";
}else{
$json .= $space."}]<br/>";
if (strpos($value, "@!") != false) {
$json .= $space . "}<br/>";
} else {
$json .= $space . "}]<br/>";
}
return $json;
}
... ...