applybusinessserver.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\userapplylogmodel;
  10. use app\index\model\usersharelogmodel;
  11. use app\index\server\scorebusinessserver as BusinessBase;
  12. use think\Log;
  13. /**
  14. * 分享进入
  15. * 20220104
  16. * wj
  17. */
  18. class applybusinessserver extends BusinessBase
  19. {
  20. private $info;
  21. private $option;
  22. private $param;
  23. public function dobusiness($param)
  24. {
  25. $this->param = $param;
  26. $this->info = $this->getinfo($this->param);
  27. $this->option = json_decode($this->info['option'], true);
  28. $info = $this->getapplyinfo();
  29. if (!$info) {
  30. return backarr(0, "无数据");
  31. }
  32. $msg = "分享进入";
  33. $returndata = [
  34. 'uaarid' => 0,
  35. 'addscore' => 0,
  36. ];
  37. if (1 == $info['isnewuser']) {
  38. $msg .= "-新用户";
  39. $maxnewuser = $this->option['maxnewuser'];
  40. $shareresult = $this->getshareloginfo($info['shareuid']);
  41. if (!$shareresult['status']) {
  42. return $shareresult;
  43. }
  44. $shareinfo = $shareresult['data'];
  45. $userid = $shareinfo['userid'];
  46. $isaddscore = false;
  47. if ($maxnewuser > 0) {
  48. $count = $this->countnewuser($userid);
  49. if ($count < $maxnewuser) {
  50. $isaddscore = true;
  51. }
  52. } else {
  53. $isaddscore = true;
  54. }
  55. if ($isaddscore) {
  56. $adddata = [
  57. 'sourcedemo' => $msg,
  58. 'userid' => $userid,
  59. 'scoretype' => $this->info['scoretype'],
  60. 'addscore' => $this->info['score'],
  61. 'sourcetype' => 2,
  62. ];
  63. $result = $this->adduserscore($adddata);
  64. if (empty($result['status'])) {
  65. return $result;
  66. }
  67. $data = $result['data'];
  68. $uaarid = $data['uaarid'];
  69. $recorddata = [
  70. 'sbid' => $this->info['id'],
  71. 'code' => $this->info['code'],
  72. 'refid' => $uaarid,
  73. 'type' => 1,
  74. ];
  75. $id = $this->newrecord($recorddata);
  76. if (!$id) {
  77. log::error($msg . " 创建关系失败");
  78. }
  79. $returndata = [
  80. 'uaarid' => $uaarid,
  81. 'addscore' => $adddata['addscore'],
  82. ];
  83. }
  84. }
  85. return backarr(1, $msg, $returndata);
  86. }
  87. /**
  88. * 获取新用户数量
  89. * 20220104
  90. * wj
  91. */
  92. /*private function countnewuser()
  93. {
  94. $arr = $this->param;
  95. $m_ual = new userapplylogmodel();
  96. if (!isset($arr['shareuid']) || empty($arr['shareuid']) || !is_numeric($arr['shareuid'])) {
  97. return backarr(0, "请求错误");
  98. }
  99. $where = [
  100. 'isnewuser' => 1,
  101. 'shareuid' => $arr['shareuid'],
  102. 'sharetime' => ['like', '%' . date('Y-m-d') . '%'],
  103. ];
  104. $count = $m_ual->getList($where, 'count');
  105. return $count;
  106. }*/
  107. public function countnewuser($userid)
  108. {
  109. $where = [
  110. 'usl.userid' => $userid,
  111. 'ual.sharetime' => ['like', '%' . date('Y-m-d') . '%'],
  112. 'ual.isnewuser' => 1,
  113. ];
  114. $m_usl = new usersharelogmodel();
  115. $count = $m_usl->getListjoinapply($where, 'count');
  116. $count = empty($count) ? 0 : $count;
  117. return $count;
  118. }
  119. /**
  120. * 获取详细
  121. * 20220104
  122. * wj
  123. */
  124. private function getapplyinfo()
  125. {
  126. $arr = $this->param;
  127. $where = [];
  128. if (isset($arr['shareuid'])) {
  129. $where['shareuid'] = $arr['shareuid'];
  130. }
  131. if (isset($arr['userid'])) {
  132. $where['userid'] = $arr['userid'];
  133. }
  134. if (isset($arr['openid'])) {
  135. $where['shareopenid'] = $arr['openid'];
  136. }
  137. if (isset($arr['applyid'])) {
  138. $where['id'] = $arr['applyid'];
  139. }
  140. $m_ual = new userapplylogmodel();
  141. $info = $m_ual->getInfo($where);
  142. if (empty($info)) {
  143. return false;
  144. }
  145. return $info;
  146. }
  147. /**
  148. * 获取分享详情
  149. * 20220104
  150. * wj
  151. */
  152. private function getshareloginfo($shareuid)
  153. {
  154. //$arr = $this->param;
  155. $m_usl = new usersharelogmodel();
  156. $where = [
  157. 'shareuid' => $shareuid,
  158. ];
  159. $info = $m_usl->getInfo($where);
  160. if (empty($info)) {
  161. return backarr(0, "无分享信息");
  162. }
  163. if (empty($info['userid'])) {
  164. return backarr(0, "无用户id");
  165. }
  166. return backarr(1, "查询成功", $info);
  167. }
  168. }