common.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. /**
  14. * 根据IP获取地址
  15. */
  16. function get_address($ip)
  17. {
  18. $res = file_get_contents("http://ip.360.cn/IPQuery/ipquery?ip=" . $ip);
  19. $res = json_decode($res, 1);
  20. if ($res && $res['errno'] == 0) {
  21. return explode("\t", $res['data'])[0];
  22. } else {
  23. return '';
  24. }
  25. }
  26. /**
  27. * 导出数据为excel表格
  28. * @param $data 一个二维数组,结构如同从数据库查出来的数组
  29. * @param $title excel的第一行标题,一个数组,如果为空则没有标题
  30. * @param $filename 下载的文件名
  31. * @param exportexcel($arr,array('id','账户','密码','昵称'),'文件名!');
  32. */
  33. function export_excel($data = array(), $title = array(), $filename = 'report')
  34. {
  35. header("Content-type:application/octet-stream");
  36. header("Accept-Ranges:bytes");
  37. header("Content-type:application/vnd.ms-excel");
  38. header("Content-Disposition:attachment;filename=" . $filename . ".xls");
  39. header("Pragma: no-cache");
  40. header("Expires: 0");
  41. //导出xls 开始
  42. if (!empty($title)) {
  43. foreach ($title as $k => $v) {
  44. $title[$k] = iconv("UTF-8", "GB2312", $v);
  45. }
  46. $title = implode("\t", $title);
  47. echo "$title\n";
  48. }
  49. if (!empty($data)) {
  50. foreach ($data as $key => $val) {
  51. foreach ($val as $ck => $cv) {
  52. $data[$key][$ck] = iconv("UTF-8", "GB2312", $cv);
  53. }
  54. $data[$key] = implode("\t", $data[$key]);
  55. }
  56. echo implode("\n", $data);
  57. }
  58. }
  59. //读取文章分类列表
  60. function get_article_cate()
  61. {
  62. $cate = \think\facade\Db::name('ArticleCate')->order('create_time asc')->select()->toArray();
  63. return $cate;
  64. }
  65. //假期类型
  66. function get_leaves_types($id=0)
  67. {
  68. $types_array = ['未设置','事假','年假','调休假','病假','婚假','丧假','产假','陪产假','其他'];
  69. if($id==0){
  70. return $types_array;
  71. }
  72. else{
  73. $news_array=[];
  74. foreach($types_array as $key => $value){
  75. if($key>0){
  76. $news_array[]=array(
  77. 'id'=>$key,
  78. 'title'=>$value,
  79. );
  80. }
  81. }
  82. return $news_array;
  83. }
  84. }
  85. //根据假期类型读取名称
  86. function leaves_types_name($types=0)
  87. {
  88. $types_array = get_leaves_types();
  89. return $types_array[$types];
  90. }
  91. //销售合同性质
  92. function get_contract_types($check_status=0)
  93. {
  94. $contract_types_array = [
  95. ["id"=>1,"title"=>"普通合同"],
  96. ["id"=>2,"title"=>"产品合同"],
  97. ["id"=>3,"title"=>"服务合同"]
  98. ];
  99. return $contract_types_array;
  100. }
  101. //根据销售合同性质读取销售合同性质名称
  102. function contract_types_name($types=1)
  103. {
  104. $contract_types_array = get_contract_types();
  105. return $contract_types_array[$types-1];
  106. }
  107. //采购合同性质
  108. function get_purchase_types($check_status=0)
  109. {
  110. $purchase_types_array = [
  111. ["id"=>1,"title"=>"普通采购"],
  112. ["id"=>2,"title"=>"物品采购"],
  113. ["id"=>3,"title"=>"服务采购"]
  114. ];
  115. return $purchase_types_array;
  116. }
  117. //根据采购合同性质读取采购合同性质名称
  118. function purchase_types_name($types=1)
  119. {
  120. $purchase_types_array = get_purchase_types();
  121. return $purchase_types_array[$types-1];
  122. }