shake_room.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/12/23
  6. * Time: 下午3:35
  7. */
  8. namespace room;
  9. use Log;
  10. class shake_room extends base_room
  11. {
  12. public function __construct($cinfos, array $participants = [])
  13. {
  14. $this->mRoomType = 'shake_bonus';
  15. parent::__construct($cinfos, $participants);
  16. }
  17. public function shakeOp($input)
  18. {
  19. $this->clear();
  20. $user = $input['user'];
  21. $userinfo = $this->find($user);
  22. if($userinfo == false) {
  23. return false;
  24. }
  25. if(!isset($input['amount'])) return false;
  26. if($input['amount'] > 0) {
  27. $amount = intval($input['amount'] * 100 + 0.5);
  28. } else {
  29. $amount = intval($input['amount'] * 100 - 0.5);
  30. }
  31. if($amount === 0) return false;
  32. Log::record("amount = {$amount}",Log::DEBUG);
  33. $type = proto_type::msg_type_shakebonus;
  34. $content = $amount / 100;
  35. $msgid = $this->record_message($userinfo['userid'],$type,$content);
  36. if($msgid > 0) {
  37. $this->relay_broadcast('shake',['msgid' => $msgid, 'from' => $userinfo,'content' => "{$content}",'send_time' => time(),'seq' => $input['seq']]);
  38. return ['act' => 'room','op' => 'shake','room' => $this->room_id()];
  39. }
  40. else {
  41. return false;
  42. }
  43. }
  44. }