Form.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Form
  5. {
  6. # 获取当前可用的formid
  7. public function get($uid, $type = 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. $info = Dever::db('act/form_id')->getAll($where);
  21. if ($info) {
  22. $key = array_rand($info);
  23. if (isset($info[$key])) {
  24. $update['where_id'] = $info[$key]['id'];
  25. $update['num'] = $info[$key]['num'] + 1;
  26. Dever::db('act/form_id')->update($update);
  27. return $info[$key]['form_id'];
  28. }
  29. } else {
  30. return false;
  31. }
  32. }
  33. # 提交formid
  34. public function submit($uid, $id, $type = 1, $system = 1)
  35. {
  36. $where['uid'] = $uid;
  37. $where['type'] = $type;
  38. $where['cate_id'] = $system;
  39. $where['form_id'] = $id;
  40. $info = Dever::db('act/form_id')->one($where);
  41. if (!$info) {
  42. $where['num'] = 0;
  43. Dever::db('act/form_id')->insert($where);
  44. }
  45. return true;
  46. }
  47. }