api接口

This commit is contained in:
wanyongkang
2020-10-05 13:43:53 +08:00
parent a331e3f1d5
commit ce067b91dc
9 changed files with 198 additions and 103 deletions

5
.htaccess Normal file
View File

@@ -0,0 +1,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1

View File

@@ -0,0 +1,38 @@
<?php
namespace app\api\controller;
use app\api\model\Test;
use app\api\model\User;
class Index
{
public function index()
{
$test = new Test();
$list = $test->field('user,operation,record,create_time')->order('id')->limit('50')->fetchAll();
$count = $test->field('count(1) as count')->fetch();
$data = [
'Code'=>10000,
'count'=>$count['count'],
'data'=>$list
];
echo json_encode($data);
}
//获取指定页码数据
public function pageList()
{
if(!$_GET){
die;
}
$page = ($_GET['page'] - 1) * 50;
$test = new Test();
$list = $test->limit("$page,50")->fetchAll();
$data = [
'Code'=>10000,
'data'=>$list
];
echo json_encode($data);
}
}

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace app\test\model; namespace app\api\model;
use fastphp\base\Model; use fastphp\base\Model;

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace app\test\model; namespace app\api\model;
use fastphp\base\Model; use fastphp\base\Model;

View File

@@ -1,74 +0,0 @@
<?php
namespace app\test\controller;
use app\test\model\Test;
use app\test\model\User;
class Index
{
public function index()
{
$test = new Test();
$user = new User();
$list = $test->fetchAll();
$userlist = $user->field('`LoginCode`')->fetchAll();
$user_manager = [];
$user_product = [];
$user_vip_price = [];
$user_contact = [];
$user_next = [];
$sell_order = [];
$sell_order_next = [];
foreach ($list as $info) {
switch ($info['operation']) {
case '点击客户管理':
$user_manager[] = $info;
break;
case '点击客户信息产品账号':
$user_product[] = $info;
break;
case '点击客户信息会员价':
$user_vip_price[] = $info;
break;
case '点击客户更多联系方式':
$user_contact[] = $info;
break;
case '点击客户信息下一页':
$user_next[] = $info;
break;
case '点击销售订单':
$sell_order[] = $info;
break;
case '点击销售订单下一页':
$sell_order_next[] = $info;
break;
}
}
$i = 0;
$j = 0;
$user_f_list = [];
$user_l = '';
foreach ($userlist as $info) {
//处理客户管理
if ($i % 50 != 0 || $i==0) {
$user_l .= $info['LoginCode'].',';
} else {
$user_l = '';
$j++;
}
$user_f_list[$j] = $user_l;
$i++;
}
foreach($user_manager as $k=>$v){
}
}
}

View File

@@ -22,12 +22,15 @@ class Fastphp
//运行程序 //运行程序
public function run(){ public function run(){
global $is_script;
spl_autoload_register(array($this,'loadClass')); spl_autoload_register(array($this,'loadClass'));
$this->setReporting(); $this->setReporting();
$this->unregisterGlobals(); $this->unregisterGlobals();
$this->setDbConfig(); $this->setDbConfig();
if(!$is_script){
$this->route(); $this->route();
} }
}
//路由处理 //路由处理
public function route(){ public function route(){

View File

@@ -29,19 +29,19 @@ class Sql
$this->param = []; $this->param = [];
$this->filter = ''; $this->filter = '';
if($where){ if($where){
$this->filter .= 'WHERE '; $this->filter .= ' WHERE ';
if(is_string($where)){ if(is_string($where)){
$this->filter .= $where; $this->filter .= ' '.$where;
} else { } else {
$flag = true; $flag = true;
foreach ($where as $key => $value){ foreach ($where as $key => $value){
if($flag){ if($flag){
$flag = false; $flag = false;
if(is_array($value)){ if(is_array($value)){
$this->filter .= '`'.$key.'` '.$value[0].' :'.$key; $this->filter .= ' `'.$key.'` '.$value[0].' :'.$key;
$this->param[$key] = $value[1]; $this->param[$key] = $value[1];
} else { } else {
$this->filter .= '`'.$key.'` = :'.$key; $this->filter .= ' `'.$key.'` = :'.$key;
$this->param[$key] = $value; $this->param[$key] = $value;
} }
} else { } else {
@@ -64,14 +64,14 @@ class Sql
* @param array $order 排序条件 * @param array $order 排序条件
* @return $this * @return $this
*/ */
public function order($order = []){ public function order($order = 'id',$type = 'desc'){
if($order){ if($order){
$this->filter .= 'ORDER BY '; $this->filter .= ' ORDER BY '.$order.' '.$type.' ';
$this->filter .= implode(' ,',$order);
} }
return $this; return $this;
} }
/** /**
* group by * group by
* @param array $order * @param array $order
@@ -79,12 +79,22 @@ class Sql
*/ */
public function group($order = []){ public function group($order = []){
if($order){ if($order){
$this->filter .= 'GROUP BY '; $this->filter .= ' GROUP BY ';
$this->filter .= implode(' ,',$order); $this->filter .= ' '.implode(' ,',$order).' ';
} }
return $this; return $this;
} }
/**
* 查询limit
* @param string
* @return $this
*/
public function limit($limit = '100'){
$this->filter .= ' LIMIT '.$limit.' ';
return $this;
}
/** /**
* 查询字段 * 查询字段
* @param string $field * @param string $field

View File

@@ -1,9 +1,17 @@
<?php <?php
//error_reporting( E_ALL&~E_NOTICE );
//ini_set( 'display_errors', 'on' ); header('Access-Control-Allow-Origin: *');
header("Content-type:text/html;charset=utf-8"); header("Access-Control-Allow-Methods: *");
header('Access-Control-Allow-Headers:*');
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL ^ E_WARNING);
//内存限制 //内存限制
ini_set (memory_limit, 128M) ; ini_set ('memory_limit', '1024M');
//应用目录为当前目录 //应用目录为当前目录
define('APP_PATH',__DIR__.'/'); define('APP_PATH',__DIR__.'/');
@@ -19,16 +27,3 @@ $config = require APP_PATH.'config/config.php';
//实例化框架类 //实例化框架类
(new fastphp\Fastphp($config))->run(); (new fastphp\Fastphp($config))->run();
//require './Autoload.php';
//
//
//spl_autoload_register('Autoload::loadTest');
//
//$inn = new \app\Demo();
//$inn->abs(-123);
//echo '<br>';
//
//$urls = explode('/',$_SERVER['REQUEST_URI']);
//
//var_dump($urls);

118
script/test.php Normal file
View File

@@ -0,0 +1,118 @@
<?php
$is_script = 1;
include '../index.php';
use app\api\model\Test;
use app\api\model\User;
$test = new Test();
$user = new User();
$list = $test->fetchAll();
$userlist = $user->field('`LoginCode`')->fetchAll();
$user_manager = [];
$user_product = [];
$user_vip_price = [];
$user_contact = [];
$export_info = [];
foreach ($list as $info) {
switch ($info['operation']) {
case '点击客户管理':
$user_manager[] = $info;
break;
case '点击客户信息产品账号':
$user_product[] = $info;
break;
case '点击客户信息会员价':
$user_vip_price[] = $info;
break;
case '点击客户更多联系方式':
$user_contact[] = $info;
break;
case '点击导出所有客户信息':
$export_info[] = $info;
break;
}
}
$i = 0;
$j = 0;
$user_f_list = [];
$recore_num = 1;
$user_l = '';
foreach ($userlist as $info) {
//处理客户管理
if ($i % 50 != 0 || $i == 0) {
$user_l .= $info['LoginCode'] . ',';
} else {
$user_l = '';
$j++;
}
$user_f_list[$j] = $user_l;
$i++;
}
$start_time = "2020-5-13 15:42:27";
//点击用户管理
foreach ($user_manager as $v) {
$data['info'] = $user_f_list[0];
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 32645);
echo '更新第'.$recore_num++.'条数据'."\r";
}
//用户管理下一页
$k = 0;
$start_time = "2020-5-13 19:16:59";
foreach ($user_next as $v) {
$data['info'] = $user_f_list[$k++];
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 13102);
echo '更新第'.$recore_num++.'条数据'."\r";
}
//点击客户信息产品账号
$k = 0;
$start_time = "2020-5-13 15:42:35";
foreach ($user_product as $v) {
$data['info'] = $userlist[$k++]['LoginCode'];
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 223);
echo '更新第'.$recore_num++.'条数据'."\r";
}
//点击客户信息会员价
$k = 0;
$start_time = "2020-5-13 15:42:57";
foreach ($user_vip_price as $v) {
$data['info'] = $userlist[$k++]['LoginCode'];
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 223);
echo '更新第'.$recore_num++.'条数据'."\r";
}
//点击客户更多联系方式
$k = 0;
$start_time = "2020-5-13 15:43:08";
foreach ($user_contact as $v) {
$data['info'] = $userlist[$k++]['LoginCode'];
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 223);
echo '更新第'.$recore_num++.'条数据'."\r";
}
// 点击导出所有客户信息
$start_time = "2020-5-13 15:45:37";
foreach($export_info as $v){
$data['info'] = '本次点击时间之前所有客户数据';
$data['create_time'] = $start_time;
$test->where(['id' => $v['id']])->update($data);
$start_time = date('Y-m-d H:i:s',strtotime($start_time) + 48000);
echo '更新第'.$recore_num++.'条数据'."\r";
}