123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- use think\facade\Filesystem;
- if(!function_exists("error")){
-
- function error($message,$code=1004,$data=null){
- return json(["code"=>$code,"message"=>$message,"data"=>$data]);
- }
- }
- if(!function_exists('success')){
-
- function success($message,$data=null,$code=0){
- return json(['code'=>$code,'message'=>$message,'data'=>$data]);
- }
- }
- if (!function_exists('action_in_arr')) {
-
- function action_in_arr(array $arr = []): bool
- {
- $arr = is_array($arr) ? $arr : explode(',', $arr);
- if (!$arr) {
- return false;
- }
- $arr = array_map('strtolower', $arr);
- if (in_array(strtolower(request()->action()), $arr) || in_array('*', $arr)) {
- return true;
- }
- return false;
- }
- }
- if(!function_exists("startTime")){
- function startTime($time){
- return date('Y-m-d 00:00:00',strtotime($time));
- }
- }
- if(!function_exists('endTime')){
- function endTime($time){
- return date('Y-m-d 23:59:59',strtotime($time));
- }
- }
- if(!function_exists('makeToken')){
- function makeToken($strs,$salt='',$type='md5'){
- if($salt=='') $salt=time();
- $type = is_callable($type) ? $type : 'md5';
- $token = call_user_func($type,$strs.$salt);
- return $token;
- }
- };
- if(!function_exists('makeNo')){
- function makeNo($strs,$salt=''){
- $date=date('mdHis');
- $year = date('Y')-2000;
- if($salt=="")$salt=\think\helper\Str::random(4,1);
- return $strs.$year.$date.$salt;
- }
- };
- if(!function_exists('__')){
- function __($msg){
- return $msg;
- }
- };
- if(!function_exists('UploadImg')){
- function UploadImg($files){
- $savename = [];
- $files = !is_array($files) ? [$files] : $files;
- try {
-
- validate(['imgFile' => ['fileSize' => 10240000, 'fileExt' => 'jpg,jpeg,png,bmp,gif', 'fileMime' => 'image/jpeg,image/png,image/gif']])->check(['imgFile' => $files]);
- foreach ($files as $file) {
- $url = Filesystem::disk('public')->putFile('topic/' . date('Ymd'), $file, function () use ($file) {
- return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . '_' . date('YmdHis'));
- });
- $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
- $temp = ['url' => $url, 'name' => $name];
- $savename[] = $temp;
- }
- return $savename;
- } catch (\think\exception\ValidateException $e) {
- throw new \think\Exception($e->getMessage());
- }
- }
- }
- if(!function_exists('exportExcel')){
-
- function exportExcel($data,$header, $filename){
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Test Document")
- ->setSubject("Office 2007 XLSX Test Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("Test result file");
- $objPHPExcel->setActiveSheetIndex(0);
-
- $i=0;
- foreach ($header as $key=>$value){
-
- $colum = PHPExcel_Cell::stringFromColumnIndex($i);
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $value);
- $i++;
- }
-
- $j=2;
- $list = is_array($data)? $data : $data->toArray();
- foreach ($list as $key=>$value){
- $k=0;
- foreach ($value as $k1=>$v1){
-
- $objPHPExcel->getActiveSheet()->getCell(PHPExcel_Cell::stringFromColumnIndex($k).$j)->getStyle()->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
- $objPHPExcel->getActiveSheet()->setCellValueExplicit(PHPExcel_Cell::stringFromColumnIndex($k).$j, strval($v1));
-
- $k++;
- }
- $j++;
- }
-
- header('Content-Type: application/vnd.ms-excel');
- header("Content-Disposition: attachment;filename=$filename.xlsx");
- header('Cache-Control: max-age=0');
-
- header('Access-Control-Allow-Origin:*');
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- exit;
- }
- }
- if(!function_exists('validate_invoice_info')){
- function validate_invoice_info($data,&$return){
- $return=["code"=>0,"校验通过"];
- if (!isset($data['invoice_type'])||$data['invoice_type']==''){
- $return['code']=1004;
- $return['message']="发票类型不能为空";
- return false;
- }
- if (in_array($data['invoice_type'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
- if (!isset($data['invoice_total'])||$data['invoice_total']==''){
- $return['code']=1004;
- $return['message']='发票税前金额不能为空';
- return false;
- }
- }else{
- if (!isset($data['invoice_code'])||$data['invoice_code']==''){
- $return['code']=1004;
- $return['message']='发票代码不能为空';
- return false;
- }
- if (!isset($data['invoice_subtotal'])||$data['invoice_subtotal']==''){
- $return['code']=1004;
- $return['message']='发票税后金额不能为空';
- return false;
- }
- }
- if (!isset($data['invoice_number'])||$data['invoice_number']==''){
- $return['code']=1004;
- $return['message']='发票号码不能为空';
- return false;
- }
- if(in_array($data['invoice_type'],['normal','roll','toll','electronic'])){
- if(!isset($data['check_code'])||$data['check_code']==''){
- $return['code']=1004;
- $return['message']='校验码不能为空';
- return false;
- }
- }
- }
- }
|