UserHelp.class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Module\Lottery;
  4. use Cas\Dao\LotteryUserHelp;
  5. use Cas\Dao\LotteryUserHelpLog;
  6. use KIF\Verify;
  7. use KIF\Core\Request;
  8. class UserHelp extends EventsController {
  9. public function doTest() {
  10. $this->LotteryUserHelp = new LotteryUserHelp ();
  11. $condition = array();
  12. $helpData = $this->LotteryUserHelp->fetchAll ($condition, 1000000, 'id desc');
  13. foreach ($helpData as $k => $v) {
  14. $this->LotteryUserHelp->modify(array('num' => $v['nums']), array('id' => $v['id']));
  15. }
  16. echo 'yes';die;
  17. }
  18. public function doApply() {
  19. # 1.必要参数验证
  20. $uid = $this->getRunTimeUid();
  21. if (!Verify::unsignedInt($uid)) {
  22. self::ajax_fail_exit('无效用户id');
  23. }
  24. $help_id = Request::g('help_id');
  25. if (!Verify::unsignedInt($help_id)) {
  26. self::ajax_fail_exit('无效试用id');
  27. }
  28. $source_user = Request::g('source_user');
  29. if (!Verify::unsignedInt($source_user)) {
  30. self::ajax_fail_exit('无效用户id');
  31. }
  32. if ($uid == $source_user) {
  33. self::ajax_fail_exit('不能给自己助力');
  34. }
  35. $help_session = Request::g('help_session');
  36. $state = $this->shareSession($help_id, $source_user, $help_session);
  37. if (!$state) {
  38. self::ajax_fail_exit('无效试用id');
  39. }
  40. $events_id = Request::g('events_id');
  41. if (!Verify::unsignedInt($events_id)) {
  42. self::ajax_fail_exit('无效试用id');
  43. }
  44. $this->LotteryUserHelpLog = new LotteryUserHelpLog ();
  45. $this->LotteryUserHelp = new LotteryUserHelp ();
  46. $condition = array
  47. (
  48. 'help_id' => $help_id,
  49. 'events_id' => $events_id,
  50. 'uid' => $uid,
  51. );
  52. $info = $this->LotteryUserHelpLog->fetchOne ( $condition);
  53. if ($info) {
  54. self::ajax_fail_exit('您只能助力一次');
  55. # modify
  56. $this->LotteryUserHelpLog->modify($condition, array('id' => $info['id']));
  57. } else {
  58. # add
  59. $id = $this->LotteryUserHelpLog->add($condition);
  60. }
  61. $totals = $this->LotteryUserHelpLog->totals(array('help_id' => $help_id));
  62. $this->LotteryUserHelp->modify(array('num' => $totals), array('id' => $help_id));
  63. self::ajax_success_exit();
  64. }
  65. public function display() {
  66. return $this->render ();
  67. }
  68. }