common.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // 接口公共方法
  3. use think\Db;
  4. function get_order_sn(){
  5. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  6. $order_id_len = strlen($order_id_main);
  7. $order_id_sum = 0;
  8. for($i=0; $i<$order_id_len; $i++){
  9. $order_id_sum += (int)(substr($order_id_main,$i,1));
  10. }
  11. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  12. return $osn;
  13. }
  14. function encrypt_password($password){
  15. return password_hash($password,PASSWORD_DEFAULT);
  16. }
  17. function check_password($password,$hash)
  18. {
  19. return password_verify($password,$hash);
  20. }
  21. // 获取日历 默认最近7天
  22. function get_calendar($day = 7,$type='asc'){
  23. $data = [];
  24. $week_arr = ['日','一','二','三','四','五','六'];
  25. for($i=0;$i<$day;$i++) {
  26. $day_time = date('Y-m-d',strtotime("-$i days"));
  27. $day_title= trim(date('m月d日',strtotime("-$i days")),'0');
  28. $time_int = strtotime($day_time);
  29. $week_day =$week_arr[date('w',strtotime($day_time))];
  30. $data[] = ['day_time' => $day_time,'week_day'=>$week_day,'time_int'=>$time_int,'day_title'=>$day_title];
  31. }
  32. if($type == 'asc') array_multisort(array_column($data,'time_int'),SORT_ASC,$data);
  33. return $data;
  34. }