123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- // /> フ
- // | _ _|
- // /` ミ_꒳ノ
- // / |
- // / ヽ ノ
- // │ | | |
- // / ̄| | | |
- // | ( ̄ヽ__ヽ_)__)
- // \二つ
- // 应用公共文件
- //失败返回值
- use think\facade\Filesystem;
- if(!function_exists("error")){
- /**
- * @param $message
- * @param int $code
- * @param null $data
- * @return \think\response\Json
- */
- function error($message,$code=1004,$data=null){
- return json(["code"=>$code,"message"=>$message,"data"=>$data]);
- }
- }
- //成功返回值
- if(!function_exists('success')){
- /**
- * @param $message
- * @param int $code
- * @param null $data
- * @return \think\response\Json
- */
- function success($message,$data=null,$code=0){
- return json(['code'=>$code,'message'=>$message,'data'=>$data]);
- }
- }
- if (!function_exists('action_in_arr')) {
- /**
- * 检测一个访问的方式是否在白名单内 白名单不验token
- * @param array $arr
- * @return bool
- */
- 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('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;
- }
- }
- }
- }
|