factory_client.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/12/14
  6. * Time: 上午11:43
  7. */
  8. namespace room;
  9. use search\tcp_client;
  10. class factory_client extends tcp_client
  11. {
  12. protected static $stInstance;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->mBodyType = tcp_client::JsonType;
  17. }
  18. public static function instance()
  19. {
  20. if(self::$stInstance == null) {
  21. self::$stInstance = new factory_client();
  22. }
  23. return self::$stInstance;
  24. }
  25. public function __destruct()
  26. {
  27. parent::__destruct();
  28. }
  29. public function remote_addr()
  30. {
  31. global $config;
  32. $host = $config['room_factory']['host'];
  33. $port = $config['room_factory']['port'];
  34. return "{$host}:{$port}";
  35. }
  36. public function create_bargain($goods_id,$user,$lowest_price,$usable_days,$random = true,$total_num = 10)
  37. {
  38. $random = $random ? 1 : 0;
  39. $param = ["act" => 'factory','op' => 'create', "type" => 'bargain_goods','creator' => $user,'goods_id' => $goods_id,
  40. 'lowest_price' => $lowest_price,'usable_days' => $usable_days,'random' => $random,'total_num' => $total_num];
  41. $result = $this->request($param);
  42. if(empty($result)) return false;
  43. $code = intval($result['code']);
  44. if($code != 200) {
  45. return false;
  46. }
  47. else {
  48. return $result['data'];
  49. }
  50. }
  51. public function create_chat($creator,$user)
  52. {
  53. $param = ["act" => 'factory','op' => 'create', "type" => 'chat','creator' => $creator,'user' => $user];
  54. $result = $this->request($param);
  55. if(empty($result)) return false;
  56. $code = intval($result['code']);
  57. if($code != 200) {
  58. return false;
  59. }
  60. else {
  61. return $result['data'];
  62. }
  63. }
  64. public function create_group($creator)
  65. {
  66. $param = ["act" => 'factory','op' => 'create', "type" => 'group','creator' => $creator];
  67. $result = $this->request($param);
  68. if(empty($result)) return false;
  69. $code = intval($result['code']);
  70. if($code != 200) {
  71. return false;
  72. }
  73. else {
  74. return $result['data'];
  75. }
  76. }
  77. public function create_shake($creator)
  78. {
  79. $param = ["act" => 'factory','op' => 'create', "type" => 'shake_bonus','creator' => $creator];
  80. $result = $this->request($param);
  81. if(empty($result)) return false;
  82. $code = intval($result['code']);
  83. if($code != 200) {
  84. return false;
  85. }
  86. else {
  87. return $result['data'];
  88. }
  89. }
  90. public function invite($roomid,$user)
  91. {
  92. $param = ["act" => 'factory','op' => 'invite','room' => $roomid,'user' => $user];
  93. $result = $this->request($param);
  94. if(empty($result)) return false;
  95. $code = intval($result['code']);
  96. if($code != 200) {
  97. return false;
  98. }
  99. else {
  100. return $result['data'];
  101. }
  102. }
  103. }