Form.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Form
  5. {
  6. # 获取当前可用的formid
  7. public function get($uid, $type = 1, $system = 1)
  8. {
  9. $where['uid'] = $uid;
  10. if ($type > 0) {
  11. $where['type'] = $type;
  12. if ($type == 2) {
  13. # 支付表单有3次机会
  14. $where['num'] = 3;
  15. } else {
  16. # 普通表单只有一次机会
  17. $where['num'] = 1;
  18. }
  19. }
  20. $where['cate_id'] = $system;
  21. $info = Dever::db('act/form_id')->getAll($where);
  22. if ($info) {
  23. $key = array_rand($info);
  24. if (isset($info[$key])) {
  25. $update['where_id'] = $info[$key]['id'];
  26. $update['num'] = $info[$key]['num'] + 1;
  27. Dever::db('act/form_id')->update($update);
  28. return $info[$key]['form_id'];
  29. }
  30. } else {
  31. return false;
  32. }
  33. }
  34. # 提交formid
  35. public function submit($uid, $id, $type = 1, $system = 1)
  36. {
  37. $where['uid'] = $uid;
  38. $where['type'] = $type;
  39. $where['cate_id'] = $system;
  40. $where['form_id'] = $id;
  41. $info = Dever::db('act/form_id')->one($where);
  42. if (!$info) {
  43. $where['num'] = 0;
  44. Dever::db('act/form_id')->insert($where);
  45. }
  46. return true;
  47. }
  48. }