2024-03-15 18:15:17 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\app\controller;
|
|
|
|
|
|
|
|
|
|
use think\Controller;
|
|
|
|
|
use think\Db;
|
|
|
|
|
use app\bj\controller\Common;
|
|
|
|
|
use think\Log;
|
|
|
|
|
use \think\Validate;
|
|
|
|
|
|
|
|
|
|
class Card extends Controller{
|
|
|
|
|
|
|
|
|
|
|
2024-03-29 18:34:01 +08:00
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
|
|
|
|
// 存储卡片顺序
|
|
|
|
|
// $data = ['user_token'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]]
|
|
|
|
|
public function save_card_order(){
|
|
|
|
|
$data = input();
|
2024-04-03 18:15:07 +08:00
|
|
|
if(!array_key_exists('order_list', $data) || !array_key_exists('user_token', $data)){
|
2024-03-29 18:34:01 +08:00
|
|
|
return $this->msg(10001,'数据格式错误');
|
|
|
|
|
}
|
|
|
|
|
if(!$this->isNumericArray($data['order_list'])){
|
|
|
|
|
return $this->msg(10002,'数据内参数格式或值错误');
|
|
|
|
|
}
|
|
|
|
|
$data['order_list'] = json_encode($data['order_list']);
|
|
|
|
|
$result = Db::table('app_user_data')->where(['id'=>$data['user_token']])->update(['card_order'=>$data['order_list']]);
|
|
|
|
|
if($result){
|
|
|
|
|
return $this->msg(0,'success');
|
2024-03-15 18:15:17 +08:00
|
|
|
}else{
|
2024-03-29 18:34:01 +08:00
|
|
|
return $this->msg(10003,'修改失败');
|
2024-03-15 18:15:17 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 18:15:07 +08:00
|
|
|
// 获取卡片列表
|
|
|
|
|
// $data = ['id'=>'2','time'=>'1991-04-20',content=>'15个']
|
|
|
|
|
public function get_card_list(){
|
|
|
|
|
$data = input();
|
|
|
|
|
if(!array_key_exists('ann_id', $data) || !array_key_exists('time', $data) || !array_key_exists('content', $data)){
|
|
|
|
|
return $this->msg(10001,'数据格式错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = Db::table('app_card_data_log')->insert(['aud_id'=>$data['id'],'log_time'=>$data['time'],'content'=>$data['content'],'create_time'=>date('Y-m-d H:i:s')]);
|
|
|
|
|
if($result){
|
|
|
|
|
return $this->msg(0,'success');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10003,'添加失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 18:34:01 +08:00
|
|
|
// 添加卡片规则
|
|
|
|
|
// $data = ['user_token'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]]
|
|
|
|
|
public function add_card_rule(){
|
|
|
|
|
$data = input();
|
|
|
|
|
if(!array_key_exists('order_list', $data) || !array_key_exists('user_token', $data)){
|
|
|
|
|
return $this->msg(10001,'数据格式错误');
|
|
|
|
|
}
|
|
|
|
|
if(!$this->isNumericArray($data['order_list'])){
|
|
|
|
|
return $this->msg(10002,'数据内参数格式或值错误');
|
|
|
|
|
}
|
|
|
|
|
$data['order_list'] = json_encode($data['order_list']);
|
|
|
|
|
$result = Db::table('app_user_data')->where(['id'=>$data['user_token']])->update(['card_order'=>$data['order_list']]);
|
|
|
|
|
if($result){
|
|
|
|
|
return $this->msg(0,'success');
|
2024-03-15 18:15:17 +08:00
|
|
|
}else{
|
2024-03-29 18:34:01 +08:00
|
|
|
return $this->msg(10003,'修改失败');
|
2024-03-15 18:15:17 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 18:15:07 +08:00
|
|
|
// 添加卡片记录
|
|
|
|
|
// $data = ['id'=>'2','time'=>'1991-04-20',content=>'15个']
|
|
|
|
|
public function add_card_data(){
|
|
|
|
|
$data = input();
|
|
|
|
|
if(!array_key_exists('ann_id', $data) || !array_key_exists('time', $data) || !array_key_exists('content', $data)){
|
|
|
|
|
return $this->msg(10001,'数据格式错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = Db::table('app_card_data_log')->insert(['aud_id'=>$data['id'],'log_time'=>$data['time'],'content'=>$data['content'],'create_time'=>date('Y-m-d H:i:s')]);
|
|
|
|
|
if($result){
|
|
|
|
|
return $this->msg(0,'success');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10003,'添加失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 18:15:17 +08:00
|
|
|
|
2024-03-29 18:34:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-15 18:15:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################other################################################################
|
|
|
|
|
################################################################other################################################################
|
|
|
|
|
################################################################other################################################################
|
|
|
|
|
|
2024-03-29 18:34:01 +08:00
|
|
|
// 检查变量是否是一个只有数字的一维数组
|
|
|
|
|
function isNumericArray($array) {
|
|
|
|
|
if (!is_array($array)) {
|
|
|
|
|
return false; // 变量不是数组
|
2024-03-15 18:15:17 +08:00
|
|
|
}
|
2024-03-29 18:34:01 +08:00
|
|
|
foreach ($array as $value) {
|
|
|
|
|
if (!is_numeric($value)) {
|
|
|
|
|
return false; // 数组中包含非数字元素
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$result = Db::table('app_card_data')->where(['is_del'=>1])->cache(true,3600)->column('id');//查询结果缓存3600秒
|
|
|
|
|
if(empty(array_diff($array, $result))){
|
|
|
|
|
return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
|
|
|
|
|
}else{
|
|
|
|
|
return false;//跟数据库比对过,存在无效数值
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 18:15:17 +08:00
|
|
|
|
|
|
|
|
public function msg($code,$msg='',$data=[]){
|
|
|
|
|
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|