signinbusinessserver.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\signinmodel;
  10. use app\index\model\userinfomodel;
  11. use app\index\server\scorebusinessserver as BusinessBase;
  12. /**
  13. * 签到
  14. * 20220104
  15. * wj
  16. */
  17. class signinbusinessserver 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. $uinfo = $this->getuserinfo();
  30. $userid = $uinfo['id'];
  31. $issign = $this->issign();
  32. if ($issign) {
  33. return backarr(0, "已签到");
  34. }
  35. $adddata = [
  36. 'sourcedemo' => $msg,
  37. 'userid' => $userid,
  38. 'scoretype' => $this->info['scoretype'],
  39. 'addscore' => $this->info['score'],
  40. 'sourcetype' => 2,
  41. ];
  42. $result = $this->adduserscore($adddata);
  43. if (empty($result['status'])) {
  44. return $result;
  45. }
  46. $data = $result['data'];
  47. $uaarid = $data['uaarid'];
  48. $recorddata = [
  49. 'sbid' => $this->info['id'],
  50. 'code' => $this->info['code'],
  51. 'refid' => $uaarid,
  52. 'type' => 1, //积分增加
  53. ];
  54. $id = $this->newrecord($recorddata);
  55. if (!$id) {
  56. log::error($msg . " 创建关系失败");
  57. }
  58. $returndata = [
  59. 'uaarid' => $uaarid,
  60. 'addscore' => $adddata['addscore'],
  61. ];
  62. return backarr(1, $msg, $returndata);
  63. }
  64. /**
  65. * 是否签到
  66. * 20220105
  67. * wj
  68. */
  69. private function issign()
  70. {
  71. $arr = $this->param;
  72. $m_s = new signinmodel();
  73. $where = [
  74. 'userid' => $arr['userid'],
  75. 'signdate' => date('Y-m-d'),
  76. ];
  77. $count = $m_s->getList($where, 'count');
  78. return 1 < $count ? true : false;
  79. }
  80. /**
  81. * 获取分享详情
  82. * 20220104
  83. * wj
  84. */
  85. private function getuserinfo()
  86. {
  87. $arr = $this->param;
  88. $checkuserinfo = isset($arr['checkuserinfo']) && $arr['checkuserinfo'] ? true : false;
  89. $where = [];
  90. if (isset($arr['userid'])) {
  91. $where['id'] = $arr['userid'];
  92. }
  93. if (isset($arr['openid'])) {
  94. $where['openid'] = $arr['openid'];
  95. }
  96. if (empty($where)) {
  97. throw new Exception("请求数据错误");
  98. }
  99. if ($checkuserinfo) {
  100. $m_u = new userinfomodel();
  101. $info = $m_u->getInfo($where);
  102. if (empty($info)) {
  103. throw new Exception("无用户信息");
  104. }
  105. } else {
  106. $info = $where;
  107. }
  108. return $info;
  109. }
  110. }