common.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. use think\Db;
  3. /**
  4. * 秒转换为天
  5. */
  6. function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
  7. {
  8. $day = floor($remain_time / (3600*24));
  9. $day = $day > 0 ? $day.'天' : '';
  10. $hour = floor(($remain_time % (3600*24)) / 3600);
  11. $hour = $hour > 0 ? $hour.'小时' : '';
  12. if($is_hour && $is_minutes) {
  13. $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
  14. $minutes = $minutes > 0 ? $minutes.'分钟' : '';
  15. return $day.$hour.$minutes;
  16. }
  17. if($hour) {
  18. return $day.$hour;
  19. }
  20. return $day;
  21. }
  22. //获取全图片地址 $image_data
  23. function image_path($image_data){
  24. if(empty($image_data)){
  25. return $image_data;
  26. }
  27. if (strpos($image_data,'|')!==false){
  28. $image_res = explode('|',$image_data);
  29. }elseif(strpos($image_data,',')!==false){
  30. $image_res = explode(',',$image_data);
  31. }else{
  32. $image_res = array($image_data);
  33. }
  34. return $image_res;
  35. }
  36. function get_order_sn(){
  37. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  38. $order_id_len = strlen($order_id_main);
  39. $order_id_sum = 0;
  40. for($i=0; $i<$order_id_len; $i++){
  41. $order_id_sum += (int)(substr($order_id_main,$i,1));
  42. }
  43. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  44. return $osn;
  45. }
  46. /**
  47. * 更新会员积分
  48. * @param $user_id
  49. * @param $integral
  50. * @param $desc
  51. * @param int $rel_id
  52. * @throws \think\Exception
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. * @throws \think\exception\PDOException
  57. */
  58. function update_user_integral($user_id,$integral,$type,$desc,$rel_id = 0)
  59. {
  60. $user = Db::table('store_member')->find($user_id);
  61. $integral_info=[
  62. 'user_id'=> $user_id,
  63. 'create_at'=> date("Y-m-d H:i:s"),
  64. 'integral'=> $integral,
  65. 'before'=> $user['integral'],
  66. 'after'=> $user['integral'] + $integral,
  67. 'type'=>$type,
  68. 'desc'=> $desc,
  69. 'rel_id'=> $rel_id,
  70. ];
  71. Db::table('integral_info')->insert($integral_info);
  72. Db::table('store_member')->where(['id'=>$user_id])->update(['integral'=>$integral_info['after']]);
  73. }