FansService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\wechat\service;
  15. use think\Db;
  16. /**
  17. * 微信粉丝信息
  18. * Class FansService
  19. * @package app\wechat\service
  20. */
  21. class FansService
  22. {
  23. /**
  24. * 增加或更新粉丝信息
  25. * @param array $user 粉丝信息
  26. * @param string $appid 微信APPID
  27. * @return boolean
  28. * @throws \think\Exception
  29. * @throws \think\exception\PDOException
  30. */
  31. public static function set(array $user, $appid = '')
  32. {
  33. if (!empty($user['subscribe_time'])) {
  34. $user['subscribe_at'] = date('Y-m-d H:i:s', $user['subscribe_time']);
  35. }
  36. if (isset($user['tagid_list']) && is_array($user['tagid_list'])) {
  37. $user['tagid_list'] = is_array($user['tagid_list']) ? join(',', $user['tagid_list']) : '';
  38. }
  39. if ($appid !== '') $user['appid'] = $appid;
  40. unset($user['privilege'], $user['groupid']);
  41. return data_save('WechatFans', $user, 'openid');
  42. }
  43. /**
  44. * 获取粉丝信息
  45. * @param string $openid
  46. * @return array|null
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public static function get($openid)
  52. {
  53. return Db::name('WechatFans')->where(['openid' => $openid])->find();
  54. }
  55. }