McMappingFansModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 17/2/23
  6. * Time: 上午10:53
  7. */
  8. /**
  9. * 公众号登录表
  10. */
  11. namespace app\frontend\modules\member\models;
  12. use app\common\models\McMappingFans;
  13. class McMappingFansModel extends McMappingFans
  14. {
  15. public $timestamps = false;
  16. protected $guarded = [];
  17. protected $fillable = ['openid','uid','acid','uniacid', 'salt', 'updatetime', 'nickname', 'follow', 'followtime', 'unfollowtime', 'tag'];
  18. protected $attributes = ['unionid' => '', 'groupid' => 0];
  19. /*public function getOauthUserInfo()
  20. {
  21. return mc_oauth_userinfo();
  22. }*/
  23. /**
  24. * 获取粉丝uid
  25. *
  26. * @param $openid
  27. * @return mixed
  28. */
  29. public static function getUId($openid)
  30. {
  31. return self::select('uid')
  32. ->uniacid()
  33. ->where('openid', $openid)
  34. ->first();
  35. }
  36. /**
  37. * 添加数据
  38. *
  39. * @param $data
  40. */
  41. public static function insertData($userinfo, $data)
  42. {
  43. if (isset($userinfo['subscribe']) && 1 == $userinfo['subscribe']) {
  44. $subscribe = 1;
  45. $followtime = explode(',', rtrim($userinfo['subscribe_time'],','));
  46. $count = count($followtime);
  47. $follow_time = $followtime[$count-1];
  48. } else {
  49. $subscribe = 0;
  50. $follow_time = time();
  51. }
  52. $fans_model = new McMappingFansModel();
  53. $fans_model->openid = $userinfo['openid'];
  54. $fans_model->unionid = !empty($userinfo['unionid']) ? $userinfo['unionid'] : '';
  55. $fans_model->uid = $data['uid'];
  56. $fans_model->acid = $data['uniacid'];
  57. $fans_model->uniacid = $data['uniacid'];
  58. $fans_model->salt = $data['salt'];
  59. $fans_model->updatetime = time();
  60. $fans_model->nickname = stripslashes($userinfo['nickname']);
  61. $fans_model->follow = $subscribe;
  62. $fans_model->followtime = $follow_time;
  63. $fans_model->unfollowtime = 0;
  64. $fans_model->tag = '';//小程序数据过长无法添加 base64_encode(serialize($userinfo));
  65. if ($fans_model->save()) {
  66. return $fans_model->uid;
  67. } else {
  68. return false;
  69. }
  70. }
  71. /**
  72. * 更新数据
  73. *
  74. * @param $uid
  75. * @param $data
  76. */
  77. public static function updateData($uid, $data)
  78. {
  79. self::uniacid()
  80. ->where('uid', $uid)
  81. ->update($data);
  82. }
  83. public static function updateDataById($id, $data)
  84. {
  85. self::uniacid()
  86. ->where('fanid', $id)
  87. ->update($data);
  88. }
  89. /**
  90. * 获取粉丝数据
  91. *
  92. * @param $openid
  93. * @return mixed
  94. */
  95. public static function getFansData($openid)
  96. {
  97. return self::select('fanid', 'uid','follow')
  98. ->uniacid()
  99. ->where('openid', $openid)
  100. ->first();
  101. }
  102. }