123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /**
- * ShareAct.php UTF-8
- *
- *
- * @date : 2018/5/26 17:40
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\posts;
- use huo\controller\common\Base;
- use huo\controller\member\MemCache;
- use huo\controller\request\Channel;
- use huo\controller\request\Device;
- use huo\controller\request\Game;
- use huo\controller\request\Mem;
- use huo\controller\shop\ItgOrder;
- use huo\logic\posts\PostsLogic;
- use huo\logic\posts\ShareActLogic;
- use huo\model\posts\PostsModel;
- use huo\model\posts\ShareLogModel;
- use huolib\constant\MemItgConst;
- use huolib\constant\ShareConst;
- use huolib\status\CommonStatus;
- class ShareAct extends Base {
- /**
- * 分享成功后回调操作
- *
- * @param Game $game_rq
- * @param Channel $channel
- * @param Device $device
- * @param Mem $member
- *
- * @param array $_share_data
- *
- * @return array
- */
- public function callback(Game $game_rq, Channel $channel, Device $device, Mem $member, $_share_data = []) {
- //验证活动是否有效
- $_share_type = get_val($_share_data, 'share_type');
- $_to_target = get_val($_share_data, 'to_target');
- if (empty($_share_type) || empty($_to_target)) {
- return $this->huoError(CommonStatus::INVALID_PARAMS);
- }
- //验证分享途径
- $_target_types_key = array_keys(ShareConst::getTargetTypeMsg(null, true));
- if (!in_array($_to_target, $_target_types_key)) {
- return $this->huoError(CommonStatus::INVALID_PARAMS);
- }
- if (ShareConst::SHARE_TYPE_POSTS == $_share_type) {
- $_act_id = get_val($_share_data, 'share_id');
- if (empty($_act_id)) {
- return $this->huoError(CommonStatus::INVALID_PARAMS);
- }
- $post = (new PostsLogic())->getDetail($_act_id);
- if (empty($post)) {
- return $this->huoError(CommonStatus::INVALID_PARAMS);
- }
- //获取分享的配置信息
- $_share_data['title'] = $post['title'];
- $_share_data['content'] = $post['excerpt'];
- $_share_data['url'] = $post['url'];
- $_share_data['table_name'] = (new PostsModel())->getName();
- $_share_data['object_id'] = $_act_id;
- $_share_act_logic = new ShareActLogic();
- //判断玩家是否已经分享过指定平台 wx qq
- $_share_log = (new ShareLogModel())->getTodayShareLog($member->getMemId(), $_to_target);
- if (empty($_share_log)) {
- //增加玩家活动对应的抽奖次数
- $_itg_order = ItgOrder::ins();
- $_mc_class = MemCache::ins();
- $_me_data = $_mc_class->getInfoById($member->getMemId());
- //当日,一个手机号最多抽奖 MemItgConst::MAX_LOTTERY_DRAW_COUNT
- $count = $_itg_order->getDayMobileDrawCount($_me_data['mobile'], $_act_id);
- if ($count <= MemItgConst::MAX_LOTTERY_DRAW_COUNT) {
- $_reward_cnt = ShareConst::DEFAULT_SHARE_INCR_COUNT;
- $_rs = $_share_act_logic->incrLotteryCnt($member->getMemId(), $_act_id, $_reward_cnt);
- if (false == $_rs) {
- return $this->huoError(
- CommonStatus::INNER_ERROR, CommonStatus::getMsg(CommonStatus::INNER_ERROR)
- );
- }
- }
- //写入分享log
- $_rs = $_share_act_logic->insertShareLog($game_rq, $channel, $device, $member, $_share_data);
- if (false == $_rs) {
- return $this->huoError(CommonStatus::INNER_ERROR, CommonStatus::getMsg(CommonStatus::INNER_ERROR));
- }
- }
- }
- return $this->huoSuccess(CommonStatus::NO_ERROR, CommonStatus::getMsg(CommonStatus::NO_ERROR));
- }
- /**
- * 充值抽奖次数
- * @param $mem_id
- * @param $act_id
- *
- * @return array|mixed
- */
- public function resetLotteryCnt($mem_id, $act_id) {
- $_share_act_logic = new ShareActLogic();
- $_free_cnt = ShareConst::DEFAULT_LOTTERY_FREE_COUNT;
- //增加玩家活动对应的抽奖次数
- $_itg_order = ItgOrder::ins();
- $_mc_class = MemCache::ins();
- $_m_data = $_mc_class->getInfoById($mem_id);
- //当日,一个手机号最多抽奖 MemItgConst::MAX_LOTTERY_DRAW_COUNT
- $count = $_itg_order->getDayMobileDrawCount($_m_data['mobile'], $act_id);
- if ($count > MemItgConst::MAX_LOTTERY_DRAW_COUNT) {
- $_free_cnt = 0;
- }
- $_rs = $_share_act_logic->resetLotteryCnt($mem_id, $act_id, $_free_cnt);
- if (true !== $_rs) {
- return $this->huoError(CommonStatus::INVALID_PARAMS);
- }
- return $this->huoSuccess(CommonStatus::NO_ERROR);
- }
- }
|