UserHelp.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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->objLotteryUserHelp->fetchAll ($condition, 1000000, 'id desc');
  13. foreach ($helpData as $k => $v) {
  14. $this->LotteryUserHelp->modify(array('nums' => $v['num']), 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. $totals = $this->LotteryUserHelpLog->totals(array('help_id' => $help_id));
  47. $this->LotteryUserHelp->modify(array('num' => $totals), array('id' => $help_id));
  48. $condition = array
  49. (
  50. 'help_id' => $help_id,
  51. 'events_id' => $events_id,
  52. 'uid' => $uid,
  53. );
  54. $info = $this->LotteryUserHelpLog->fetchOne ( $condition);
  55. if ($info) {
  56. self::ajax_fail_exit('您只能助力一次');
  57. # modify
  58. $this->LotteryUserHelpLog->modify($condition, array('id' => $info['id']));
  59. } else {
  60. # add
  61. $id = $this->LotteryUserHelpLog->add($condition);
  62. }
  63. self::ajax_success_exit();
  64. }
  65. public function display() {
  66. return $this->render ();
  67. }
  68. }