123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- <?php
- /**
- * DayMem.php UTF-8
- *
- *
- * @date : 2018/5/31 20:24
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\data;
- use huo\controller\member\MemCache;
- use huo\controller\pay\SdkOrderCache;
- use huo\model\log\DayMemLogModel;
- use huo\model\log\DmlSwitchModel;
- use huo\model\member\MgRoleModel;
- use huolib\constant\MemConst;
- use huolib\constant\OrderConst;
- use huolib\queue\request\Channel;
- use huolib\queue\request\Common;
- use huolib\queue\request\Device;
- use huolib\queue\request\Game;
- use huolib\queue\request\Mem as MemRq;
- use huolib\queue\request\Order as OrderRq;
- use huolib\queue\request\Role as RoleRq;
- use huolib\tool\Ip;
- use huolib\tool\Time;
- class DayMem {
- protected $date = '';/* 日期 */
- protected $mem_id = 0; /* 玩家ID */
- protected $agent_id = 0; /* 归属渠道 */
- protected $app_id = 0; /* 游戏ID */
- protected $reg_time = 0; /* 玩家注册时间 */
- protected $reg_days = 0; /* 注册天数 */
- protected $role_days = 0; /* 创角天数 */
- protected $device_id = ''; /* 手机设备码 */
- protected $device_cnt = 0; /* 登陆设备数量 */
- protected $login_cnt = 0; /* 登陆次数 */
- protected $sum_login_cnt = 0; /* 当日总登陆次数 */
- protected $sum_money = 0.00; /* 累计充值 */
- protected $first_pay_time = 0; /* 第一笔充值时间 */
- protected $last_pay_time = 0; /* 最近充值时间 */
- protected $last_money = 0.00; /* 最近充值金额 */
- protected $order_cnt = 0; /* 订单数量 */
- protected $order_suc_cnt = 0; /* 支付成功订单数量 */
- protected $last_login_ip = ''; /* 玩家最近登陆ip */
- protected $is_login = 0;/* 1 表示登陆 2 表示注册 0 其他 */
- protected $is_new = 0;/* 1 表示新增 0 表示非新增 */
- protected $auth_cnt = 0;/* 授权登陆次数 */
- /**
- * 转数组
- *
- * @return mixed
- */
- public function toArray() {
- $_data['date'] = $this->getDate();
- $_data['mem_id'] = $this->getMemId();
- $_data['agent_id'] = $this->getAgentId();
- $_data['app_id'] = $this->getAppId();
- $_data['reg_time'] = $this->getRegTime();
- $_data['reg_days'] = $this->getRegDays();
- $_data['role_days'] = $this->getRoleDays();
- $_data['device_id'] = $this->getDeviceId();
- $_data['device_cnt'] = $this->getDeviceCnt();
- $_data['login_cnt'] = $this->getLoginCnt();
- $_data['sum_money'] = $this->getSumMoney();
- $_data['first_pay_time'] = $this->getFirstPayTime();
- $_data['last_pay_time'] = $this->getLastPayTime();
- $_data['last_money'] = $this->getLastMoney();
- $_data['order_cnt'] = $this->getOrderCnt();
- $_data['order_suc_cnt'] = $this->getOrderSucCnt();
- $_data['last_login_ip'] = $this->getLastLoginIp();
- $_data['auth_cnt'] = $this->getAuthCnt();
- return $_data;
- }
- /**
- * 更新每日玩家
- *
- * @param Common $com_rq
- * @param Device $device_rq
- * @param Game $game_rq
- * @param Channel $agent_rq
- * @param MemRq $mem_rq
- * @param RoleRq $role_rq
- * @param OrderRq $order_rq
- *
- * @return bool|int|string
- */
- public function updateDayMem(
- Common $com_rq,
- Device $device_rq,
- Game $game_rq,
- Channel $agent_rq,
- MemRq $mem_rq,
- RoleRq $role_rq,
- OrderRq $order_rq
- ) {
- $_order_id = $order_rq->getOrderId();
- $_is_switch = OrderConst::PAY_SWITCH_NO; //默认不切换
- $_mem_data = MemCache::ins()->getInfoById($mem_rq->getMemId());
- if (!empty($_mem_data) && OrderConst::PAY_SWITCH_YES == $_mem_data['is_switch']) {
- $_is_switch = OrderConst::PAY_SWITCH_YES;
- } elseif (!empty($_order_id)) {
- $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_id);
- if (!empty($_order_data) && OrderConst::PAY_SWITCH_YES == $_order_data['is_switch']) {
- $_is_switch = OrderConst::PAY_SWITCH_YES;
- }
- }
- $_model = new DayMemLogModel();
- $_map['date'] = date('Y-m-d', $com_rq->getTs());
- $_map['mem_id'] = $mem_rq->getMemId();
- /* 计算今日登陆次数 */
- $_sum_login_cnt = $_model->getSumLoginCnt($_map);
- $_map['app_id'] = $com_rq->getAppId();
- $_data = $_model->getDetail($_map);
- if (empty($_data)) {
- $this->setIsNew(1);
- $this->setDate($_map['date']);
- $this->setMemId($_map['mem_id']);
- $this->setAppId($_map['app_id']);
- $this->setAgentId($agent_rq->getCh());
- $this->setRegTime($mem_rq->getRegTime());
- $_days = Time::timeDateDiff($mem_rq->getRegTime(), $mem_rq->getLoginTime());
- $this->setRegDays($_days);
- $_role_days = (new MgRoleModel())->getRoleDays($mem_rq->getMgMemId());
- $this->setRoleDays($_role_days);
- $this->setDeviceId($device_rq->getDeviceId());
- $_device_id = $device_rq->getDeviceId();
- if (!empty($_device_id)) {
- $this->setDeviceCnt(1);
- }
- if (MemConst::STATUS_NORMAL == $mem_rq->getStatus()) {
- /* 状态未2 表示已授权 */
- $this->setAuthCnt(1);
- }
- $this->setLoginCnt(1);
- $this->setSumLoginCnt($_sum_login_cnt + 1);
- $this->setSumMoney($order_rq->getProductPrice());
- $this->setFirstPayTime($order_rq->getPayTime());
- $this->setLastPayTime($order_rq->getPayTime());
- $this->setLastMoney($order_rq->getProductPrice());
- if (!empty($_order_id)) {
- $this->setOrderCnt(1);
- if (OrderConst::PAY_STATUS_SUC == $order_rq->getStatus()) {
- $this->setOrderSucCnt(1);
- }
- }
- $this->setLastLoginIp($device_rq->getIp());
- if (OrderConst::PAY_SWITCH_YES == $_is_switch) {
- $_rs = (new DmlSwitchModel())->insertLog($this->toArray());
- }
- $_rs = $_model->insertLog($this->toArray());
- return $_rs;
- } else {
- $this->setDataFromDayMem($_data);
- if ($device_rq->getDeviceId() && $device_rq->getDeviceId() != $this->getDeviceId()) {
- $this->setDeviceId($device_rq->getDeviceId());
- $_device_id = $device_rq->getDeviceId();
- if (!empty($_device_id)) {
- $this->setDeviceCnt($this->getDeviceCnt() + 1);
- }
- }
- if ($this->getIsLogin()) {
- $this->setLoginCnt($this->getLoginCnt() + 1);
- if (MemConst::STATUS_NORMAL == $mem_rq->getStatus()) {
- /* 状态未2 表示已授权 */
- $this->setAuthCnt($this->getAuthCnt() + 1);
- }
- $this->setSumLoginCnt($_sum_login_cnt + 1);
- $this->setLastLoginIp($device_rq->getIp());
- }
- $_money = $order_rq->getProductPrice();
- if (!empty($_money)) {
- $this->setOrderCnt($this->getOrderCnt() + 1);
- $_sum_money = $this->getSumMoney();
- if (!empty($_sum_money)) {
- $this->setFirstPayTime($order_rq->getPayTime());
- }
- if (OrderConst::PAY_STATUS_SUC == $order_rq->getStatus()) {
- $this->setSumMoney($_sum_money + $order_rq->getProductPrice());
- $this->setLastPayTime($order_rq->getPayTime());
- $this->setLastMoney($order_rq->getProductPrice());
- $this->setOrderSucCnt($this->getOrderSucCnt() + 1);
- }
- }
- $_role_days = (new MgRoleModel())->getRoleDays($mem_rq->getMgMemId());
- if (!empty($_role_days) && $_role_days != $this->getRoleDays()) {
- $this->setRoleDays($_role_days);
- }
- if (OrderConst::PAY_SWITCH_YES == $_is_switch) {
- (new DmlSwitchModel())->updateLog($this->toArray(), $_data['id']);
- }
- return $_model->updateLog($this->toArray(), $_data['id']);
- }
- }
- /**
- * 从Day_mem设置数据
- *
- * @param $data
- */
- public function setDataFromDayMem($data) {
- if (empty($data)) {
- return;
- }
- $this->setDate($data['date']);
- $this->setMemId($data['mem_id']);
- $this->setAppId($data['app_id']);
- $this->setAgentId($data['agent_id']);
- $this->setRegTime($data['reg_time']);
- $this->setRegDays($data['reg_days']);
- $this->setDeviceId($data['device_id']);
- $this->setDeviceCnt($data['device_cnt']);
- $this->setLoginCnt($data['login_cnt']);
- $this->setSumMoney($data['sum_money']);
- $this->setFirstPayTime($data['first_pay_time']);
- $this->setLastPayTime($data['last_pay_time']);
- $this->setLastMoney($data['last_money']);
- $this->setOrderCnt($data['order_cnt']);
- $this->setOrderSucCnt($data['order_suc_cnt']);
- $this->setLastLoginIp($data['last_login_ip']);
- $this->setAuthCnt($data['auth_cnt']);
- }
- /**
- * @return string
- */
- public function getDate() {
- return $this->date;
- }
- /**
- * @param string $date
- */
- public function setDate($date) {
- $this->date = $date;
- }
- /**
- * @return int
- */
- public function getMemId() {
- return $this->mem_id;
- }
- /**
- * @param int $mem_id
- */
- public function setMemId($mem_id) {
- $this->mem_id = $mem_id;
- }
- /**
- * @return int
- */
- public function getAgentId() {
- return $this->agent_id;
- }
- /**
- * @param int $agent_id
- */
- public function setAgentId($agent_id) {
- $this->agent_id = $agent_id;
- }
- /**
- * @return int
- */
- public function getAppId() {
- return $this->app_id;
- }
- /**
- * @param int $app_id
- */
- public function setAppId($app_id) {
- $this->app_id = $app_id;
- }
- /**
- * @return int
- */
- public function getRegTime() {
- return $this->reg_time;
- }
- /**
- * @param int $reg_time
- */
- public function setRegTime($reg_time) {
- $this->reg_time = $reg_time;
- }
- /**
- * @return int
- */
- public function getRegDays() {
- return $this->reg_days;
- }
- /**
- * @param int $reg_days
- */
- public function setRegDays($reg_days) {
- $this->reg_days = $reg_days;
- }
- /**
- * @return int
- */
- public function getRoleDays() {
- return $this->role_days;
- }
- /**
- * @param int $role_days
- */
- public function setRoleDays($role_days) {
- $this->role_days = $role_days;
- }
- /**
- * @return string
- */
- public function getDeviceId() {
- return $this->device_id;
- }
- /**
- * @param string $device_id
- */
- public function setDeviceId($device_id) {
- $this->device_id = $device_id;
- }
- /**
- * @return int
- */
- public function getLoginCnt() {
- return $this->login_cnt;
- }
- /**
- * @param int $login_cnt
- */
- public function setLoginCnt($login_cnt) {
- $this->login_cnt = $login_cnt;
- }
- /**
- * @return float
- */
- public function getSumMoney() {
- return $this->sum_money;
- }
- /**
- * @param float $sum_money
- */
- public function setSumMoney($sum_money) {
- $this->sum_money = $sum_money;
- }
- /**
- * @return int
- */
- public function getFirstPayTime() {
- return $this->first_pay_time;
- }
- /**
- * @param int $first_pay_time
- */
- public function setFirstPayTime($first_pay_time) {
- $this->first_pay_time = $first_pay_time;
- }
- /**
- * @return int
- */
- public function getLastPayTime() {
- return $this->last_pay_time;
- }
- /**
- * @param int $last_pay_time
- */
- public function setLastPayTime($last_pay_time) {
- $this->last_pay_time = $last_pay_time;
- }
- /**
- * @return float
- */
- public function getLastMoney() {
- return $this->last_money;
- }
- /**
- * @param float $last_money
- */
- public function setLastMoney($last_money) {
- $this->last_money = $last_money;
- }
- /**
- * @return int
- */
- public function getOrderCnt() {
- return $this->order_cnt;
- }
- /**
- * @param int $order_cnt
- */
- public function setOrderCnt($order_cnt) {
- $this->order_cnt = $order_cnt;
- }
- /**
- * @return int
- */
- public function getOrderSucCnt() {
- return $this->order_suc_cnt;
- }
- /**
- * @param int $order_suc_cnt
- */
- public function setOrderSucCnt($order_suc_cnt) {
- $this->order_suc_cnt = $order_suc_cnt;
- }
- /**
- * @return string
- */
- public function getLastLoginIp() {
- return $this->last_login_ip;
- }
- /**
- * @param string $last_login_ip
- */
- public function setLastLoginIp($last_login_ip) {
- if (false == is_integer($last_login_ip)) {
- $last_login_ip = Ip::ipToLong($last_login_ip);
- }
- $this->last_login_ip = $last_login_ip;
- }
- /**
- * @return int
- */
- public function getDeviceCnt() {
- return $this->device_cnt;
- }
- /**
- * @param int $device_cnt
- */
- public function setDeviceCnt($device_cnt) {
- $this->device_cnt = $device_cnt;
- }
- /**
- * @param int $is_login
- */
- public function setIsLogin($is_login) {
- $this->is_login = $is_login;
- }
- /**
- * @return int
- */
- public function getIsLogin() {
- return $this->is_login;
- }
- /**
- * @return int
- */
- public function getSumLoginCnt() {
- return $this->sum_login_cnt;
- }
- /**
- * @param int $sum_login_cnt
- */
- public function setSumLoginCnt($sum_login_cnt) {
- $this->sum_login_cnt = $sum_login_cnt;
- }
- /**
- * @return int
- */
- public function getIsNew() {
- return $this->is_new;
- }
- /**
- * @param int $is_new
- */
- public function setIsNew($is_new) {
- $this->is_new = $is_new;
- }
- /**
- * @return int
- */
- public function getAuthCnt() {
- return $this->auth_cnt;
- }
- /**
- * @param int $auth_cnt
- */
- public function setAuthCnt($auth_cnt) {
- $this->auth_cnt = $auth_cnt;
- }
- }
|