123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?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\userinfomodel;
- use app\index\model\usersharelogmodel;
- use app\index\server\scorebusinessserver as BusinessBase;
- /**
- * 分享出去
- * 20220104
- * wj
- */
- class sharebusinessserver 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);
- $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);
- }
- }
|