SdkQueue.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * SdkQueue.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/30 22:42
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\queue;
  13. use huo\controller\common\Base;
  14. use huo\controller\request\Channel;
  15. use huo\controller\request\Device;
  16. use huo\controller\request\Game;
  17. use huo\controller\request\Mem;
  18. use huolib\queue\constant\ClassConst;
  19. use huolib\queue\constant\JobConst;
  20. use huolib\status\CommonStatus;
  21. use think\Queue;
  22. class SdkQueue extends Base {
  23. protected $param = [];
  24. protected $job_class = '';
  25. protected $job_name = '';
  26. public function __construct($app_id = 0) {
  27. $this->job_class = ClassConst::CLASS_SDK_FIRE;
  28. $this->job_name = JobConst::JOB_SDK;
  29. $this->param['ts'] = time();
  30. $this->setAppId($app_id);
  31. // $this->param['token'] = session_id();
  32. }
  33. public function setAppId($app_id) {
  34. $this->param['app_id'] = $app_id;
  35. }
  36. /**
  37. * 返回数据
  38. *
  39. * @param int $code
  40. * @param array $data
  41. *
  42. * @return array
  43. */
  44. protected function retSucMsg($code = CommonStatus::NO_ERROR, $data = []) {
  45. /* 数据录入LOG */
  46. $this->param['queue'] = '1';
  47. return $this->huoSuccess($code, '', $data);
  48. }
  49. /**
  50. * 返回数据
  51. *
  52. * @param $code
  53. *
  54. * @return array|mixed
  55. */
  56. protected function retErrMsg($code = CommonStatus::PUSH_QUEUE_ERROR) {
  57. /* 数据录入LOG */
  58. $this->param['queue'] = '0';
  59. return $this->huoError($code);
  60. }
  61. /**
  62. * 入队列
  63. *
  64. * @return array
  65. */
  66. protected function pushQueue() {
  67. if (class_exists('think\\Queue')) {
  68. $_is_pushed = Queue::push($this->job_class, $this->param, $this->job_name);
  69. if ($_is_pushed !== false) {
  70. return $this->retErrMsg();
  71. }
  72. }
  73. return $this->retSucMsg();
  74. }
  75. /**
  76. * 设置设备参数
  77. *
  78. * @param Device $device_rq
  79. */
  80. public function setParamDevice(Device $device_rq) {
  81. $_queue_device = new \huolib\queue\request\Device();
  82. $_queue_device->setDeviceId($device_rq->getDeviceId());
  83. $_queue_device->setMac($device_rq->getMac());
  84. $_queue_device->setIp($device_rq->getIp());
  85. $_queue_device->setBrand($device_rq->getBrand());
  86. $_queue_device->setModel($device_rq->getModel());
  87. $_queue_device->setOs($device_rq->getOs());
  88. $_queue_device->setOsVersion($device_rq->getOsVersion());
  89. $_queue_device->setScreen($device_rq->getScreen());
  90. $_queue_device->setNet($device_rq->getNet());
  91. $_queue_device->setImsi($device_rq->getImsi());
  92. $_queue_device->setLongitude($device_rq->getLongitude());
  93. $_queue_device->setLatitude($device_rq->getLatitude());
  94. $_queue_device->setUserua($device_rq->getUserua());
  95. $this->param['device'] = $_queue_device->toArray();
  96. }
  97. /**
  98. * 设置渠道参数
  99. *
  100. * @param Channel $agent_rq
  101. */
  102. public function setParamChannel(Channel $agent_rq) {
  103. $_queue_channel = new \huolib\queue\request\Channel();
  104. $_queue_channel->setCh($agent_rq->getCh());
  105. $_queue_channel->setSubCh($agent_rq->getSubCh());
  106. $this->param['agent'] = $_queue_channel->toArray();
  107. }
  108. /**
  109. * 设置玩家参数
  110. *
  111. * @param Mem $mem_rq
  112. */
  113. public function setParamMem(Mem $mem_rq) {
  114. $_queue_mem = new \huolib\queue\request\Mem();
  115. $_queue_mem->setCreator($mem_rq->getCreator());
  116. $_queue_mem->setMemId($mem_rq->getMemId());
  117. $_queue_mem->setMgMemId($mem_rq->getMgMemId());
  118. $_queue_mem->setRegTime($mem_rq->getRegTime());
  119. $_queue_mem->setLoginTime($mem_rq->getLoginTime());
  120. $_queue_mem->setStatus($mem_rq->getStatus());
  121. $this->param['mem'] = $_queue_mem->toArray();
  122. }
  123. /**
  124. * 设置玩家参数
  125. *
  126. * @param \huo\controller\request\Role $role_rq
  127. */
  128. public function setParamRole(\huo\controller\request\Role $role_rq) {
  129. $_queue_role = new \huolib\queue\request\Role();
  130. $_queue_role->setEvent($role_rq->getEvent());
  131. $_queue_role->setServerId($role_rq->getServerId());
  132. $_queue_role->setServerName($role_rq->getServerName());
  133. $_queue_role->setRoleId($role_rq->getRoleId());
  134. $_queue_role->setRoleName($role_rq->getRoleName());
  135. $_queue_role->setRoleLevel($role_rq->getRoleLevel());
  136. $_queue_role->setCombatNum($role_rq->getCombatNum());
  137. $_queue_role->setLastLoginTime($role_rq->getLastLoginTime());
  138. $this->param['role'] = $_queue_role->toArray();
  139. }
  140. /**
  141. * 设置游戏参数
  142. *
  143. * @param Game $game_rq
  144. */
  145. public function setParamGame(Game $game_rq) {
  146. $_queue_game = new \huolib\queue\request\Game();
  147. $_queue_game->setPkgName($game_rq->getPkgName());
  148. $_queue_game->setAppVer($game_rq->getAppVer());
  149. $_queue_game->setHVer($game_rq->getHVer());
  150. $_queue_game->setSdkVer($game_rq->getSdkVer());
  151. $_queue_game->setHAppId($game_rq->getHAppId());
  152. $this->param['game'] = $_queue_game->toArray();
  153. }
  154. /**
  155. * 设置订单参数
  156. *
  157. * @param \huo\controller\request\Order $order_rq
  158. */
  159. public function setParamOrder(\huo\controller\request\Order $order_rq) {
  160. $_queue_order = new \huolib\queue\request\Order();
  161. $_queue_order->setOrderId($order_rq->getOrderId());
  162. $_queue_order->setPayway($order_rq->getPayway());
  163. $_queue_order->setCurrency($order_rq->getCurrency());
  164. $_queue_order->setCpOrderId($order_rq->getCpOrderId());
  165. $_queue_order->setProductPrice($order_rq->getProductPrice());
  166. $_queue_order->setProductId($order_rq->getProductId());
  167. $_queue_order->setProductCnt($order_rq->getProductCnt());
  168. $_queue_order->setProductName($order_rq->getProductName());
  169. $_queue_order->setProductDesc($order_rq->getProductDesc());
  170. $_queue_order->setStatus($order_rq->getStatus());
  171. $this->param['order'] = $_queue_order->toArray();
  172. }
  173. /**
  174. * @return array
  175. */
  176. public function getParam() {
  177. return $this->param;
  178. }
  179. /**
  180. * @param array $param
  181. */
  182. public function setParam($param) {
  183. $this->param = $param;
  184. }
  185. /**
  186. * @return string
  187. */
  188. public function getJobClass() {
  189. return $this->job_class;
  190. }
  191. /**
  192. * @param string $job_class
  193. */
  194. public function setJobClass($job_class) {
  195. $this->job_class = $job_class;
  196. }
  197. /**
  198. * @return string
  199. */
  200. public function getJobName() {
  201. return $this->job_name;
  202. }
  203. /**
  204. * @param string $job_name
  205. */
  206. public function setJobName($job_name) {
  207. $this->job_name = $job_name;
  208. }
  209. }