ShareActLogic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * ShareActLogic.php UTF-8
  4. * 分享活动逻辑类
  5. *
  6. * @date : 2018/5/26 16:06
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\posts;
  13. use huo\controller\request\Channel;
  14. use huo\controller\request\Device;
  15. use huo\controller\request\Game;
  16. use huo\controller\request\Mem;
  17. use huo\model\common\CommonModel;
  18. use huo\model\member\MemActivityModel;
  19. use huo\model\posts\ShareLogModel;
  20. use huolib\constant\ShareConst;
  21. use huolib\status\CommonStatus;
  22. class ShareActLogic extends CommonModel {
  23. public function __construct() {
  24. parent::__construct();
  25. }
  26. /**
  27. * 重置分享活动的抽奖次数
  28. *
  29. * @param $mem_id
  30. * @param $act_id
  31. *
  32. * @param int $free_cnt
  33. *
  34. * @return bool|int
  35. */
  36. public function resetLotteryCnt($mem_id, $act_id, $free_cnt = 0) {
  37. $_mem_act_model = $this->getMemActModel($mem_id, $act_id);
  38. $_today_start_time = strtotime(date('Y-m-d'));
  39. /** @var MemActivityModel $_mem_act_model */
  40. if (isset($_mem_act_model->update_time) && $_mem_act_model->update_time < $_today_start_time) {
  41. $_update_data = [
  42. 'today_cnt' => 0,
  43. 'free_cnt' => $free_cnt,
  44. 'update_time' => time(),
  45. ];
  46. if (false === $_mem_act_model->updateMemAct($_update_data, $_mem_act_model->id)) {
  47. return CommonStatus::INNER_ERROR;
  48. }
  49. }
  50. return true;
  51. }
  52. /**
  53. * 增加玩家在活动中的每日抽奖次数和总抽奖次数
  54. *
  55. * @param $mem_id
  56. * @param $act_id
  57. * @param int $count
  58. *
  59. * @return bool
  60. */
  61. public function incrLotteryCnt($mem_id, $act_id, $count = ShareConst::DEFAULT_SHARE_INCR_COUNT) {
  62. /** @var MemActivityModel $_mem_act_model */
  63. $_mem_act_model = $this->getMemActModel($mem_id, $act_id);
  64. $_old_todal_cnt = isset($_mem_act_model->total_cnt) ? $_mem_act_model->total_cnt : 0;
  65. $_old_today_cnt = isset($_mem_act_model->today_cnt) ? $_mem_act_model->today_cnt : 0;
  66. $_data['total_cnt'] = $_old_todal_cnt + $count;
  67. $_data['today_cnt'] = $_old_today_cnt + $count;
  68. return $_mem_act_model->updateMemAct($_data, $_mem_act_model->id);
  69. }
  70. /**
  71. * 获取MemActivityModel,不存在则创建
  72. *
  73. * @param $mem_id
  74. * @param $act_id
  75. *
  76. * @return bool|mixed
  77. */
  78. public function getMemActModel($mem_id, $act_id) {
  79. $_mem_act_model = new MemActivityModel();
  80. $_mem_act = $_mem_act_model->getMemActModel($mem_id, $act_id);
  81. if (empty($_mem_act)) {
  82. $_add_data = [
  83. 'mem_id' => $mem_id,
  84. 'act_id' => $act_id,
  85. 'free_cnt' => ShareConst::DEFAULT_LOTTERY_FREE_COUNT,
  86. ];
  87. $_mem_act_id = $_mem_act_model->addMemAct($_add_data);
  88. return $_mem_act_model->getInfoById($_mem_act_id);
  89. }
  90. return $_mem_act;
  91. }
  92. /**
  93. * 插入分享log
  94. *
  95. * @param Game $game_rq
  96. * @param Channel $channel
  97. * @param Device $device
  98. * @param Mem $member
  99. * @param $_share_data
  100. *
  101. * @return bool|mixed
  102. */
  103. public function insertShareLog(Game $game_rq, Channel $channel, Device $device, Mem $member, $_share_data) {
  104. $_data = $device->toArray();
  105. $_data['mem_id'] = $member->getMemId();
  106. $_data['create_time'] = time();
  107. $_data['title'] = isset($_share_data['title']) ? $_share_data['title'] : '';
  108. $_data['content'] = isset($_share_data['content']) ? $_share_data['content'] : '';
  109. $_data['url'] = isset($_share_data['url']) ? $_share_data['url'] : '';
  110. $_data['to_target'] = isset($_share_data['to_target']) ? $_share_data['to_target'] : '';
  111. $_data['table_name'] = isset($_share_data['table_name']) ? $_share_data['table_name'] : '';
  112. $_data['object_id'] = isset($_share_data['object_id']) ? $_share_data['object_id'] : '';
  113. return (new ShareLogModel())->insertLog($_data);
  114. }
  115. /**
  116. * 更新memAct
  117. *
  118. * @param $mem_act_id mem_act_id
  119. * @param $_mem_act_data 要更新的数组
  120. *
  121. * @return bool
  122. */
  123. public function updateMemAct($mem_act_id, $_mem_act_data) {
  124. $_mem_act_model = new MemActivityModel();
  125. $_old_data = $_mem_act_model->getMemActById($mem_act_id);
  126. $_data = array_merge($_old_data, $_mem_act_data);
  127. $_rs = $_mem_act_model->updateMemAct($_data, $mem_act_id);
  128. return $_rs;
  129. }
  130. }