ShareAct.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * ShareAct.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/26 17:40
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\posts;
  13. use huo\controller\common\Base;
  14. use huo\controller\member\MemCache;
  15. use huo\controller\request\Channel;
  16. use huo\controller\request\Device;
  17. use huo\controller\request\Game;
  18. use huo\controller\request\Mem;
  19. use huo\controller\shop\ItgOrder;
  20. use huo\logic\posts\PostsLogic;
  21. use huo\logic\posts\ShareActLogic;
  22. use huo\model\posts\PostsModel;
  23. use huo\model\posts\ShareLogModel;
  24. use huolib\constant\MemItgConst;
  25. use huolib\constant\ShareConst;
  26. use huolib\status\CommonStatus;
  27. class ShareAct extends Base {
  28. /**
  29. * 分享成功后回调操作
  30. *
  31. * @param Game $game_rq
  32. * @param Channel $channel
  33. * @param Device $device
  34. * @param Mem $member
  35. *
  36. * @param array $_share_data
  37. *
  38. * @return array
  39. */
  40. public function callback(Game $game_rq, Channel $channel, Device $device, Mem $member, $_share_data = []) {
  41. //验证活动是否有效
  42. $_share_type = get_val($_share_data, 'share_type');
  43. $_to_target = get_val($_share_data, 'to_target');
  44. if (empty($_share_type) || empty($_to_target)) {
  45. return $this->huoError(CommonStatus::INVALID_PARAMS);
  46. }
  47. //验证分享途径
  48. $_target_types_key = array_keys(ShareConst::getTargetTypeMsg(null, true));
  49. if (!in_array($_to_target, $_target_types_key)) {
  50. return $this->huoError(CommonStatus::INVALID_PARAMS);
  51. }
  52. if (ShareConst::SHARE_TYPE_POSTS == $_share_type) {
  53. $_act_id = get_val($_share_data, 'share_id');
  54. if (empty($_act_id)) {
  55. return $this->huoError(CommonStatus::INVALID_PARAMS);
  56. }
  57. $post = (new PostsLogic())->getDetail($_act_id);
  58. if (empty($post)) {
  59. return $this->huoError(CommonStatus::INVALID_PARAMS);
  60. }
  61. //获取分享的配置信息
  62. $_share_data['title'] = $post['title'];
  63. $_share_data['content'] = $post['excerpt'];
  64. $_share_data['url'] = $post['url'];
  65. $_share_data['table_name'] = (new PostsModel())->getName();
  66. $_share_data['object_id'] = $_act_id;
  67. $_share_act_logic = new ShareActLogic();
  68. //判断玩家是否已经分享过指定平台 wx qq
  69. $_share_log = (new ShareLogModel())->getTodayShareLog($member->getMemId(), $_to_target);
  70. if (empty($_share_log)) {
  71. //增加玩家活动对应的抽奖次数
  72. $_itg_order = ItgOrder::ins();
  73. $_mc_class = MemCache::ins();
  74. $_me_data = $_mc_class->getInfoById($member->getMemId());
  75. //当日,一个手机号最多抽奖 MemItgConst::MAX_LOTTERY_DRAW_COUNT
  76. $count = $_itg_order->getDayMobileDrawCount($_me_data['mobile'], $_act_id);
  77. if ($count <= MemItgConst::MAX_LOTTERY_DRAW_COUNT) {
  78. $_reward_cnt = ShareConst::DEFAULT_SHARE_INCR_COUNT;
  79. $_rs = $_share_act_logic->incrLotteryCnt($member->getMemId(), $_act_id, $_reward_cnt);
  80. if (false == $_rs) {
  81. return $this->huoError(
  82. CommonStatus::INNER_ERROR, CommonStatus::getMsg(CommonStatus::INNER_ERROR)
  83. );
  84. }
  85. }
  86. //写入分享log
  87. $_rs = $_share_act_logic->insertShareLog($game_rq, $channel, $device, $member, $_share_data);
  88. if (false == $_rs) {
  89. return $this->huoError(CommonStatus::INNER_ERROR, CommonStatus::getMsg(CommonStatus::INNER_ERROR));
  90. }
  91. }
  92. }
  93. return $this->huoSuccess(CommonStatus::NO_ERROR, CommonStatus::getMsg(CommonStatus::NO_ERROR));
  94. }
  95. /**
  96. * 充值抽奖次数
  97. * @param $mem_id
  98. * @param $act_id
  99. *
  100. * @return array|mixed
  101. */
  102. public function resetLotteryCnt($mem_id, $act_id) {
  103. $_share_act_logic = new ShareActLogic();
  104. $_free_cnt = ShareConst::DEFAULT_LOTTERY_FREE_COUNT;
  105. //增加玩家活动对应的抽奖次数
  106. $_itg_order = ItgOrder::ins();
  107. $_mc_class = MemCache::ins();
  108. $_m_data = $_mc_class->getInfoById($mem_id);
  109. //当日,一个手机号最多抽奖 MemItgConst::MAX_LOTTERY_DRAW_COUNT
  110. $count = $_itg_order->getDayMobileDrawCount($_m_data['mobile'], $act_id);
  111. if ($count > MemItgConst::MAX_LOTTERY_DRAW_COUNT) {
  112. $_free_cnt = 0;
  113. }
  114. $_rs = $_share_act_logic->resetLotteryCnt($mem_id, $act_id, $_free_cnt);
  115. if (true !== $_rs) {
  116. return $this->huoError(CommonStatus::INVALID_PARAMS);
  117. }
  118. return $this->huoSuccess(CommonStatus::NO_ERROR);
  119. }
  120. }