param = $param; $this->info = $this->getinfo($this->param); $this->option = json_decode($this->info['option'], true); $isaddscore = false; $msg = "分享出去"; $returndata = [ 'uaarid' => 0, 'addscore' => 0, ]; $result = $this->getuserinfo(); if (!$result['status']) { return $result; } $uinfo = $result['data']; $userid = $uinfo['id']; switch ($this->option['action']) { case 1: # 首次分享 if ($this->isfirst()) { $msg .= "-首次分享"; $isaddscore = true; } break; case 2: # 每次分享 $isaddscore = true; break; } if ($isaddscore) { $adddata = [ 'sourcedemo' => $msg, 'userid' => $userid, 'scoretype' => $this->info['scoretype'], 'addscore' => $this->info['score'], 'sourcetype' => 2, ]; $result = $this->adduserscore($adddata); if (empty($result['status'])) { return $result; } $data = $result['data']; $uaarid = $data['uaarid']; $recorddata = [ 'sbid' => $this->info['id'], 'code' => $this->info['code'], 'refid' => $uaarid, 'type' => 1, ]; $id = $this->newrecord($recorddata); if (!$id) { log::error($msg . " 创建关系失败"); } $returndata = [ 'uaarid' => $uaarid, 'addscore' => $adddata['addscore'], ]; } return backarr(1, $msg, $returndata); } /** * 获取是否首次分享 * 20220104 * wj */ private function isfirst() { $arr = $this->param; $where = []; if (isset($arr['openid'])) { $where['shareopenid'] = $arr['openid']; } if (isset($arr['userid'])) { $where['userid'] = $arr['userid']; } if (empty($where)) { throw new Exception("无用户信息"); } $where['sharetime'] = ['like', '%' . date('Y-m-d') . '%']; $m_usl = new usersharelogmodel(); $count = $m_usl->getList($where, 'count'); return 1 == $count ? true : false; } /** * 获取分享详情 * 20220104 * wj */ private function getuserinfo() { $arr = $this->param; $m_u = new userinfomodel(); $where = []; if (isset($arr['userid'])) { $where['id'] = $arr['userid']; } if (isset($arr['openid'])) { $where['openid'] = $arr['openid']; } $info = $m_u->getInfo($where); if (empty($info)) { return backarr(0, "无用户信息"); } return backarr(1, "查询成功", $info); } }