作者 黎建湛

云订单的清理日志文件更新

@@ -52,6 +52,7 @@ $config = [ @@ -52,6 +52,7 @@ $config = [
52 'showScriptName' => false, 52 'showScriptName' => false,
53 'rules' => [ 53 'rules' => [
54 'index' => 'api/demo/getdemolist', 54 'index' => 'api/demo/getdemolist',
  55 + 'api/demo/testclearlogs' => 'api/demo/testclearlogs',
55 'POST api/demo/getdemolist' => 'api/demo/getdemolist', 56 'POST api/demo/getdemolist' => 'api/demo/getdemolist',
56 'POST api/demo/testdemoapi' => 'api/demo/testdemoapi', 57 'POST api/demo/testdemoapi' => 'api/demo/testdemoapi',
57 'POST api/demo/testdemoinfo' => 'api/demo/testdemoinfo', 58 'POST api/demo/testdemoinfo' => 'api/demo/testdemoinfo',
@@ -128,6 +128,32 @@ class DemoController extends Controller @@ -128,6 +128,32 @@ class DemoController extends Controller
128 exit(); 128 exit();
129 } 129 }
130 130
  131 + public function actionTestclearlogs()
  132 + {
  133 + // 获取前七天产生的日志文件目录
  134 + $dir = '../runtime/logs/'.date('Ymd', strtotime('-7 days'));
  135 +
  136 + // 文件目录是否存在
  137 + if (is_dir($dir)) {
  138 + // 打开目录句柄 操作文件夹
  139 + $handle = @opendir($dir);
  140 + // 循环使用句柄读取所在目录的文件
  141 + while(($file = @readdir($handle)) != false) {
  142 + // 如果文件不是隐藏文件
  143 + if ($file != '.' && $file != '..') {
  144 + // 获取文件夹名称或者文件名称
  145 + $dirName = $dir.'/'.$file;
  146 + // 判断文件是文件夹还是文件 rmdir 删除目录 unlink 删除文件
  147 + is_dir($dirName) ? rmdir($dirName) : @unlink($dirName);
  148 + }
  149 + }
  150 + // 关闭目录句柄
  151 + closedir($handle);
  152 + }
  153 +
  154 + return rmdir($dir);
  155 + }
  156 +
131 public function getExcel($name,$title,$arr,$data,$width = false) { 157 public function getExcel($name,$title,$arr,$data,$width = false) {
132 //设置导出文件名 158 //设置导出文件名
133 $file_name = date("Y-m-d") . "-".$name."数据.xlsx"; 159 $file_name = date("Y-m-d") . "-".$name."数据.xlsx";
@@ -211,18 +237,6 @@ class DemoController extends Controller @@ -211,18 +237,6 @@ class DemoController extends Controller
211 return $data['data']; 237 return $data['data'];
212 } 238 }
213 239
214 - public function getDataInfo($and_where){  
215 - //$and_where = ['and', "uuid='{$id}'"]  
216 - return WarehouseModel::find()->andWhere($and_where)->one();  
217 - }  
218 -  
219 - public function getTableAllData($table,$where){  
220 - //查询表是否存在  
221 - $tables = Yii::$app->db->createCommand("SHOW TABLES LIKE '{$table}'")->queryAll();  
222 - if(empty($tables[0])) return [];  
223 - return Yii::$app->db->createCommand("SELECT * FROM `{$table}` WHERE {$where}")->queryAll();  
224 - }  
225 -  
226 /*public function truncateTable($table){ 240 /*public function truncateTable($table){
227 //验证表明是否nt_dw_20200516_196_phone 241 //验证表明是否nt_dw_20200516_196_phone
228 if(substr( $table, 0, 6 ) != 'nt_dw_' || substr( $table, 18, 24 ) != '_phone') return false; 242 if(substr( $table, 0, 6 ) != 'nt_dw_' || substr( $table, 18, 24 ) != '_phone') return false;
@@ -233,11 +247,6 @@ class DemoController extends Controller @@ -233,11 +247,6 @@ class DemoController extends Controller
233 return Yii::$app->db->createCommand($sql)->execute(); 247 return Yii::$app->db->createCommand($sql)->execute();
234 }*/ 248 }*/
235 249
236 - public function editDataData($where,$data){  
237 - //$data = ['status' => 1], $where = 'age > 30'  
238 - return Yii::$app->db->createCommand()->update('nt_data_warehouse', $data, $where)->execute();  
239 - }  
240 -  
241 // 测试接口 250 // 测试接口
242 public function actionTestdemoinfo() { 251 public function actionTestdemoinfo() {
243 // 测试端口模块 start 252 // 测试端口模块 start
@@ -509,16 +518,6 @@ class DemoController extends Controller @@ -509,16 +518,6 @@ class DemoController extends Controller
509 return array_filter($user); 518 return array_filter($user);
510 } 519 }
511 520
512 - // 数据库查询  
513 - public function getWarehouseAllPhoneDataAll(){  
514 - return Yii::$app->db->createCommand("SELECT phone FROM `nt_data_warehouse_all_phone`")->queryAll();  
515 - }  
516 -  
517 - // 数据库查询  
518 - public function getWarehouseAllPhoneInWhere($in){  
519 - return Yii::$app->db->createCommand("SELECT phone FROM `nt_data_warehouse_all_phone` WHERE phone IN ({$in})")->queryAll();  
520 - }  
521 -  
522 // 字符串格式 utf8格式化 521 // 字符串格式 utf8格式化
523 public function StrToUtf8($str){ 522 public function StrToUtf8($str){
524 $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5')); 523 $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
@@ -561,6 +560,32 @@ class DemoController extends Controller @@ -561,6 +560,32 @@ class DemoController extends Controller
561 } 560 }
562 561
563 /**********DAO**********/ 562 /**********DAO**********/
  563 + public function getDataInfo($and_where){
  564 + //$and_where = ['and', "uuid='{$id}'"]
  565 + return WarehouseModel::find()->andWhere($and_where)->one();
  566 + }
  567 +
  568 + public function getTableAllData($table,$where){
  569 + //查询表是否存在
  570 + $tables = Yii::$app->db->createCommand("SHOW TABLES LIKE '{$table}'")->queryAll();
  571 + if(empty($tables[0])) return [];
  572 + return Yii::$app->db->createCommand("SELECT * FROM `{$table}` WHERE {$where}")->queryAll();
  573 + }
  574 +
  575 + public function editDataData($where,$data){
  576 + //$data = ['status' => 1], $where = 'age > 30'
  577 + return Yii::$app->db->createCommand()->update('nt_data_warehouse', $data, $where)->execute();
  578 + }
  579 +
  580 + // 数据库查询
  581 + public function getWarehouseAllPhoneDataAll(){
  582 + return Yii::$app->db->createCommand("SELECT phone FROM `nt_data_warehouse_all_phone`")->queryAll();
  583 + }
  584 +
  585 + // 数据库查询
  586 + public function getWarehouseAllPhoneInWhere($in){
  587 + return Yii::$app->db->createCommand("SELECT phone FROM `nt_data_warehouse_all_phone` WHERE phone IN ({$in})")->queryAll();
  588 + }
564 589
565 public function editStaffData($where,$data){ 590 public function editStaffData($where,$data){
566 //$data = ['status' => 1], $where = 'age > 30' 591 //$data = ['status' => 1], $where = 'age > 30'