123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * Created by PhpStorm.
- * User: dianzhong
- * Date: 2018/11/8
- * Time: 14:06
- */
- namespace app\admin\service;
- use app\admin\library\Auth;
- use app\common\model\Activity;
- use app\common\model\Admin;
- use app\main\constants\ActivityConstants;
- use app\main\service\LogService;
- use think\Config;
- class CommonService
- {
- /**
- * @var CommonService
- */
- private static $instance = NULL;
- protected $configmodel = NULL;
- public function __construct()
- {
- $this->configmodel = model('Config');
- }
- /**
- * @return CommonService
- */
- public static function instance()
- {
- if (self::$instance == NULL) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- /**
- * 获取群发订阅号|群发服务号 最高上限
- * @return array
- * @throws \think\exception\DbException
- */
- public function getWechatAccountLimit()
- {
- $sub_data = $this->configmodel->get(['name' => 'group_hair_sub_max']);
- $ser_data = $this->configmodel->get(['name' => 'group_hair_ser_max']);
- $data = [
- 'subLimitNum' => $sub_data['value'] ?? 9999,
- 'serLimitNum' => $ser_data['value'] ?? 9999,
- ];
- return $data;
- }
- /**
- * 获取有效的活动
- * @return false|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getValidActivities($admin_id = 0)
- {
- $is_vip = 0;
- if ($admin_id) {
- $group = Auth::instance()->getGroups($admin_id);
- $group_id = isset($group) ? $group[0]['group_id'] : 0;
- if ($group_id == Auth::GROUP_ID_VIP) {
- $is_vip = 1;
- }
- }
- $activity = new Activity();
- $sql_db = $activity
- ->where('id', 'neq', 100)
- ->where('starttime', '<=', time())
- ->where('endtime', '>=', time())
- ->where('status', 'eq', 1);
- if ($is_vip) {
- $sql_db = $sql_db->where('type', 'eq', ActivityConstants::ACTIVITY_TYPE_PLAT);
- } else {
- $sql_db = $sql_db->where(function ($query) use ($admin_id) {
- $query->where('type', 'eq', ActivityConstants::ACTIVITY_TYPE_PLAT)
- ->whereOr('admin_id', 'eq', $admin_id);
- });
- }
- $data = $sql_db->select();
- $aActivity = [];
- if ($data) {
- foreach ($data as $activity) {
- $aActivity[$activity->id] = $activity->name;
- }
- }
- return $aActivity;
- }
- /**
- * 获取VIP创建的自定义活动列表
- * @param $admin_id
- * @return array
- */
- public function getVipActivityList($admin_id)
- {
- $result = [];
- $maps = [
- 'admin_id' => ['eq', $admin_id],
- 'type' => ['eq', ActivityConstants::ACTIVITY_TYPE_CUSTOM],
- 'status' => ['eq', '1'],
- 'endtime' => ['>', time()],
- ];
- $rows = model("Activity")->field("id, name, config_id")->where($maps)->order('id', 'desc')->select();
- if ($rows) {
- $activity_config = Config::get('site.activity_config');
- foreach ($rows as $row) {
- $config_id = $row['config_id'];
- $config = $activity_config['config'][$config_id] ?? null;
- if (!$config) {
- LogService::error("Activity Error activity_id:{$row['id']} config_id:{$config_id} Config Not Find");
- }
- $resourceModel = model("Resource")
- ->field(['id'])
- ->where('id', 'in', $config['resource_id'])
- ->where('resource_type', ActivityConstants::ACTIVITY_TYPE_CUSTOM)
- ->order('weigh', 'desc')->find();
- if ($resourceModel) {
- $result[$row['id']] = [
- 'id' => $row['id'],
- 'name' => $row['name'],
- 'rid' => $resourceModel['id']
- ];
- }
- }
- }
- return $result;
- }
- /**
- * 获取常用链接地址
- * @return array
- */
- public function getTmpDailyLink()
- {
- /*
- * @var 常用链接地址列表
- * [
- * @title 常用链接名称
- * @link 链接地址
- * @isUseMenuDomain getCurrentDomain方法参数
- * */
- return [
- 'userRecent' => ['title' => '最近阅读', 'link' => '/index/user/recent', 'isUseMenuDomain' => 1],
- 'manCategory' => ['title' => '男频分类', 'link' => '/index/category?sex=1', 'isUseMenuDomain' => 1],
- 'womenCategory' => ['title' => '女频分类', 'link' => '/index/category?sex=2', 'isUseMenuDomain' => 1],
- 'index' => ['title' => '首页', 'link' =>'/', 'isUseMenuDomain' => 1],
- 'userIndex' => ['title' => '个人中心', 'link' => '/index/user/index', 'isUseMenuDomain' => 1],
- 'rechargePay' => ['title' => '充值', 'link' => '/index/recharge/pay', 'isUseMenuDomain' => 1],
- 'search' => ['title' => '搜索', 'link' => '/index/index/search', 'isUseMenuDomain' => 1],
- 'userSign' => ['title' => '签到', 'link' => '/index/user/sign', 'isUseMenuDomain' => 1],
- 'girl' => ['title' => '女频专区', 'link' => '?type=girl', 'isUseMenuDomain' => 1],
- 'boy' => ['title' => '男频专区', 'link' => '?type=boy', 'isUseMenuDomain' => 1],
- 'bookFree' => ['title' => '限免专区', 'link' => '/index/book/list?type=free', 'isUseMenuDomain' => 0],
- 'vip' => ['title' => 'VIP充值', 'link' => '/index/recharge/vip?from=wechat', 'isUseMenuDomain' => 0],
- // 'smallpay' => ['title' => '小额充值', 'link' => '/index/recharge/smallpay', 'isUseMenuDomain' => 0],
- 'questionnaire' => ['title' => '调查问卷', 'link' => '/index/index/questionnaire', 'isUseMenuDomain' => 1],
- 'bookList' => ['title' => '排行榜', 'link' => '/index/book/list?sex=1', 'isUseMenuDomain' => 1]
- ];
- }
- }
|