123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /*
- * @Author: wang jun
- * @Date: 2021-10-29 16:16:29
- * @Last Modified by: wang jun
- * @Last Modified time: 2021-12-31 17:52:41
- */
- namespace app\index\server;
- use app\index\model\userapplylogmodel;
- use app\index\model\usersharelogmodel;
- use app\index\server\scorebusinessserver as BusinessBase;
- use think\Log;
- /**
- * 分享进入
- * 20220104
- * wj
- */
- class applybusinessserver extends BusinessBase
- {
- private $info;
- private $option;
- private $param;
- public function dobusiness($param)
- {
- $this->param = $param;
- $this->info = $this->getinfo($this->param);
- $this->option = json_decode($this->info['option'], true);
- $info = $this->getapplyinfo();
- if (!$info) {
- return backarr(0, "无数据");
- }
- $msg = "分享进入";
- $returndata = [
- 'uaarid' => 0,
- 'addscore' => 0,
- ];
- if (1 == $info['isnewuser']) {
- $msg .= "-新用户";
- $maxnewuser = $this->option['maxnewuser'];
- $shareresult = $this->getshareloginfo($info['shareuid']);
- if (!$shareresult['status']) {
- return $shareresult;
- }
- $shareinfo = $shareresult['data'];
- $userid = $shareinfo['userid'];
- $isaddscore = false;
- if ($maxnewuser > 0) {
- $count = $this->countnewuser($userid);
- if ($count < $maxnewuser) {
- $isaddscore = true;
- }
- } else {
- $isaddscore = true;
- }
- 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 countnewuser()
- {
- $arr = $this->param;
- $m_ual = new userapplylogmodel();
- if (!isset($arr['shareuid']) || empty($arr['shareuid']) || !is_numeric($arr['shareuid'])) {
- return backarr(0, "请求错误");
- }
- $where = [
- 'isnewuser' => 1,
- 'shareuid' => $arr['shareuid'],
- 'sharetime' => ['like', '%' . date('Y-m-d') . '%'],
- ];
- $count = $m_ual->getList($where, 'count');
- return $count;
- }*/
- public function countnewuser($userid)
- {
- $where = [
- 'usl.userid' => $userid,
- 'ual.sharetime' => ['like', '%' . date('Y-m-d') . '%'],
- 'ual.isnewuser' => 1,
- ];
- $m_usl = new usersharelogmodel();
- $count = $m_usl->getListjoinapply($where, 'count');
- $count = empty($count) ? 0 : $count;
- return $count;
- }
- /**
- * 获取详细
- * 20220104
- * wj
- */
- private function getapplyinfo()
- {
- $arr = $this->param;
- $where = [];
- if (isset($arr['shareuid'])) {
- $where['shareuid'] = $arr['shareuid'];
- }
- if (isset($arr['userid'])) {
- $where['userid'] = $arr['userid'];
- }
- if (isset($arr['openid'])) {
- $where['shareopenid'] = $arr['openid'];
- }
- if (isset($arr['applyid'])) {
- $where['id'] = $arr['applyid'];
- }
- $m_ual = new userapplylogmodel();
- $info = $m_ual->getInfo($where);
- if (empty($info)) {
- return false;
- }
- return $info;
- }
- /**
- * 获取分享详情
- * 20220104
- * wj
- */
- private function getshareloginfo($shareuid)
- {
- //$arr = $this->param;
- $m_usl = new usersharelogmodel();
- $where = [
- 'shareuid' => $shareuid,
- ];
- $info = $m_usl->getInfo($where);
- if (empty($info)) {
- return backarr(0, "无分享信息");
- }
- if (empty($info['userid'])) {
- return backarr(0, "无用户id");
- }
- return backarr(1, "查询成功", $info);
- }
- }
|