123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2018/12/3
- * Time: 下午3:38
- */
- namespace app\main\service;
- use app\common\model\Activity;
- use app\common\model\Goods;
- use app\common\model\Resource;
- use app\main\constants\ActivityConstants;
- use app\main\constants\AdminConstants;
- use app\main\constants\PayConstants;
- use app\main\constants\UserConstants;
- use app\main\helper\ArrayHelper;
- use app\main\model\object\UserObject;
- use think\Config;
- use think\Exception;
- use think\Request;
- use app\common\library\Redis;
- /**
- * 处理活动
- * Class ActivityService
- * @package app\main\service
- */
- class ActivityService extends BaseService
- {
- /**
- * @var ActivityService
- */
- protected static $self = NULL;
- /**
- * @return ActivityService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * @return Activity
- */
- public function getActivityModel()
- {
- return model('Activity');
- }
- /**
- * @return Resource
- */
- public function getResourceModel()
- {
- return model('Resource');
- }
- /**
- * @return Goods
- */
- public function getGoodsModel()
- {
- return model('Goods');
- }
- /**
- * 前台登录的活动获取
- * @param $controllerName
- * @param $actionName
- * @param $channel_id
- * @param $user_id
- * @return null
- */
- public function getActivityFront($controllerName, $actionName,$channel_id,$user_id)
- {
- $relation = [
- 'user_recent' => ActivityConstants::RESOURCE_POP_RANGE_RECENT,
- 'index_index' => ActivityConstants::RESOURCE_POP_RANGE_MALE,
- 'index_index_girl' => ActivityConstants::RESOURCE_POP_RANGE_FEMALE,
- 'index_index_boy' => ActivityConstants::RESOURCE_POP_RANGE_MALE,
- 'user_index' => ActivityConstants::RESOURCE_POP_RANGE_PERSONAL,
- 'category_index' => ActivityConstants::RESOURCE_POP_RANGE_CATEGORY,
- 'book_list_free' => ActivityConstants::RESOURCE_POP_RANGE_FREE,
- 'book_list_finish' => ActivityConstants::RESOURCE_POP_RANGE_COMPLETE,
- ];
- $type = ArrayHelper::array_get($_GET, 'type', '');
- if($type){
- $key = implode('_', [$controllerName, $actionName, $type]);
- }else{
- $key = implode('_', [$controllerName, $actionName]);
- }
- $pop_range = ArrayHelper::array_get($relation, $key, ActivityConstants::RESOURCE_POP_RANGE_RECENT);
- $time = Request::instance()->server('REQUEST_TIME');
- $user = UserService::instance();
- $show_type = [];
- //商品资源展示对象
- if ($user->is_pay == UserConstants::USER_IS_PAY_NO) {
- $show_type['goods']['pay_type'] = ActivityConstants::GOODS_SHOW_TYPE_PAY_NO; //未付费
- } else {
- $show_type['goods']['pay_type'] = ActivityConstants::GOODS_SHOW_TYPE_PAY_YES; //普通付费
- }
- //用户类别
- if ($user->createtime < strtotime(date("Ymd"))) {
- //老用户
- $show_type['goods']['register_type'] = ActivityConstants::GOODS_SHOW_TYPE_USER_OLD;
- } else {
- //新用户
- $show_type['goods']['register_type'] = ActivityConstants::GOODS_SHOW_TYPE_USER_NEW;
- }
- //活动资源展示对象
- if ($user->is_pay == UserConstants::USER_IS_PAY_NO) {
- $show_type['resource']['pay_type'] = ActivityConstants::RESOURCE_PAY_NOT; //未付费
- } else {
- $show_type['resource']['pay_type'] = ActivityConstants::RESOURCE_PAY_NORMAL; //普通付费
- }
- //年费会员
- if ($user->vip_endtime > $time) {
- $show_type['resource']['pay_type'] = ActivityConstants::RESOURCE_PAY_YEAR; //年费会员
- }
- $activityRes = $this->getActivity($pop_range, $show_type, $channel_id, $user_id);
- if ($activityRes) {
- return $activityRes;
- }
- return null;
- }
- /**
- * 获取活动的资源,如果能关联到活动商品,以商品的展示对象为准;如果不能,则以资源的展示对象为准
- * @param $aid 活动id
- * @return array 活动对象+是否超出活动范围(1超出;0正常展示)
- */
- public function getActivityResource($aid)
- {
- $goodsShowTypes = $this->_makeGoodsShowType();//通过当前用户登录信息确定"展示对象"
- $arRedisKey = 'ARK:1:'.md5(json_encode($goodsShowTypes)).":".$aid;
- $arRedisData = Redis::instance()->get($arRedisKey);
- if ($arRedisData === false) {
- $resource = $this->getResourceModel()->join(['goods' => 'g'], 'g.id=resource.goods_id')
- ->field(['resource.id'])
- ->whereIn('g.show_type', $goodsShowTypes)
- ->where('activity_id', $aid)
- ->order('resource.weigh', 'desc')
- ->select();
- if (!empty($resource)) {
- $result = [current($resource), 0];
- Redis::instance()->set($arRedisKey, json_encode($result), 60);
- } else {
- $resourceShowTypes = $this->_makeResourceShowType();
- $arRedisKey2 = 'ARK:2:'.md5(json_encode($resourceShowTypes)).":".$aid;
- $arRedisData2 = Redis::instance()->get($arRedisKey2);
- if ($arRedisData2 === false) {
- $resource = $this->getResourceModel()->field(['resource.id'])
- ->whereIn('show_type', $resourceShowTypes)
- ->where('activity_id', $aid)
- ->order('weigh', 'desc')
- ->select();
- if (!empty($resource)) {
- $result = [current($resource), 0];
- Redis::instance()->set($arRedisKey2, json_encode($result), 60);
- } else {
- $arRedisKey3 = 'ARK:3:'.":".$aid;
- $arRedisData3 = Redis::instance()->get($arRedisKey3);
- if ($arRedisData3 === false) {
- $resource = $this->getResourceModel()->where('activity_id', $aid)
- ->find();
- $result = [$resource, 1];
- Redis::instance()->set($arRedisKey3, json_encode($result), 60);
- } else {
- $result = json_decode($arRedisData3, true);
- }
- }
- } else {
- $result = json_decode($arRedisData2, true);
- }
- }
- } else {
- $result = json_decode($arRedisData, true);
- }
- return $result;
- }
- /**
- * 构造商品的显示范围
- * @return array
- */
- private function _makeGoodsShowType()
- {
- $user = UserService::instance()->getUserInfo();
- $showType = $user->is_pay == UserConstants::USER_IS_PAY_NO ?
- PayConstants::GOODS_SHOW_TYPE_UN_RECHARGED : PayConstants::GOODS_SHOW_TYPE_RECHARGED;
- return [PayConstants::GOODS_SHOW_TYPE_ALL, $showType];
- }
- /**
- * 构造资源的显示范围
- * @return array
- */
- private function _makeResourceShowType()
- {
- $time = Request::instance()->server('REQUEST_TIME');
- $user = UserService::instance()->getUserInfo();
- if ($user->is_pay == UserConstants::USER_IS_PAY_NO) {
- $showType = ActivityConstants::RESOURCE_PAY_NOT; //未付费
- } else {
- $showType = ActivityConstants::RESOURCE_PAY_NORMAL; //普通付费
- }
- if ($user->vip_endtime > $time) {
- $showType = ActivityConstants::RESOURCE_PAY_YEAR; //年费会员
- }
- return [ActivityConstants::RESOURCE_ALL, $showType];
- }
- public function getActivity($pop_range, $show_type, $channel_id, $user_id)
- {
- if ($channel_id) {
- $group_id = model('AuthGroupAccess')->getGroupId($channel_id);
- $ex_info = model('AdminExtend')->getInfo($channel_id);
- //-------------------渠道自定义活动
- //平台没有活动时,检查渠道的活动
- if (AdminConstants::ADMIN_GROUP_ID_CHANNEL == $group_id) {
- if ($res = $this->getChannelActivity($pop_range, $show_type['goods'], $channel_id, $user_id)) {
- return $res;
- }
- }
- //检查配号代理商
- if (AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id && intval($ex_info['distribute'])) {
- //渠道有活动返回渠道的
- if ($res = $this->getChannelActivity($pop_range, $show_type['goods'], $ex_info['create_by'], $user_id)) {
- return $res;
- }
- //检查配号代理商
- if ($res = $this->getChannelActivity($pop_range, $show_type['goods'], $channel_id, $user_id)) {
- return $res;
- }
- }
- //渠道没有时检查普通代理商
- if (AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id && !intval($ex_info['distribute'])) {
- if ($res = $this->getChannelActivity($pop_range, $show_type['goods'], $ex_info['create_by'], $user_id)) {
- return $res;
- }
- }
- //平台有活动时显示平台的
- if ($res = $this->getPlatformActivity($pop_range, $show_type['goods'])) {
- return $res;
- }
- //-------------------赠币活动
- //平台没有活动时,检查渠道的活动
- //判断是否关闭了赠币
- $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
- if ($adminConfig && $adminConfig['give_kandian'] == 0) {
- return null;
- }
- if (AdminConstants::ADMIN_GROUP_ID_CHANNEL == $group_id) {
- if ($res = $this->getGiveActivity($pop_range, $show_type['resource'], $channel_id, $user_id)) {
- return $res;
- }
- }
- //检查配号代理商
- if (AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id && intval($ex_info['distribute'])) {
- //渠道有活动返回渠道的
- if ($res = $this->getGiveActivity($pop_range, $show_type['resource'], $ex_info['create_by'], $user_id)) {
- return $res;
- }
- //检查配号代理商
- if ($res = $this->getGiveActivity($pop_range, $show_type['resource'], $channel_id, $user_id)) {
- return $res;
- }
- }
- //渠道没有时检查普通代理商
- if (AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id && !intval($ex_info['distribute'])) {
- if ($res = $this->getGiveActivity($pop_range, $show_type['resource'], $ex_info['create_by'], $user_id)) {
- return $res;
- }
- }
- }
- return null;
- }
- /**
- * 获取平台活动
- * @param $pop_range
- * @param $show_type
- * @return mixed
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- private function getPlatformActivity($pop_range, $show_type)
- {
- if (!is_array($show_type)) {
- $show_type = [$show_type];
- }
- $res = null;
- $key = "S-P-T-P:N:";
- $redis = Redis::instance();
- foreach ($show_type as $user_type) {
- $positionKey[] = "{$pop_range}:{$user_type}";
- }
- $redisVals = $redis->hMGet($key, $positionKey);
- foreach ($redisVals as $k => $redisVal) {
- if ($redisVal != false) {
- $data = json_decode($redisVal, true);
- //判断活动结束时间
- if ($data && isset($data['endtime'])) {
- if ($data['endtime'] <= time()) {
- //结束啦
- continue;
- }
- }
- $res = $data;
- break;
- }
- }
- return $res;
- }
- /**
- * @param $resourceShowType
- * @return array
- */
- private function _makeGoodShowTypeFromResource($resourceShowType)
- {
- $goodsShowTypes = [PayConstants::GOODS_SHOW_TYPE_ALL];
- switch ($resourceShowType) {
- case ActivityConstants::RESOURCE_PAY_NOT:
- $goodsShowTypes[] = PayConstants::GOODS_SHOW_TYPE_UN_RECHARGED;
- break;
- case ActivityConstants::RESOURCE_PAY_NORMAL:
- $goodsShowTypes[] = PayConstants::GOODS_SHOW_TYPE_RECHARGED;
- break;
- case ActivityConstants::RESOURCE_PAY_YEAR:
- $goodsShowTypes[] = PayConstants::GOODS_SHOW_TYPE_RECHARGED;
- break;
- default:
- break;
- }
- return $goodsShowTypes;
- }
- /**
- * 获取渠道商活动
- * @param $pop_range
- * @param $show_type
- * @param $channel_id
- * @param $user_id
- * @return mixed
- */
- private function getChannelActivity($pop_range, $show_type, $channel_id, $user_id)
- {
- if (!is_array($show_type)) {
- $show_type = [$show_type];
- }
- $res = null;
- $key = "S-P-T-C:N:{$channel_id}";
- $redis = Redis::instance();
- foreach ($show_type as $user_type) {
- $positionKey[] = "{$pop_range}:{$user_type}";
- }
- $redisVals = $redis->hMGet($key, $positionKey);
- foreach ($redisVals as $k => $redisVal) {
- if ($redisVal != false) {
- $data = json_decode($redisVal, true);
- //判断活动结束时间
- if ($data && isset($data['endtime'])) {
- if ($data['endtime'] <= time()) {
- //结束啦
- continue;
- }
- }
- //检查限制
- if ($data && array_key_exists('limited', $data)) {
- if (intval($data['limited'])) {
- //用户在渠道自定义的活动充值次数统计
- $pay_count = intval($redis->hGet("ATPU:{$data['aid']}", $user_id));
- if (intval($data['limited']) <= $pay_count) {
- continue;
- }
- }
- }
- $res = $data;
- break;
- }
- }
- if(isset($show_type['pay_type']) && isset($res['pop_ispay']) && $res['pop_ispay']!=1){
- if($res['pop_ispay'] == 3 && $show_type['pay_type'] == 1){
- $res = null;
- }
- if($res['pop_ispay'] ==2 && $show_type['pay_type'] == 2 ){
- $res = null;
- }
- }
- return $res;
- }
- /**
- * 获取渠道商自定义活动列表,供充值页面使用
- * @param UserObject $userInfo
- * @return array|mixed
- */
- public function getRechargePageChannelActivity($userInfo)
- {
- $channelId = $userInfo->channel_id;
- $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channelId);
- if ($adminConfig['activity_show_recharge_page'] == 0) {
- return [];
- }
- $activityConfig = Config::get('site.activity_config');
- $redis = Redis::instance();
- $userId = $userInfo->id;
- $key = "CIEN:".$channelId;
- if ($redis->exists($key)) {
- $res = json_decode($redis->get($key), true);
- } else {
- $time = time();
- $res = [];
- $activitySimpleList = [];
- $activityList = $this->getActivityModel()
- ->field(['id', 'config_id', 'limited', 'pop_status'])
- ->where('starttime', '<', $time)
- ->where('endtime', '>', $time)
- ->where('status', '1')
- ->where('type', '1')
- ->where('show_for_recharge_page', 1)
- ->where('admin_id', $channelId)
- ->order('createtime desc')
- ->select();
- if ($activityList) {
- $resourceIds = [];
- foreach ($activityList as $activity) {
- //获取活动的ConfigID
- $config_id = $activity['config_id'] ?? null;
- if (!$config_id) {
- LogService::error("Activity Error activity_id:{$activity['id']} ConfigID is Null");
- continue;
- }
- $config = $activityConfig['config'][$config_id] ?? null;
- if (!$config) {
- LogService::error("Activity Error activity_id:{$activity['id']} config_id:{$config_id} Config Not Find");
- continue;
- }
- if ($config && intval($config['status']) && (isset($config['resource_id']) && $config['resource_id'])) {
- $item = [
- 'activity_id' => $activity['id'],
- 'config_id' => $activity['config_id'],
- 'limited' => $activity['limited'],
- 'resource_id' => $config['resource_id'],
- ];
- $activitySimpleList[] = $item;
- $resourceIds[] = $config['resource_id'];
- } else {
- continue;
- }
- }
- $actCategoryId = GoodsService::instance()->getActivityGoodsCategoryId();
- $resourceList = $this->getResourceModel()->alias('r')->join(['goods' => 'g'], 'r.goods_id = g.id')
- ->field([
- 'r.id' => 'rid',
- 'g.id',
- 'category_id',
- 'title',
- 'g.money',
- 'g.first_description',
- 'g.second_description',
- 'g.kandian',
- 'g.free_kandian',
- 'g.icon',
- 'g.show_type',
- 'g.type'
- ])
- ->whereIn('r.id', $resourceIds)
- ->where('resource_type', ActivityConstants::ACTIVITY_TYPE_CUSTOM)
- ->where('r.status', '1')
- ->where("find_in_set($actCategoryId,g.category_id)")
- ->order('r.weigh', 'desc')
- ->select();
- foreach ($activitySimpleList as $activitySimpleItem) {
- foreach ($resourceList as $resItem) {
- if ($activitySimpleItem['resource_id'] == $resItem['rid']) {
- $item = $activitySimpleItem;
- $item['money'] = $resItem['money'];
- $item['show_type'] = $resItem['show_type'];
- $item['id'] = $resItem['id'];
- $item['category_id'] = $resItem['category_id'];
- $item['kandian'] = $resItem['kandian'];
- $item['free_kandian'] = $resItem['free_kandian'];
- $item['title'] = $resItem['title'];
- $item['icon'] = $resItem['icon'];
- $item['first_description'] = $resItem['first_description'];
- $item['second_description'] = $resItem['second_description'];
- $res[] = $item;
- }
- }
- }
- }
- $redis->set($key, json_encode($res, JSON_UNESCAPED_UNICODE), 60);
- }
- if (intval($userInfo->is_pay) == 0) {
- $goodsShowTypes = [PayConstants::GOODS_SHOW_TYPE_ALL, PayConstants::GOODS_SHOW_TYPE_UN_RECHARGED];
- } else {
- $goodsShowTypes = [PayConstants::GOODS_SHOW_TYPE_ALL, PayConstants::GOODS_SHOW_TYPE_RECHARGED];
- }
- //检查次数限制
- foreach ($res as $item) {
- if (intval($item['limited'])) {
- //用户在渠道自定义的活动充值次数统计
- $pay_count = intval($redis->hGet("ATPU:{$item['activity_id']}", $userId));
- if (intval($item['limited']) <= $pay_count) {
- unset($item);
- continue;
- }
- if (in_array($item['show_type'], $goodsShowTypes)) {
- unset($item);
- continue;
- }
- }
- }
- return $res;
- }
- /**
- * 获取赠币活动
- * @param $pop_range
- * @param $show_type
- * @param $channel_id
- * @param $user_id
- * @return mixed
- */
- private function getGiveActivity($pop_range, $show_type, $channel_id, $user_id)
- {
- if (!is_array($show_type)) {
- $show_type = [$show_type];
- }
- $res = null;
- $key = "S-P-T-G:N:{$channel_id}";
- $redis = Redis::instance();
- foreach ($show_type as $user_type) {
- $positionKey[] = "{$pop_range}:{$user_type}";
- }
- $redisVals = $redis->hMGet($key, $positionKey);
- foreach ($redisVals as $k => $redisVal) {
- if ($redisVal != false) {
- $data = json_decode($redisVal, true);
- //判断活动结束时间
- if ($data && isset($data['endtime'])) {
- if ($data['endtime'] <= time()) {
- //结束啦
- continue;
- }
- }
- //检查限制
- if ($data && array_key_exists('limited', $data)) {
- if (intval($data['limited'])) {
- //用户在渠道自定义的活动充值次数统计
- $pay_count = intval($redis->hGet("ATGP:{$data['aid']}", $user_id));
- if (intval($data['limited']) <= $pay_count) {
- continue;
- }
- }
- }
- $res = $data;
- break;
- }
- }
- if(isset($show_type['pay_type']) && isset($res['pop_ispay']) && $res['pop_ispay']!=1){
- if($res['pop_ispay'] == 3 && $show_type['pay_type'] == 2){
- $res = null;
- }
- if($res['pop_ispay'] ==2 && $show_type['pay_type'] == 1 ){
- $res = null;
- }
- }
- return $res;
- }
- /**
- * 获取活动资源信息,其中type属性以goods表为准(1=看点充值,2=VIP充值)
- * @param $rid 资源id
- * @return array|false|\PDOStatement|string|\think\Model|null
- */
- public function getResourceForFront($rid)
- {
- //加缓存
- $key = 'A-R-R:'.$rid;
- if (Redis::instance()->exists($key)) {
- $res = json_decode(Redis::instance()->get($key), true);
- } else {
- $resource = $this->getResourceModel()->getInfo($rid);
- if (empty($resource)) {
- $res = [];
- } else {
- if ($resource['goods_id'] == 0) {
- $resource['type'] = $resource['type'] == 1 ? 2 : 1;
- $res = $resource;
- } else {
- $goods = $this->getGoodsModel()->find($resource['goods_id']);
- $res = [
- 'day' => $goods['day'],
- 'type' => $goods['type'],
- 'money' => $goods['money'],
- 'kandian' => $goods['kandian'],
- 'free_kandian' => $goods['free_kandian'],
- 'free_day' => $goods['free_day'],
- 'activity_id' => $resource['activity_id'],
- 'name' => $resource['name'],
- ];
- }
- }
- Redis::instance()->set($key, json_encode($res, JSON_UNESCAPED_UNICODE), 60);
- }
- return $res;
- }
- public function getActivityInfo($aid)
- {
- $resourceInfo = $this->getResourceModel()->where('activity_id', $aid)->find();
- $res = [];
- try {
- if (empty($resourceInfo)) {//渠道商自定义活动
- $aInfo = $this->getActivityModel()->where('id', $aid)->find();
- if (empty($aInfo)) {
- throw new Exception('没有找到活动,aId:' . $aid);
- }
- $configId = $aInfo['config_id'];
- $activity_config = Config::get('site.activity_config');
- $config = $activity_config['config'][$configId] ?? null;
- if (empty($config)) {
- throw new Exception('没有找到config,config_id:' . $configId);
- }
- if ($config && (isset($config['resource_id']) && $config['resource_id'])
- ) {
- $resourceInfo = $this->getResourceModel()->where('id', $config['resource_id'])->find();
- if (empty($resourceInfo)) {
- throw new Exception('渠道商自定义活动没有找到资源,rid:' . $config['resource_id']);
- }
- $res = $this->makeActivityInfo($resourceInfo);
- }
- return $res;
- } else {//平台活动
- $res = $this->makeActivityInfo($resourceInfo);
- return $res;
- }
- } catch (Exception $e) {
- LogService::error($e->getMessage());
- $res['free_day'] = Config::get('site.kandian_free_day');
- return $res;
- }
- }
- private function makeActivityInfo($resourceInfo)
- {
- if (empty($resourceInfo['goods_id'])) {
- $res['free_day'] = $resourceInfo['free_day'];
- } else {
- $goodsInfo = $this->getGoodsModel()->getGoodsInfoById($resourceInfo['goods_id']);
- if (empty($goodsInfo)) {
- throw new Exception('没有找到商品,goodsId:' . $resourceInfo['goods_id']);
- }
- $res['free_day'] = $goodsInfo['free_day'];
- }
- return $res;
- }
- /**
- * 获取有效的活动
- * @return false|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getValidActivities($type = 0)
- {
- $map['type'] = ['in', [0, 1, 2]];
- if ($type) {
- $map['type'] = ['eq', $type];
- }
- //$activity = new Activity();
- $data = $this->getActivityModel()
- ->where($map)
- ->where('status', 'eq', 1)
- ->where('starttime', '<', time())
- ->where('endtime', '>', time())
- ->select();
- $aActivity = [];
- if($data){
- foreach ($data as $activity) {
- $aActivity[$activity->id] = $activity->name;
- }
- }
- return $aActivity;
- }
- }
|