123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * MemItgLogModel.php UTF-8
- * 玩家积分记录
- *
- * @date : 2018/5/5 14:40
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\model\integral;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use huolib\constant\IaConst;
- use huolib\constant\MemItgConst;
- use huolib\tool\Time;
- use think\Cache;
- class MemItgLogModel extends CommonModel {
- protected $name = 'mem_itg_log';
- protected $cache_prefix = CacheConst::CACHE_MEM_ITG_SUB_CNT_PREFIX;
- public function setTypeAttr($value) {
- }
- /**
- * 关联玩家表
- */
- public function mem() {
- return $this->hasOne('huo\model\member\MemberModel', 'id', 'mem_id', [], 'left');
- }
- /**
- * 关联玩家表
- */
- public function member() {
- return $this->belongsTo('huo\model\member\MemberModel', 'mem_id', 'id')->field(
- 'id,username,nickname,avatar,mobile,real_name'
- );
- }
- /**
- * 关联下级玩家表
- */
- public function submem() {
- return $this->belongsTo('huo\model\member\MemberModel', 'link_id', 'id')->field('id,nickname,avatar');
- }
- /**
- * 添加玩家积分LOG
- *
- * @param array $data
- *
- * @return bool|mixed
- */
- public function addMemIaLog($data) {
- $_data['mem_id'] = get_val($data, 'mem_id', 0);
- $_data['itg_type'] = get_val($data, 'itg_type', 0);
- $_data['integral_total'] = get_val($data, 'integral_total', 0);
- $_data['my_integral'] = get_val($data, 'my_integral', 0);
- $_data['integral'] = get_val($data, 'integral', 0);
- $_data['ia_id'] = get_val($data, 'ia_id', 0);
- $_data['sub_ia_id'] = get_val($data, 'sub_ia_id', 0);
- $_data['ia_name'] = get_val($data, 'ia_name', '');
- $_data['link_table'] = get_val($data, 'link_table', '');
- $_data['link_id'] = get_val($data, 'link_id', 0);
- $_data['create_time'] = time();
- $_app_id = get_val($data, 'app_id', 0);
- if (empty($_data)) {
- return false;
- }
- if ($_obj = self::create($_data)) {
- $_map['mem_id'] = $_data['mem_id'];
- $_map['ia_id'] = $_data['ia_id'];
- if ($_data['sub_ia_id'] != $_app_id) {
- $_map['sub_ia_id'] = $_data['sub_ia_id'];
- $_cnt = $this->getSubCnt($_map['mem_id'], $_map['ia_id'], $_map['sub_ia_id']);
- } else {
- $_cnt = $this->getSubCnt($_map['mem_id'], $_map['ia_id']);
- }
- $_cache_key = $this->cache_prefix.md5(json_encode($_map));
- $_cnt++;
- Cache::set($_cache_key, $_cnt);
- if (IaConst::IA_SHARE == $_data['ia_id']) {
- unset($_map);
- $_map['mem_id'] = $_data['mem_id'];
- $_map['itg_type'] = MemItgConst::MEM_ITG_ADD;
- $_map['ia_id'] = $_data['ia_id'];
- $_map['sub_ia_id'] = $_data['sub_ia_id'];
- $_map['link_table'] = $_data['link_table'];
- $_map['link_id'] = $_data['link_id'];
- $_share_cache_key = $this->cache_prefix.md5(json_encode($_map));
- $_cnt = $this->getShareCnt($_map['mem_id'], $_map['sub_ia_id'], $_map['link_id']);
- $_cnt++;
- Cache::set($_share_cache_key, $_cnt);
- }
- return $_obj->id;
- } else {
- return false;
- }
- }
- /**
- * 获取子任务数量
- *
- * @param int $mem_id
- * @param int $ia_id
- * @param int $sub_ia_id
- *
- * @return int|string
- */
- public function getSubCnt($mem_id, $ia_id, $sub_ia_id = 0) {
- $_map['mem_id'] = $mem_id;
- $_map['ia_id'] = $ia_id;
- if (!empty($sub_ia_id)) {
- $_map['sub_ia_id'] = $sub_ia_id;
- }
- $_cache_key = $this->cache_prefix.md5(json_encode($_map));
- $_cnt = Cache::get($_cache_key);
- if (is_numeric($_cnt)) {
- return $_cnt;
- }
- $_cnt = $this->where($_map)->count();
- if (empty($_cnt)) {
- $_cnt = 0;
- }
- Cache::set($_cache_key, $_cnt);
- return $_cnt;
- }
- /**
- * 判断是否获取过奖励
- *
- * @param int $mem_id
- * @param int $sub_ia_id
- * @param int $link_id
- *
- * @return int|string
- */
- public function getShareCnt($mem_id, $sub_ia_id = 0, $link_id) {
- $_ia_id = IaConst::IA_SHARE;
- $_map['mem_id'] = $mem_id;
- $_map['itg_type'] = MemItgConst::MEM_ITG_ADD;
- $_map['ia_id'] = $_ia_id;
- $_map['sub_ia_id'] = $sub_ia_id;
- $_map['link_table'] = 'member';
- $_map['link_id'] = $link_id;
- $_cache_key = $this->cache_prefix.md5(json_encode($_map));
- $_cnt = Cache::get($_cache_key);
- if (is_numeric($_cnt)) {
- return $_cnt;
- }
- $_cnt = $this->where($_map)->count();
- if (empty($_cnt)) {
- $_cnt = 0;
- }
- Cache::set($_cache_key, $_cnt);
- return $_cnt;
- }
- /**
- * 获取玩家今日任务领取奖励次数
- *
- * @param $ia_id
- * @param $mem_id
- * @param int $sub_ia_id
- *
- * @return int|string
- */
- public function getMemIaTodayCnt($ia_id, $mem_id, $sub_ia_id = 0) {
- list($today_start, $today_end) = Time::today();
- $_map['mem_id'] = $mem_id;
- $_map['itg_type'] = MemItgConst::MEM_ITG_ADD;
- $_map['ia_id'] = $ia_id;
- $_map['sub_ia_id'] = $sub_ia_id;
- $_map['create_time'] = ['gt', $today_start];
- $_cnt = $this->where($_map)->count();
- if (empty($_cnt)) {
- $_cnt = 0;
- }
- return $_cnt;
- }
- }
|