UserHelp.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 doApply() {
  10. # 1.必要参数验证
  11. $uid = $this->getRunTimeUid();
  12. if (!Verify::unsignedInt($uid)) {
  13. self::ajax_fail_exit('无效用户id');
  14. }
  15. $help_id = Request::g('help_id');
  16. if (!Verify::unsignedInt($help_id)) {
  17. self::ajax_fail_exit('无效试用id');
  18. }
  19. $source_user = Request::g('source_user');
  20. if (!Verify::unsignedInt($source_user)) {
  21. self::ajax_fail_exit('无效用户id');
  22. }
  23. if ($uid == $source_user) {
  24. self::ajax_fail_exit('不能给自己助力');
  25. }
  26. $help_session = Request::g('help_session');
  27. $state = $this->shareSession($help_id, $source_user, $help_session);
  28. if (!$state) {
  29. self::ajax_fail_exit('无效试用id');
  30. }
  31. $events_id = Request::g('events_id');
  32. if (!Verify::unsignedInt($events_id)) {
  33. self::ajax_fail_exit('无效试用id');
  34. }
  35. $this->LotteryUserHelpLog = new LotteryUserHelpLog ();
  36. $this->LotteryUserHelp = new LotteryUserHelp ();
  37. $totals = $this->LotteryUserHelpLog->totals(array('help_id' => $help_id));
  38. $this->LotteryUserHelp->modify(array('num' => $totals), array('id' => $help_id));
  39. $condition = array
  40. (
  41. 'help_id' => $help_id,
  42. 'events_id' => $events_id,
  43. 'uid' => $uid,
  44. );
  45. $info = $this->LotteryUserHelpLog->fetchOne ( $condition);
  46. if ($info) {
  47. self::ajax_fail_exit('您只能助力一次');
  48. # modify
  49. $this->LotteryUserHelpLog->modify($condition, array('id' => $info['id']));
  50. } else {
  51. # add
  52. $id = $this->LotteryUserHelpLog->add($condition);
  53. }
  54. self::ajax_success_exit();
  55. }
  56. public function display() {
  57. return $this->render ();
  58. }
  59. }