一款PHP自动竞拍出价程序

用户提交自己的信息后,保存在数据库中,程序每一次读取当前结果时都要判断一次,如用户可设置几秒钟时参加竞拍,竞拍多少次,并且可以设置前面有多少人竞拍后我才参加,都是一些人性化的功能,实例代码如下:

  1. function auto($second,$gid,$shutuid)
  2. {
  3. global $table_prefix;
  4. //取出此商品已经竞拍次数
  5. $maxnumber=0;
  6. $unumber=array();
  7. $query=mysql_query("select id,uid from `".$table_prefix."buylog` where gid=".$gid);
  8. while($rows=mysql_fetch_assoc($query))
  9. {
  10. $maxnumber++;
  11. if(isset($unumber[$rows['uid']]))
  12. {
  13. $unumber[$rows['uid']]++;
  14. }
  15. else
  16. {
  17. $unumber[$rows['uid']]=0;
  18. }
  19. }
  20. //取出自动竞拍的会员
  21. $sql="select uid,username,number,second,maxnumber,gid,ip from `".$table_prefix."autobuy` where gid=".$gid;
  22. $query=mysql_query($sql);
  23. $allow=array();
  24. $shutu,',$shutuid);
  25. while($rows=mysql_fetch_assoc($query))
  26. {//开源代码phpfensi.com
  27. $seconds=explode(',',$rows['second']);
  28. $unumber[$rows['uid']]=isset($unumber[$rows['uid']])?$unumber[$rows['uid']]:0;
  29. if(in_array($second,$seconds) && !in_array($rows['uid'],$shutuid) && $rows['maxnumber']<=$maxnumber && $rows['number']>$unumber[$rows['uid']]) //包含时刻,并且不在黑名单,符合此会员竞拍次数设置
  30. {
  31. $allow[]=$rows['uid'];
  32. }
  33. }
  34. $allowuser=array();
  35. if($allow)
  36. {
  37. $query=mysql_query('select uid,username,money,ip from `'.$table_prefix.'user` where uid in ('.implode(',',$allow).')');
  38. while($rows=mysql_fetch_assoc($query))
  39. {
  40. $allowuser[]=$rows;
  41. }
  42. }
  43. unset($allow,$sql,$number,$maxnumber,$shutuid,$query,$u);
  44. return $allowuser;
  45. }