sharebusinessserver.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-10-29 16:16:29
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-31 17:52:41
  7. */
  8. namespace app\index\server;
  9. use app\index\model\userinfomodel;
  10. use app\index\model\usersharelogmodel;
  11. use app\index\server\scorebusinessserver as BusinessBase;
  12. /**
  13. * 分享出去
  14. * 20220104
  15. * wj
  16. */
  17. class sharebusinessserver extends BusinessBase
  18. {
  19. private $info;
  20. private $option;
  21. private $param;
  22. public function dobusiness($param)
  23. {
  24. $this->param = $param;
  25. $this->info = $this->getinfo($this->param);
  26. $this->option = json_decode($this->info['option'], true);
  27. $isaddscore = false;
  28. $msg = "分享出去";
  29. $returndata = [
  30. 'uaarid' => 0,
  31. 'addscore' => 0,
  32. ];
  33. $result = $this->getuserinfo();
  34. if (!$result['status']) {
  35. return $result;
  36. }
  37. $uinfo = $result['data'];
  38. $userid = $uinfo['id'];
  39. switch ($this->option['action']) {
  40. case 1:
  41. # 首次分享
  42. if ($this->isfirst()) {
  43. $msg .= "-首次分享";
  44. $isaddscore = true;
  45. }
  46. break;
  47. case 2:
  48. # 每次分享
  49. $isaddscore = true;
  50. break;
  51. }
  52. if ($isaddscore) {
  53. $adddata = [
  54. 'sourcedemo' => $msg,
  55. 'userid' => $userid,
  56. 'scoretype' => $this->info['scoretype'],
  57. 'addscore' => $this->info['score'],
  58. 'sourcetype' => 2,
  59. ];
  60. $result = $this->adduserscore($adddata);
  61. if (empty($result['status'])) {
  62. return $result;
  63. }
  64. $data = $result['data'];
  65. $uaarid = $data['uaarid'];
  66. $recorddata = [
  67. 'sbid' => $this->info['id'],
  68. 'code' => $this->info['code'],
  69. 'refid' => $uaarid,
  70. 'type' => 1,
  71. ];
  72. $id = $this->newrecord($recorddata);
  73. if (!$id) {
  74. log::error($msg . " 创建关系失败");
  75. }
  76. $returndata = [
  77. 'uaarid' => $uaarid,
  78. 'addscore' => $adddata['addscore'],
  79. ];
  80. }
  81. return backarr(1, $msg, $returndata);
  82. }
  83. /**
  84. * 获取是否首次分享
  85. * 20220104
  86. * wj
  87. */
  88. private function isfirst()
  89. {
  90. $arr = $this->param;
  91. $where = [];
  92. if (isset($arr['openid'])) {
  93. $where['shareopenid'] = $arr['openid'];
  94. }
  95. if (isset($arr['userid'])) {
  96. $where['userid'] = $arr['userid'];
  97. }
  98. if (empty($where)) {
  99. throw new Exception("无用户信息");
  100. }
  101. $where['sharetime'] = ['like', '%' . date('Y-m-d') . '%'];
  102. $m_usl = new usersharelogmodel();
  103. $count = $m_usl->getList($where, 'count');
  104. return 1 == $count ? true : false;
  105. }
  106. /**
  107. * 获取分享详情
  108. * 20220104
  109. * wj
  110. */
  111. private function getuserinfo()
  112. {
  113. $arr = $this->param;
  114. $m_u = new userinfomodel();
  115. $where = [];
  116. if (isset($arr['userid'])) {
  117. $where['id'] = $arr['userid'];
  118. }
  119. if (isset($arr['openid'])) {
  120. $where['openid'] = $arr['openid'];
  121. }
  122. $info = $m_u->getInfo($where);
  123. if (empty($info)) {
  124. return backarr(0, "无用户信息");
  125. }
  126. return backarr(1, "查询成功", $info);
  127. }
  128. }