305 lines
12 KiB
PHP
305 lines
12 KiB
PHP
<?php
|
||
|
||
namespace app\ZengJieCode\controller\app;
|
||
|
||
use think\Db;
|
||
use think\Cache;
|
||
|
||
class Savemsg extends Base{
|
||
|
||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||
protected $max_box_num = 10;
|
||
protected $name_list = [
|
||
[
|
||
'name'=>'LS-2502',
|
||
'character_uuid'=>'2A25',
|
||
'service_uuid'=>'180A'
|
||
],
|
||
|
||
];
|
||
protected $name_default = 0;
|
||
protected $kitchenscale_db_msg = [
|
||
'cookbook'=>'app_user_cookbook',//菜谱表
|
||
'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
|
||
'user'=>'app_user_data',//banner
|
||
];
|
||
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
################################################################百度接口################################################################
|
||
################################################################百度接口################################################################
|
||
################################################################百度接口################################################################
|
||
|
||
// 获取配置信息
|
||
public function config_msg(){
|
||
try {
|
||
$result = $this->config_msg_action();
|
||
return $this->msg($result);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
|
||
}
|
||
|
||
public function save_sn_msg($data = ['sn_code'=>'564654564654654','bl_name'=>'bl_5520']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('sn_code', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!array_key_exists('bl_name', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['sn_code'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['bl_name'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
$result = $this->save_sn_msg_action($data);
|
||
return $result;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
// dump($data);
|
||
// die;
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
|
||
}
|
||
|
||
public function save_box_msg($data = ['sn_code_all'=>'564654564654654,564654564654654','box_serial_number'=>'996589585']){
|
||
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('sn_code_all', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!array_key_exists('box_serial_number', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['sn_code_all'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['box_serial_number'],'num&letter')){
|
||
return $this->msg(10005);
|
||
}
|
||
$result = $this->save_box_msg_action($data);
|
||
return $result;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
// dump($data);
|
||
// die;
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
|
||
}
|
||
|
||
public function print_again($data = ['code'=>'564654564654654','type'=>'sn']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('code', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!array_key_exists('type', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['code'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
|
||
$result = $this->print_again_action($data);
|
||
return $result;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
// dump($data);
|
||
// die;
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
########################################################################action########################################################################
|
||
########################################################################action########################################################################
|
||
########################################################################action########################################################################
|
||
|
||
public function config_msg_action(){
|
||
// $length = strlen("0065601800007037");
|
||
// // 生成200个随机数字字符串
|
||
// $randomStrings = [];
|
||
// for ($i = 0; $i < 200; $i++) {
|
||
// $randomString = '';
|
||
// for ($j = 0; $j < $length; $j++) {
|
||
// $randomString .= rand(0, 9); // 生成0-9的随机数字
|
||
// }
|
||
// $randomStrings[] = [
|
||
// 'bluetooth_name'=>'bl_5520',
|
||
// 'sn_code'=>$randomString,
|
||
// 'create_time'=>date('Y-m-d H:i:s'),
|
||
// ];
|
||
// }
|
||
// $zengjie = Db::connect('zengjie_db');
|
||
// $result = $zengjie->table('sn_code_all')->insertAll($randomStrings);
|
||
// dump($result);
|
||
// die;
|
||
$data = [
|
||
'max_box_num'=>$this->max_box_num,
|
||
'name_list'=>$this->name_list,
|
||
'name_default_key'=>$this->name_default,
|
||
|
||
];
|
||
return $data;
|
||
}
|
||
|
||
public function save_sn_msg_action($data){
|
||
$zengjie = Db::connect('zengjie_db');
|
||
// $sn_code = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['sn_code']])->count();
|
||
// if($sn_code > 0){
|
||
// return $this->msg(10002,'该码已录入');
|
||
// }
|
||
$result = $zengjie->table('sn_code_all')->insert([
|
||
'sn_code'=>$data['sn_code'],
|
||
'bluetooth_name'=>$data['bl_name'],
|
||
'create_time'=>date('Y-m-d H:i:s'),
|
||
]);
|
||
if($result){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002,'录入失败');
|
||
}
|
||
}
|
||
|
||
public function save_box_msg_action($data){
|
||
$zengjie = Db::connect('zengjie_db');
|
||
|
||
$box_num = $zengjie->table('box_code_all')->where(['box_code'=>$data['box_serial_number']])->count();
|
||
$box_num = $box_num+1;
|
||
$result = $zengjie->table('box_code_all')->insert([
|
||
'box_code'=>$data['box_serial_number'],
|
||
'box_num'=>$box_num,
|
||
'create_time'=>date('Y-m-d H:i:s'),
|
||
'content_str'=>$data['sn_code_all'],
|
||
]);
|
||
|
||
if($result){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002,'录入失败');
|
||
}
|
||
|
||
// try {
|
||
// // 使用事务闭包,TP5会自动管理事务
|
||
// $result = $zengjie->transaction(function() use ($zengjie, $data) {
|
||
// $sn_code = $zengjie->table('box_code_all')->where(['box_code'=>$data['box_serial_number']])->count();
|
||
// $num = $sn_code+1;
|
||
|
||
// $box_id = $zengjie->table('box_code_all')->insertGetId([
|
||
// 'box_code'=>$data['box_serial_number'],
|
||
// 'box_num'=>$num,
|
||
// 'create_time'=>date('Y-m-d H:i:s'),
|
||
// ]);
|
||
|
||
// // 使用安全的参数绑定方式
|
||
// $snCodes = explode(',', $data['sn_code_all']);
|
||
// $zengjie->table('sn_code_all')
|
||
// ->where('sn_code', 'in', $snCodes)
|
||
// ->update(['batch_id' => $box_id]);
|
||
|
||
// return $box_id;
|
||
// });
|
||
|
||
// return $this->msg(['id'=>$result]);
|
||
// } catch (\Exception $e) {
|
||
// trace('保存盒信息失败: ' . $e->getMessage(), 'error');
|
||
// return $this->msg(10002, '录入失败: ' . $e->getMessage());
|
||
// }
|
||
}
|
||
|
||
|
||
public function print_again_action($data){
|
||
$zengjie = Db::connect('zengjie_db');
|
||
if($data['type'] == 'sn'){
|
||
$result = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->count();
|
||
}else{
|
||
$result = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->count();
|
||
}
|
||
|
||
if($result <= 0){
|
||
return $this->msg(10002,'未找到该码录入');
|
||
}
|
||
|
||
if($data['type'] == 'sn'){
|
||
$result2 = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->update([
|
||
'is_print'=>3
|
||
]);
|
||
}else{
|
||
$result2 = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->update([
|
||
'is_print'=>0
|
||
]);
|
||
}
|
||
|
||
if($result){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002,'打印失败');
|
||
}
|
||
}
|
||
|
||
} |