123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- /**
- * SdkQueue.php UTF-8
- *
- *
- * @date : 2018/5/30 22:42
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\queue;
- use huo\controller\common\Base;
- use huo\controller\request\Channel;
- use huo\controller\request\Device;
- use huo\controller\request\Game;
- use huo\controller\request\Mem;
- use huolib\queue\constant\ClassConst;
- use huolib\queue\constant\JobConst;
- use huolib\status\CommonStatus;
- use think\Queue;
- class SdkQueue extends Base {
- protected $param = [];
- protected $job_class = '';
- protected $job_name = '';
- public function __construct($app_id = 0) {
- $this->job_class = ClassConst::CLASS_SDK_FIRE;
- $this->job_name = JobConst::JOB_SDK;
- $this->param['ts'] = time();
- $this->setAppId($app_id);
- // $this->param['token'] = session_id();
- }
- public function setAppId($app_id) {
- $this->param['app_id'] = $app_id;
- }
- /**
- * 返回数据
- *
- * @param int $code
- * @param array $data
- *
- * @return array
- */
- protected function retSucMsg($code = CommonStatus::NO_ERROR, $data = []) {
- /* 数据录入LOG */
- $this->param['queue'] = '1';
- return $this->huoSuccess($code, '', $data);
- }
- /**
- * 返回数据
- *
- * @param $code
- *
- * @return array|mixed
- */
- protected function retErrMsg($code = CommonStatus::PUSH_QUEUE_ERROR) {
- /* 数据录入LOG */
- $this->param['queue'] = '0';
- return $this->huoError($code);
- }
- /**
- * 入队列
- *
- * @return array
- */
- protected function pushQueue() {
- if (class_exists('think\\Queue')) {
- $_is_pushed = Queue::push($this->job_class, $this->param, $this->job_name);
- if ($_is_pushed !== false) {
- return $this->retErrMsg();
- }
- }
- return $this->retSucMsg();
- }
- /**
- * 设置设备参数
- *
- * @param Device $device_rq
- */
- public function setParamDevice(Device $device_rq) {
- $_queue_device = new \huolib\queue\request\Device();
- $_queue_device->setDeviceId($device_rq->getDeviceId());
- $_queue_device->setMac($device_rq->getMac());
- $_queue_device->setIp($device_rq->getIp());
- $_queue_device->setBrand($device_rq->getBrand());
- $_queue_device->setModel($device_rq->getModel());
- $_queue_device->setOs($device_rq->getOs());
- $_queue_device->setOsVersion($device_rq->getOsVersion());
- $_queue_device->setScreen($device_rq->getScreen());
- $_queue_device->setNet($device_rq->getNet());
- $_queue_device->setImsi($device_rq->getImsi());
- $_queue_device->setLongitude($device_rq->getLongitude());
- $_queue_device->setLatitude($device_rq->getLatitude());
- $_queue_device->setUserua($device_rq->getUserua());
- $this->param['device'] = $_queue_device->toArray();
- }
- /**
- * 设置渠道参数
- *
- * @param Channel $agent_rq
- */
- public function setParamChannel(Channel $agent_rq) {
- $_queue_channel = new \huolib\queue\request\Channel();
- $_queue_channel->setCh($agent_rq->getCh());
- $_queue_channel->setSubCh($agent_rq->getSubCh());
- $this->param['agent'] = $_queue_channel->toArray();
- }
- /**
- * 设置玩家参数
- *
- * @param Mem $mem_rq
- */
- public function setParamMem(Mem $mem_rq) {
- $_queue_mem = new \huolib\queue\request\Mem();
- $_queue_mem->setCreator($mem_rq->getCreator());
- $_queue_mem->setMemId($mem_rq->getMemId());
- $_queue_mem->setMgMemId($mem_rq->getMgMemId());
- $_queue_mem->setRegTime($mem_rq->getRegTime());
- $_queue_mem->setLoginTime($mem_rq->getLoginTime());
- $_queue_mem->setStatus($mem_rq->getStatus());
- $this->param['mem'] = $_queue_mem->toArray();
- }
- /**
- * 设置玩家参数
- *
- * @param \huo\controller\request\Role $role_rq
- */
- public function setParamRole(\huo\controller\request\Role $role_rq) {
- $_queue_role = new \huolib\queue\request\Role();
- $_queue_role->setEvent($role_rq->getEvent());
- $_queue_role->setServerId($role_rq->getServerId());
- $_queue_role->setServerName($role_rq->getServerName());
- $_queue_role->setRoleId($role_rq->getRoleId());
- $_queue_role->setRoleName($role_rq->getRoleName());
- $_queue_role->setRoleLevel($role_rq->getRoleLevel());
- $_queue_role->setCombatNum($role_rq->getCombatNum());
- $_queue_role->setLastLoginTime($role_rq->getLastLoginTime());
- $this->param['role'] = $_queue_role->toArray();
- }
- /**
- * 设置游戏参数
- *
- * @param Game $game_rq
- */
- public function setParamGame(Game $game_rq) {
- $_queue_game = new \huolib\queue\request\Game();
- $_queue_game->setPkgName($game_rq->getPkgName());
- $_queue_game->setAppVer($game_rq->getAppVer());
- $_queue_game->setHVer($game_rq->getHVer());
- $_queue_game->setSdkVer($game_rq->getSdkVer());
- $_queue_game->setHAppId($game_rq->getHAppId());
- $this->param['game'] = $_queue_game->toArray();
- }
- /**
- * 设置订单参数
- *
- * @param \huo\controller\request\Order $order_rq
- */
- public function setParamOrder(\huo\controller\request\Order $order_rq) {
- $_queue_order = new \huolib\queue\request\Order();
- $_queue_order->setOrderId($order_rq->getOrderId());
- $_queue_order->setPayway($order_rq->getPayway());
- $_queue_order->setCurrency($order_rq->getCurrency());
- $_queue_order->setCpOrderId($order_rq->getCpOrderId());
- $_queue_order->setProductPrice($order_rq->getProductPrice());
- $_queue_order->setProductId($order_rq->getProductId());
- $_queue_order->setProductCnt($order_rq->getProductCnt());
- $_queue_order->setProductName($order_rq->getProductName());
- $_queue_order->setProductDesc($order_rq->getProductDesc());
- $_queue_order->setStatus($order_rq->getStatus());
- $this->param['order'] = $_queue_order->toArray();
- }
- /**
- * @return array
- */
- public function getParam() {
- return $this->param;
- }
- /**
- * @param array $param
- */
- public function setParam($param) {
- $this->param = $param;
- }
- /**
- * @return string
- */
- public function getJobClass() {
- return $this->job_class;
- }
- /**
- * @param string $job_class
- */
- public function setJobClass($job_class) {
- $this->job_class = $job_class;
- }
- /**
- * @return string
- */
- public function getJobName() {
- return $this->job_name;
- }
- /**
- * @param string $job_name
- */
- public function setJobName($job_name) {
- $this->job_name = $job_name;
- }
- }
|