CommonService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dianzhong
  5. * Date: 2018/11/8
  6. * Time: 14:06
  7. */
  8. namespace app\admin\service;
  9. use app\admin\library\Auth;
  10. use app\common\model\Activity;
  11. use app\common\model\Admin;
  12. use app\main\constants\ActivityConstants;
  13. use app\main\service\LogService;
  14. use think\Config;
  15. class CommonService
  16. {
  17. /**
  18. * @var CommonService
  19. */
  20. private static $instance = NULL;
  21. protected $configmodel = NULL;
  22. public function __construct()
  23. {
  24. $this->configmodel = model('Config');
  25. }
  26. /**
  27. * @return CommonService
  28. */
  29. public static function instance()
  30. {
  31. if (self::$instance == NULL) {
  32. self::$instance = new self();
  33. }
  34. return self::$instance;
  35. }
  36. /**
  37. * 获取群发订阅号|群发服务号 最高上限
  38. * @return array
  39. * @throws \think\exception\DbException
  40. */
  41. public function getWechatAccountLimit()
  42. {
  43. $sub_data = $this->configmodel->get(['name' => 'group_hair_sub_max']);
  44. $ser_data = $this->configmodel->get(['name' => 'group_hair_ser_max']);
  45. $data = [
  46. 'subLimitNum' => $sub_data['value'] ?? 9999,
  47. 'serLimitNum' => $ser_data['value'] ?? 9999,
  48. ];
  49. return $data;
  50. }
  51. /**
  52. * 获取有效的活动
  53. * @return false|\PDOStatement|string|\think\Collection
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. * @throws \think\exception\DbException
  57. */
  58. public function getValidActivities($admin_id = 0)
  59. {
  60. $is_vip = 0;
  61. if ($admin_id) {
  62. $group = Auth::instance()->getGroups($admin_id);
  63. $group_id = isset($group) ? $group[0]['group_id'] : 0;
  64. if ($group_id == Auth::GROUP_ID_VIP) {
  65. $is_vip = 1;
  66. }
  67. }
  68. $activity = new Activity();
  69. $sql_db = $activity
  70. ->where('id', 'neq', 100)
  71. ->where('starttime', '<=', time())
  72. ->where('endtime', '>=', time())
  73. ->where('status', 'eq', 1);
  74. if ($is_vip) {
  75. $sql_db = $sql_db->where('type', 'eq', ActivityConstants::ACTIVITY_TYPE_PLAT);
  76. } else {
  77. $sql_db = $sql_db->where(function ($query) use ($admin_id) {
  78. $query->where('type', 'eq', ActivityConstants::ACTIVITY_TYPE_PLAT)
  79. ->whereOr('admin_id', 'eq', $admin_id);
  80. });
  81. }
  82. $data = $sql_db->select();
  83. $aActivity = [];
  84. if ($data) {
  85. foreach ($data as $activity) {
  86. $aActivity[$activity->id] = $activity->name;
  87. }
  88. }
  89. return $aActivity;
  90. }
  91. /**
  92. * 获取VIP创建的自定义活动列表
  93. * @param $admin_id
  94. * @return array
  95. */
  96. public function getVipActivityList($admin_id)
  97. {
  98. $result = [];
  99. $maps = [
  100. 'admin_id' => ['eq', $admin_id],
  101. 'type' => ['eq', ActivityConstants::ACTIVITY_TYPE_CUSTOM],
  102. 'status' => ['eq', '1'],
  103. 'endtime' => ['>', time()],
  104. ];
  105. $rows = model("Activity")->field("id, name, config_id")->where($maps)->order('id', 'desc')->select();
  106. if ($rows) {
  107. $activity_config = Config::get('site.activity_config');
  108. foreach ($rows as $row) {
  109. $config_id = $row['config_id'];
  110. $config = $activity_config['config'][$config_id] ?? null;
  111. if (!$config) {
  112. LogService::error("Activity Error activity_id:{$row['id']} config_id:{$config_id} Config Not Find");
  113. }
  114. $resourceModel = model("Resource")
  115. ->field(['id'])
  116. ->where('id', 'in', $config['resource_id'])
  117. ->where('resource_type', ActivityConstants::ACTIVITY_TYPE_CUSTOM)
  118. ->order('weigh', 'desc')->find();
  119. if ($resourceModel) {
  120. $result[$row['id']] = [
  121. 'id' => $row['id'],
  122. 'name' => $row['name'],
  123. 'rid' => $resourceModel['id']
  124. ];
  125. }
  126. }
  127. }
  128. return $result;
  129. }
  130. /**
  131. * 获取常用链接地址
  132. * @return array
  133. */
  134. public function getTmpDailyLink()
  135. {
  136. /*
  137. * @var 常用链接地址列表
  138. * [
  139. * @title 常用链接名称
  140. * @link 链接地址
  141. * @isUseMenuDomain getCurrentDomain方法参数
  142. * */
  143. return [
  144. 'userRecent' => ['title' => '最近阅读', 'link' => '/index/user/recent', 'isUseMenuDomain' => 1],
  145. 'manCategory' => ['title' => '男频分类', 'link' => '/index/category?sex=1', 'isUseMenuDomain' => 1],
  146. 'womenCategory' => ['title' => '女频分类', 'link' => '/index/category?sex=2', 'isUseMenuDomain' => 1],
  147. 'index' => ['title' => '首页', 'link' =>'/', 'isUseMenuDomain' => 1],
  148. 'userIndex' => ['title' => '个人中心', 'link' => '/index/user/index', 'isUseMenuDomain' => 1],
  149. 'rechargePay' => ['title' => '充值', 'link' => '/index/recharge/pay', 'isUseMenuDomain' => 1],
  150. 'search' => ['title' => '搜索', 'link' => '/index/index/search', 'isUseMenuDomain' => 1],
  151. 'userSign' => ['title' => '签到', 'link' => '/index/user/sign', 'isUseMenuDomain' => 1],
  152. 'girl' => ['title' => '女频专区', 'link' => '?type=girl', 'isUseMenuDomain' => 1],
  153. 'boy' => ['title' => '男频专区', 'link' => '?type=boy', 'isUseMenuDomain' => 1],
  154. 'bookFree' => ['title' => '限免专区', 'link' => '/index/book/list?type=free', 'isUseMenuDomain' => 0],
  155. 'vip' => ['title' => 'VIP充值', 'link' => '/index/recharge/vip?from=wechat', 'isUseMenuDomain' => 0],
  156. // 'smallpay' => ['title' => '小额充值', 'link' => '/index/recharge/smallpay', 'isUseMenuDomain' => 0],
  157. 'questionnaire' => ['title' => '调查问卷', 'link' => '/index/index/questionnaire', 'isUseMenuDomain' => 1],
  158. 'bookList' => ['title' => '排行榜', 'link' => '/index/book/list?sex=1', 'isUseMenuDomain' => 1]
  159. ];
  160. }
  161. }