| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 | <?php/** * ShareActLogic.php UTF-8 * 分享活动逻辑类 * * @date    : 2018/5/26 16:06 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : luowei <lw@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\logic\posts;use huo\controller\request\Channel;use huo\controller\request\Device;use huo\controller\request\Game;use huo\controller\request\Mem;use huo\model\common\CommonModel;use huo\model\member\MemActivityModel;use huo\model\posts\ShareLogModel;use huolib\constant\ShareConst;use huolib\status\CommonStatus;class ShareActLogic extends CommonModel {    public function __construct() {        parent::__construct();    }    /**     * 重置分享活动的抽奖次数     *     * @param     $mem_id     * @param     $act_id     *     * @param int $free_cnt     *     * @return bool|int     */    public function resetLotteryCnt($mem_id, $act_id, $free_cnt = 0) {        $_mem_act_model = $this->getMemActModel($mem_id, $act_id);        $_today_start_time = strtotime(date('Y-m-d'));        /** @var MemActivityModel $_mem_act_model */        if (isset($_mem_act_model->update_time) && $_mem_act_model->update_time < $_today_start_time) {            $_update_data = [                'today_cnt'   => 0,                'free_cnt'    => $free_cnt,                'update_time' => time(),            ];            if (false === $_mem_act_model->updateMemAct($_update_data, $_mem_act_model->id)) {                return CommonStatus::INNER_ERROR;            }        }        return true;    }    /**     * 增加玩家在活动中的每日抽奖次数和总抽奖次数     *     * @param     $mem_id     * @param     $act_id     * @param int $count     *     * @return bool     */    public function incrLotteryCnt($mem_id, $act_id, $count = ShareConst::DEFAULT_SHARE_INCR_COUNT) {        /** @var MemActivityModel $_mem_act_model */        $_mem_act_model = $this->getMemActModel($mem_id, $act_id);        $_old_todal_cnt = isset($_mem_act_model->total_cnt) ? $_mem_act_model->total_cnt : 0;        $_old_today_cnt = isset($_mem_act_model->today_cnt) ? $_mem_act_model->today_cnt : 0;        $_data['total_cnt'] = $_old_todal_cnt + $count;        $_data['today_cnt'] = $_old_today_cnt + $count;        return $_mem_act_model->updateMemAct($_data, $_mem_act_model->id);    }    /**     * 获取MemActivityModel,不存在则创建     *     * @param $mem_id     * @param $act_id     *     * @return bool|mixed     */    public function getMemActModel($mem_id, $act_id) {        $_mem_act_model = new MemActivityModel();        $_mem_act = $_mem_act_model->getMemActModel($mem_id, $act_id);        if (empty($_mem_act)) {            $_add_data = [                'mem_id'   => $mem_id,                'act_id'   => $act_id,                'free_cnt' => ShareConst::DEFAULT_LOTTERY_FREE_COUNT,            ];            $_mem_act_id = $_mem_act_model->addMemAct($_add_data);            return $_mem_act_model->getInfoById($_mem_act_id);        }        return $_mem_act;    }    /**     * 插入分享log     *     * @param Game    $game_rq     * @param Channel $channel     * @param Device  $device     * @param Mem     $member     * @param         $_share_data     *     * @return bool|mixed     */    public function insertShareLog(Game $game_rq, Channel $channel, Device $device, Mem $member, $_share_data) {        $_data = $device->toArray();        $_data['mem_id'] = $member->getMemId();        $_data['create_time'] = time();        $_data['title'] = isset($_share_data['title']) ? $_share_data['title'] : '';        $_data['content'] = isset($_share_data['content']) ? $_share_data['content'] : '';        $_data['url'] = isset($_share_data['url']) ? $_share_data['url'] : '';        $_data['to_target'] = isset($_share_data['to_target']) ? $_share_data['to_target'] : '';        $_data['table_name'] = isset($_share_data['table_name']) ? $_share_data['table_name'] : '';        $_data['object_id'] = isset($_share_data['object_id']) ? $_share_data['object_id'] : '';        return (new ShareLogModel())->insertLog($_data);    }    /**     * 更新memAct     *     * @param $mem_act_id     mem_act_id     * @param $_mem_act_data  要更新的数组     *     * @return bool     */    public function updateMemAct($mem_act_id, $_mem_act_data) {        $_mem_act_model = new MemActivityModel();        $_old_data = $_mem_act_model->getMemActById($mem_act_id);        $_data = array_merge($_old_data, $_mem_act_data);        $_rs = $_mem_act_model->updateMemAct($_data, $mem_act_id);        return $_rs;    }}
 |