common.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // 应用公共文件
  3. use think\facade\Db;
  4. if (!function_exists('getNewOrderId')) {
  5. /**
  6. * 生成订单唯一id
  7. * @param $uid 用户uid
  8. * @return string
  9. */
  10. function getNewOrderId()
  11. {
  12. list($msec, $sec) = explode(' ', microtime());
  13. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  14. $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
  15. if (\app\models\auction\AuctionOrder::where('order_id', $orderId)) $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
  16. return $orderId;
  17. }
  18. }
  19. function getDataFind($table,$where=[]){
  20. $data = Db::name($table)->where($where)->find();
  21. return $data;
  22. }
  23. //查找所有上级
  24. function getParent($uid){
  25. //当前用户
  26. static $arr=[];
  27. //当前用户
  28. $member = getDataFind('user',array('uid'=>$uid));
  29. if ($member['spread_uid'] > 0){
  30. $parent = getDataFind('user',array('uid'=>$member['spread_uid']));
  31. $arr[]= $parent['uid'];
  32. getParent($parent['uid']);
  33. }
  34. return $arr;
  35. }