Member.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryData;
  4. use Cas\Dao\LotteryEvents;
  5. use KIF\Core\Request;
  6. use Cas\Module\Lottery;
  7. use Cas\Dao\UserInfo;
  8. use Cas\Dao\LotteryUserFeedback;
  9. use Cas\Dao\ArticleLikeCounter;
  10. use Cas\Dao\LotteryUserHelp;
  11. use Cas\Module\LotteryLog;
  12. use Cas\Dao\LotteryUserExpress;
  13. /**
  14. *
  15. * 用户资料设置
  16. */
  17. class Member extends EventsController {
  18. public function doDefault() {
  19. $this->tpl = 'member';
  20. }
  21. /**
  22. * 我的首页
  23. */
  24. public function doMy() {
  25. # 获取当前用户的信息
  26. $objUserData = new UserInfo();
  27. $uid = $this->getRunTimeUid();
  28. $userData = $objUserData -> get($uid);
  29. $this->setOutput('userData', $userData);
  30. $thisTime = time();
  31. # 获取登录地址
  32. $url = Request::g('url');
  33. $thisUrl = Request::schemeDomain().'/member/my';
  34. $loginUrl = $this -> getLoginUrl($thisUrl);
  35. $this->setOutput('loginUrl', $loginUrl);
  36. # 判断是否需要登录
  37. $ckLogin = $this->ckLogin();
  38. $this->setOutput('ckLogin', $ckLogin);
  39. # 获取我的助力值
  40. $condition = array (
  41. //'events_id' => $events_id,
  42. 'uid' => $uid,
  43. );
  44. $objLotteryUserHelp = new LotteryUserHelp();
  45. $info = $objLotteryUserHelp->fetchAll ( $condition, 10000, 'id desc' );
  46. $num = 0;
  47. if ($info) {
  48. foreach ($info as $k => $v) {
  49. $num += $v['num'];
  50. }
  51. }
  52. $this->tpl = 'my';
  53. $this->setOutput('thisTime', $thisTime);
  54. $this->setOutput('title', '我的');
  55. $this->setOutput('num', $num);
  56. $this->setOutput('action', 'gift');
  57. $this->setOutput('display', 1);
  58. $this->setOutput('notShowWeixinShare', true);
  59. }
  60. /**
  61. * 资料设置
  62. */
  63. public function doSet() {
  64. # 获取当前用户的信息
  65. $objUserData = new UserInfo();
  66. $uid = $this->getRunTimeUid();
  67. $userData = $objUserData -> get($uid);
  68. $this->setOutput('userData', $userData);
  69. $thisTime = time();
  70. # 获取登录地址
  71. $url = Request::g('url');
  72. $thisUrl = Request::schemeDomain().'/member/set';
  73. $loginUrl = $this -> getLoginUrl($thisUrl);
  74. $this->setOutput('loginUrl', $loginUrl);
  75. # 判断是否需要登录
  76. $ckLogin = $this->ckLogin();
  77. $this->setOutput('ckLogin', $ckLogin);
  78. # 获取用户最新收货地址
  79. $objDLotteryUserExpress = new LotteryUserExpress();
  80. $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
  81. # 获取我的资料
  82. $this->tpl = 'my_set';
  83. $this->setOutput('thisTime', $thisTime);
  84. $this->setOutput('title', '我的资料');
  85. $this->setOutput('my', $userExpress);
  86. $this->setOutput('action', 'gift');
  87. $this->setOutput('display', 1);
  88. $this->setOutput('notShowWeixinShare', true);
  89. }
  90. /**
  91. * 我参与的活动
  92. */
  93. public function doAct() {
  94. # 获取当前用户的信息
  95. $objUserData = new UserInfo();
  96. $uid = $this->getRunTimeUid();
  97. $userData = $objUserData -> get($uid);
  98. $this->setOutput('userData', $userData);
  99. $thisTime = time();
  100. # 获取登录地址
  101. $url = Request::g('url');
  102. $thisUrl = Request::schemeDomain().'/member/act';
  103. $loginUrl = $this -> getLoginUrl($thisUrl);
  104. $this->setOutput('loginUrl', $loginUrl);
  105. # 判断是否需要登录
  106. $ckLogin = $this->ckLogin();
  107. $this->setOutput('ckLogin', $ckLogin);
  108. $plat_form_id = $this->getPlatFormId();
  109. $objLottery = new Lottery();
  110. # 根据uid,得到参与的活动
  111. $objMLotteryLog = new LotteryLog ();
  112. $condition = array('uid' => $uid);
  113. $totals = $objMLotteryLog -> getUserParticipateLogNum($condition);
  114. $offset = 0;
  115. $size = 10;
  116. $data = $objMLotteryLog->findUserParticipateData($condition, "{$offset},{$size}", 'create_time desc');
  117. $events_ids = array();
  118. foreach($data as $key=> $d) {
  119. $events_ids[$d['events_id']] = $d['events_id'];
  120. }
  121. $objDLotteryEvents = new LotteryEvents();
  122. $eventsData = $objDLotteryEvents -> gets($events_ids);
  123. $objMLottery = new Lottery();
  124. # 剩余天数
  125. $TIME = time();
  126. $objArticleLikeCounter = new ArticleLikeCounter();
  127. foreach ($eventsData as $tmpKey => $tmpData) {
  128. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  129. $eventsData[$tmpKey]['rday'] = ceil($rday);
  130. # 参与人数
  131. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  132. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  133. if ($tmpData['type'] == 9) {
  134. # 阅读人数
  135. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  136. # 点赞人数
  137. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  138. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  139. } else {
  140. if (isset($tmpData['base_num']) && $tmpData['base_num']) {
  141. $eventsData[$tmpKey]['user_total'] += $tmpData['base_num'];
  142. }
  143. }
  144. $eventsData[$tmpKey]['url'] = $objMLottery->getEventsUrl($tmpData['type'],$tmpData['create_time']);
  145. }
  146. $this->setOutput('eventsData', $eventsData);
  147. $this->setOutput('title', '我参与的活动');
  148. $this->setOutput('totals', ceil($totals / $size));
  149. $this->tpl = 'my_act';
  150. $this->setOutput('action', 'gift');
  151. $this->setOutput('plat_form_id', $plat_form_id);
  152. $this->setOutput('display', 1);
  153. $this->setOutput('notShowWeixinShare', true);
  154. }
  155. /**
  156. * 事件:ajax翻页
  157. */
  158. public function doActAjax() {
  159. $page = Request::varGetInt('page', 1);
  160. $thisTime = time();
  161. $objLottery = new Lottery();
  162. $uid = $this->getRunTimeUid();
  163. $condition = array('uid' => $uid);
  164. $totals = $objLottery -> getLotteryDataListNum($condition);
  165. $size = 10;
  166. $offset = ($page - 1) * $size;
  167. $limit = "{$offset},{$size}";
  168. $data = $objLottery->getLotteryDataList($condition, "{$offset},{$size}", 'create_time desc');
  169. $newData = array();
  170. $events_ids = array();
  171. $events_ids = array();
  172. foreach($data as $key=> $d) {
  173. $events_ids[$d['run_time_data']['events']['id']] = $d['run_time_data']['events']['id'];
  174. }
  175. $objDLotteryEvents = new LotteryEvents();
  176. $eventsData = $objDLotteryEvents -> gets($events_ids);
  177. # 剩余天数
  178. $TIME = time();
  179. $objArticleLikeCounter = new ArticleLikeCounter();
  180. foreach ($eventsData as $tmpKey => $tmpData) {
  181. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  182. $eventsData[$tmpKey]['rday'] = ceil($rday);
  183. # 参与人数
  184. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  185. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  186. if ($tmpData['type'] == 9) {
  187. # 阅读人数
  188. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  189. # 点赞人数
  190. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  191. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  192. } else {
  193. if (isset($tmpData['base_num']) && $tmpData['base_num']) {
  194. $eventsData[$tmpKey]['user_total'] += $tmpData['base_num'];
  195. }
  196. }
  197. }
  198. $this->setOutput('eventsData', $eventsData);
  199. $this->tpl = 'ajax_my_act';
  200. $this->ajax_success_exit($this->render(true));
  201. }
  202. /**
  203. * 我的礼品
  204. */
  205. public function doGifts() {
  206. //填写收货地址 c=Express&lottery_data_id=3
  207. $objLottery = new Lottery();
  208. $thisTime = time();
  209. $plat_form_id = $this->getPlatFormId();
  210. # 获取用户信息
  211. $objUserData = new UserInfo();
  212. $uid = $this->getRunTimeUid();
  213. $userData = $objUserData -> get($uid);
  214. $this->setOutput('userData', $userData);
  215. # 获取登录地址
  216. $url = Request::g('url');
  217. $thisUrl = Request::schemeDomain().'/member/gifts';
  218. $loginUrl = $this -> getLoginUrl($thisUrl);
  219. $this->setOutput('loginUrl', $loginUrl);
  220. # 判断是否需要登录
  221. $ckLogin = $this->ckLogin();
  222. $this->setOutput('ckLogin', $ckLogin);
  223. $condition = array('audit' => 2, 'uid' => $uid,'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  224. $totals = $objLottery -> getLotteryDataListNum($condition);
  225. $offset = 0;
  226. $size = 6;
  227. $order = 'id desc';
  228. $data = $objLottery->getLotteryDataList($condition, "{$offset},{$size}", 'create_time desc');
  229. $newData = array();
  230. $events_ids = array();
  231. $objLotteryUserFeedback = new LotteryUserFeedback();
  232. foreach($data as $key=> $d){
  233. $data[$key]['feedback'] = 1;//不需要填写反馈
  234. $events_ids[$d['run_time_data']['events']['id']] = $d['run_time_data']['events']['id'];
  235. if (in_array($d['run_time_data']['events']['type'], array(4,0))) {
  236. $data[$key]['feedback'] = 2;//未填写反馈
  237. $where = array();
  238. $where['uid'] = $d['uid'];
  239. $where['events_id'] = $d['run_time_data']['events']['id'];
  240. $where['status'] = 1;
  241. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  242. if ($ids) {
  243. $data[$key]['feedback'] = 3;//已填写反馈
  244. }
  245. /*
  246. if (isset($d['express']) && $d['express']) {
  247. $data[$key]['feedback'] = 2;//未填写反馈
  248. $where = array();
  249. $where['uid'] = $d['uid'];
  250. $where['events_id'] = $d['run_time_data']['events']['id'];
  251. $where['status'] = 1;
  252. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  253. if ($ids) {
  254. $data[$key]['feedback'] = 3;//已填写反馈
  255. }
  256. } else {
  257. $data[$key]['feedback'] = 4;//未填写收货地址
  258. }
  259. */
  260. }
  261. }
  262. $objDLotteryEvents = new LotteryEvents();
  263. $eventsData = $objDLotteryEvents -> gets($events_ids);
  264. $time = time();
  265. foreach($data as $key=> $d){
  266. $eventsInfo = $eventsData[$d['run_time_data']['events']['id']];
  267. if ($v['feedback'] == 3) {
  268. # 查看是否过期
  269. if ($time > $eventsInfo['end_time']) {
  270. $data[$key]['feedback'] = 5;//未填写收货地址并且已经过期
  271. }
  272. }
  273. $newData[$key] = array();
  274. $newData[$key]['feedback'] = $d['feedback'];
  275. $thisEventID = $d['run_time_data']['events']['id'];
  276. $newData[$key]['prize_id'] = $d['prize_id'];
  277. $newData[$key]['prize_name'] = $d['run_time_data']['prize'][$d['prize_id']]['prize_name'];
  278. $newData[$key]['prize_type'] = $d['run_time_data']['prize'][$d['prize_id']]['type'];
  279. $newData[$key]['prize_express'] = $d['run_time_data']['prize'][$d['prize_id']]['express'];
  280. if ($d['run_time_data']['events']['type'] == LotteryEvents::TYPE_EVENTS_CODE) {
  281. //$newData[$key]['prize_img_url'] = $d['run_time_data']['events']['weixinShare']['imgUrl'];
  282. $newData[$key]['prize_img_url'] = $d['run_time_data']['prize'][$d['prize_id']]['img_url'];
  283. } else {
  284. $newData[$key]['prize_img_url'] = $d['run_time_data']['prize'][$d['prize_id']]['img_url'];
  285. }
  286. $newData[$key]['events_id'] = $thisEventID;
  287. $newData[$key]['events_delivery'] = $eventsData[$thisEventID]['delivery'];
  288. $newData[$key]['events_name'] = $eventsData[$thisEventID]['events_name'];
  289. $newData[$key]['events_type'] = $eventsData[$thisEventID]['type'];
  290. $newData[$key]['end_time_receive_prizes'] = $eventsData[$thisEventID]['end_time_receive_prizes'];
  291. $newData[$key]['virtual_data'] = $d['virtual_data'];
  292. $newData[$key]['express'] = $d['express'];
  293. $newData[$key]['lottery_data_id'] = $key;
  294. $newData[$key]['show_up_express_a'] = false;
  295. if($newData[$key]['end_time_receive_prizes'] < time() && empty($newData[$key]['express'])){
  296. $newData[$key]['show_up_express_a'] = true;
  297. }
  298. $newData[$key]['url'] = $objLottery -> getEventsUrl($eventsInfo['type'],$eventsInfo['create_time'],$this->platform['url']);
  299. }
  300. $this->tpl = 'gifts';
  301. $this->setOutput('thisTime', $thisTime);
  302. $this->setOutput('title', '我的奖品');
  303. $this->setOutput('data', $data);
  304. $this->setOutput('newData', $newData);
  305. $this->setOutput('totals', ceil($totals / $size));
  306. $this->setOutput('action', 'gift');
  307. $this->setOutput('display', 1);
  308. $this->setOutput('notShowWeixinShare', true);
  309. }
  310. /**
  311. * 事件:ajax翻页
  312. */
  313. public function doAjax() {
  314. $page = Request::varGetInt('page', 1);
  315. $thisTime = time();
  316. $objLottery = new Lottery();
  317. $uid = $this->getRunTimeUid();
  318. $condition = array('audit' => 2, 'uid' => $uid,'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  319. $totals = $objLottery -> getLotteryDataListNum($condition);
  320. $order = 'create_time desc';
  321. $size = 6;
  322. $offset = ($page - 1) * $size;
  323. $limit = "{$offset},{$size}";
  324. $data = $objLottery->getLotteryDataList($condition, "{$offset},{$size}", 'create_time desc');
  325. $newData = array();
  326. $events_ids = array();
  327. $objLotteryUserFeedback = new LotteryUserFeedback();
  328. foreach($data as $key=> $d){
  329. $data[$key]['feedback'] = 1;//不需要填写反馈
  330. $events_ids[$d['run_time_data']['events']['id']] = $d['run_time_data']['events']['id'];
  331. if (in_array($d['run_time_data']['events']['type'], array(4,0))) {
  332. $data[$key]['feedback'] = 2;//未填写反馈
  333. $where = array();
  334. $where['uid'] = $d['uid'];
  335. $where['events_id'] = $d['run_time_data']['events']['id'];
  336. $where['status'] = 1;
  337. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  338. $info = $objLotteryUserFeedback->gets ( $ids );
  339. if ($info) {
  340. $data[$key]['feedback'] = 3;//已填写反馈
  341. }
  342. /*
  343. if (isset($d['express']) && $d['express']) {
  344. $data[$key]['feedback'] = 2;//未填写反馈
  345. $where = array();
  346. $where['uid'] = $d['uid'];
  347. $where['events_id'] = $d['run_time_data']['events']['id'];
  348. $where['status'] = 1;
  349. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  350. $info = $objLotteryUserFeedback->gets ( $ids );
  351. if ($info) {
  352. $data[$key]['feedback'] = 3;//已填写反馈
  353. }
  354. } else {
  355. $data[$key]['feedback'] = 4;//未填写收货地址
  356. }
  357. */
  358. }
  359. }
  360. $objDLotteryEvents = new LotteryEvents();
  361. $eventsData = $objDLotteryEvents -> gets($events_ids);
  362. foreach($data as $key=> $d){
  363. $newData[$key] = array();
  364. $thisEventID = $d['run_time_data']['events']['id'];
  365. $newData[$key]['prize_id'] = $d['prize_id'];
  366. $newData[$key]['prize_name'] = $d['run_time_data']['prize'][$d['prize_id']]['prize_name'];
  367. $newData[$key]['prize_type'] = $d['run_time_data']['prize'][$d['prize_id']]['type'];
  368. $newData[$key]['prize_express'] = $d['run_time_data']['prize'][$d['prize_id']]['express'];
  369. if ($d['run_time_data']['events']['type'] == LotteryEvents::TYPE_EVENTS_CODE) {
  370. $newData[$key]['prize_img_url'] = $d['run_time_data']['events']['weixinShare']['imgUrl'];
  371. } else {
  372. $newData[$key]['prize_img_url'] = $d['run_time_data']['prize'][$d['prize_id']]['img_url'];
  373. }
  374. $newData[$key]['events_id'] = $thisEventID;
  375. $newData[$key]['events_delivery'] = $eventsData[$thisEventID]['delivery'];
  376. $newData[$key]['events_name'] = $eventsData[$thisEventID]['events_name'];
  377. $newData[$key]['events_type'] = $eventsData[$thisEventID]['type'];
  378. $newData[$key]['end_time_receive_prizes'] = $eventsData[$thisEventID]['end_time_receive_prizes'];
  379. $newData[$key]['virtual_data'] = $d['virtual_data'];
  380. $newData[$key]['express'] = $d['express'];
  381. $newData[$key]['lottery_data_id'] = $key;
  382. $newData[$key]['show_up_express_a'] = false;
  383. if($newData[$key]['end_time_receive_prizes'] < time() && empty($newData[$key]['express'])){
  384. $newData[$key]['show_up_express_a'] = true;
  385. }
  386. }
  387. $this->setOutput('data', $data);
  388. $this->setOutput('newData', $newData);
  389. $this->tpl = 'ajax_gifts';
  390. $this->ajax_success_exit($this->render(true));
  391. }
  392. public function display() {
  393. return $this->render();
  394. }
  395. }