UserProfile.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\weixin\model;
  3. use app\weixin\service\Award;
  4. use app\weixin\service\PRedis;
  5. use think\Db;
  6. use think\Model;
  7. class UserProfile extends Model
  8. {
  9. protected $table = 'sg_user_profile';
  10. /**
  11. * 验证资料是否存在
  12. * @param $userId
  13. * @return mixed
  14. */
  15. public static function checkProfile($userId){
  16. return UserProfile::where(['userid'=> $userId])->value('id');
  17. }
  18. /**
  19. * 保存资料
  20. * @param $where 条件
  21. * @param $data 数据
  22. * @return int|string
  23. */
  24. public static function saveData($where, $data){
  25. $data['updated_at'] = date('Y-m-d H:i:s');
  26. return UserProfile::where($where)->update($data);
  27. }
  28. /**
  29. * 完善资料奖励
  30. * @param $userId
  31. * @return bool|int|string
  32. */
  33. public static function profileAward($userId){
  34. // 验证资料是否已完善
  35. $profile = UserProfile::checkUserProfile($userId);
  36. $isAward = isset($profile['profile_award_status'])? intval($profile['profile_award_status']) : 0;
  37. PRedis::set('member:profileAward:'.$userId, $profile, 600);
  38. if(empty($profile) || $isAward || (empty($profile['photolist']) || empty($profile['introduce']) || empty($profile['family']) || empty($profile['hobby']) || empty($profile['purpose']) || empty($profile['cause']) || empty($profile['expect']))){
  39. // 设置为隐身模式
  40. Member::saveData(['id'=> $userId], ['is_heart'=> 0]);
  41. return false;
  42. }
  43. // 加入怦然心动,关闭隐身
  44. Member::saveData(['id'=> $userId], ['is_heart'=> 1]);
  45. // 完善资料分销奖励
  46. $inviteInfo = Member::getInviteInfo($userId);
  47. $inviteId = isset($inviteInfo['invite_id'])? $inviteInfo['invite_id'] : 0;
  48. if($inviteInfo && $inviteId>0){
  49. if(!UserBalanceLog::checkHasMarket($inviteId, $userId, 4)){
  50. Award::marketAward($inviteId, $userId, 4);
  51. }
  52. }
  53. // 不在送爱心
  54. return false;
  55. /*Db::startTrans();
  56. $siteInfo = cmf_get_site_info();
  57. $awardNum = isset($siteInfo['profile_award_redheart'])? intval($siteInfo['profile_award_redheart']) : 0;
  58. $field = 'id,openid,user_nickname,real_name,redheart';
  59. $memberInfo = Member::getInfo(['id'=> $userId], $field);
  60. if($awardNum){
  61. $redheart = isset($memberInfo['redheart'])? intval($memberInfo['redheart']) : 0;
  62. if(!Member::saveData(['id'=> $userId], ['redheart'=> intval($redheart + $awardNum)])){
  63. Db::rollback();
  64. return 2125;
  65. }
  66. // 账户明细
  67. $remark = "完善资料奖励{$awardNum}个爱心";
  68. $accountData = [
  69. 'type' => 4,
  70. 'account_type' => 1,
  71. 'change_type' => 1,
  72. 'user_id' => $userId,
  73. 'money' => $awardNum,
  74. 'balance' => $redheart,
  75. 'created_at' => date('Y-m-d H:i:s'),
  76. 'remark' => $remark,
  77. ];
  78. AccountLog::insertGetId($accountData);
  79. }
  80. // 加入怦然心动
  81. if(!Member::saveData(['id'=> $userId], ['is_heart'=> 1])){
  82. Db::rollback();
  83. return false;
  84. }
  85. // 奖励爱心
  86. $res = UserProfile::saveData(['userid'=> $userId], ['profile_award_status'=> 1]);
  87. if(!$res){
  88. Db::rollback();
  89. return false;
  90. }
  91. Db::commit();
  92. return $res;*/
  93. }
  94. /**
  95. * 验证用户信息是否完善
  96. * @param $userId
  97. * @return array|bool|false|\PDOStatement|string|Model
  98. */
  99. public static function checkUserProfile($userId){
  100. $field = 'photolist,introduce,family,hobby,purpose,cause,expect,profile_award_status';
  101. $profile = UserProfile::getInfo(['userid'=> $userId], $field);
  102. if(empty($profile) || (empty($profile['photolist']) || empty($profile['introduce']) || empty($profile['family']) || empty($profile['hobby']) || empty($profile['purpose']) || empty($profile['cause']) || empty($profile['expect']))){
  103. return false;
  104. }
  105. return $profile;
  106. }
  107. /**
  108. * 获取会员信息
  109. * @param $where 条件
  110. * @param string $field 字段
  111. * @return array|false|\PDOStatement|string|Model
  112. */
  113. public static function getInfo($where, $field = "")
  114. {
  115. $field = $field? $field : 'id,userid,idcard,wechat_code,qq';
  116. $info = UserProfile::where($where)->field($field)->find();
  117. return $info ? $info->toArray() : [];
  118. }
  119. }