Common.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/14
  6. * Time: 10:42
  7. */
  8. namespace addons\ddrive\library;
  9. class Common{
  10. /**
  11. * 得到类似几分钟前等
  12. */
  13. function getTimeInfoUser($time){
  14. $mtime=time()-$time;
  15. if($mtime<=60){
  16. $time=$mtime.'秒前';
  17. }else if($mtime>60 && $mtime<3600){
  18. $time=round($mtime/60).'分前';
  19. }else if($mtime>=3600 && $mtime<3600*24){
  20. $time=round($mtime/3600).'小时前';
  21. }else if($mtime>=(3600*24) && $mtime<(3600*24*2)){
  22. $time='昨日'.date('H:i',$time);
  23. }else if($mtime>=(3600*24*2) && $mtime<(3600*24*3)){
  24. $time='两天前';
  25. }else if($mtime>=(3600*24*3) && $mtime<(3600*24*4)){
  26. $time='三天前';
  27. }else if($mtime>=(3600*24*7) && $mtime<(3600*24*14)){
  28. $time='一周前';
  29. }else if($mtime>=(3600*24*14) && $mtime<(3600*24*21)){
  30. $time='两周前';
  31. }else if($mtime>=(3600*24*30) && $mtime<(3600*24*60)){
  32. $time='一个月前';
  33. }else if($mtime>=(3600*24*60) && $mtime<(3600*24*90)){
  34. $time='两个月前';
  35. }else{
  36. $time=date('Y-m-d',$time);
  37. }
  38. return $time;
  39. }
  40. /**
  41. * 获取微信openid
  42. *
  43. * @return void
  44. */
  45. function getOpenid($code = '')
  46. {
  47. if ($code) {
  48. $wx_info['code'] = $code;
  49. }
  50. $config = get_addon_config('ddrive');
  51. $appid = $config['wx_appid'];
  52. $secret = $config['wx_secret'];
  53. $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$wx_info['code']}&grant_type=authorization_code";
  54. $res = \fast\Http::get($api);
  55. $res = json_decode($res, true);
  56. if ($res['session_key']) {
  57. if (isset($res['errmsg'])) {
  58. return $res['errmsg'];
  59. } else {
  60. return $data = [ 'openid' => $res['openid']];
  61. }
  62. }
  63. }
  64. //计算奖励金钱乘
  65. function except($money1, $money, $scale = '0')
  66. {
  67. $newMoney = bcdiv($money1, $money, $scale);
  68. return $newMoney;
  69. }
  70. //计算金钱加
  71. function math_add($money, $money1, $scale = '2')
  72. {
  73. return bcadd($money, $money1, $scale);
  74. }
  75. //计算金钱减
  76. function math_jian($money, $money1, $scale = '2')
  77. {
  78. return bcsub($money, $money1, $scale);
  79. }
  80. /**对象转数组
  81. * object_array
  82. * @des
  83. * @param $array
  84. * @return array
  85. */
  86. function object_array($array)
  87. {
  88. if (isset($array)) {
  89. return $array->toArray();
  90. }
  91. return [];
  92. }
  93. }