DayMem.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <?php
  2. /**
  3. * DayMem.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/31 20:24
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\data;
  13. use huo\controller\member\MemCache;
  14. use huo\controller\pay\SdkOrderCache;
  15. use huo\model\log\DayMemLogModel;
  16. use huo\model\log\DmlSwitchModel;
  17. use huo\model\member\MgRoleModel;
  18. use huolib\constant\MemConst;
  19. use huolib\constant\OrderConst;
  20. use huolib\queue\request\Channel;
  21. use huolib\queue\request\Common;
  22. use huolib\queue\request\Device;
  23. use huolib\queue\request\Game;
  24. use huolib\queue\request\Mem as MemRq;
  25. use huolib\queue\request\Order as OrderRq;
  26. use huolib\queue\request\Role as RoleRq;
  27. use huolib\tool\Ip;
  28. use huolib\tool\Time;
  29. class DayMem {
  30. protected $date = '';/* 日期 */
  31. protected $mem_id = 0; /* 玩家ID */
  32. protected $agent_id = 0; /* 归属渠道 */
  33. protected $app_id = 0; /* 游戏ID */
  34. protected $reg_time = 0; /* 玩家注册时间 */
  35. protected $reg_days = 0; /* 注册天数 */
  36. protected $role_days = 0; /* 创角天数 */
  37. protected $device_id = ''; /* 手机设备码 */
  38. protected $device_cnt = 0; /* 登陆设备数量 */
  39. protected $login_cnt = 0; /* 登陆次数 */
  40. protected $sum_login_cnt = 0; /* 当日总登陆次数 */
  41. protected $sum_money = 0.00; /* 累计充值 */
  42. protected $first_pay_time = 0; /* 第一笔充值时间 */
  43. protected $last_pay_time = 0; /* 最近充值时间 */
  44. protected $last_money = 0.00; /* 最近充值金额 */
  45. protected $order_cnt = 0; /* 订单数量 */
  46. protected $order_suc_cnt = 0; /* 支付成功订单数量 */
  47. protected $last_login_ip = ''; /* 玩家最近登陆ip */
  48. protected $is_login = 0;/* 1 表示登陆 2 表示注册 0 其他 */
  49. protected $is_new = 0;/* 1 表示新增 0 表示非新增 */
  50. protected $auth_cnt = 0;/* 授权登陆次数 */
  51. /**
  52. * 转数组
  53. *
  54. * @return mixed
  55. */
  56. public function toArray() {
  57. $_data['date'] = $this->getDate();
  58. $_data['mem_id'] = $this->getMemId();
  59. $_data['agent_id'] = $this->getAgentId();
  60. $_data['app_id'] = $this->getAppId();
  61. $_data['reg_time'] = $this->getRegTime();
  62. $_data['reg_days'] = $this->getRegDays();
  63. $_data['role_days'] = $this->getRoleDays();
  64. $_data['device_id'] = $this->getDeviceId();
  65. $_data['device_cnt'] = $this->getDeviceCnt();
  66. $_data['login_cnt'] = $this->getLoginCnt();
  67. $_data['sum_money'] = $this->getSumMoney();
  68. $_data['first_pay_time'] = $this->getFirstPayTime();
  69. $_data['last_pay_time'] = $this->getLastPayTime();
  70. $_data['last_money'] = $this->getLastMoney();
  71. $_data['order_cnt'] = $this->getOrderCnt();
  72. $_data['order_suc_cnt'] = $this->getOrderSucCnt();
  73. $_data['last_login_ip'] = $this->getLastLoginIp();
  74. $_data['auth_cnt'] = $this->getAuthCnt();
  75. return $_data;
  76. }
  77. /**
  78. * 更新每日玩家
  79. *
  80. * @param Common $com_rq
  81. * @param Device $device_rq
  82. * @param Game $game_rq
  83. * @param Channel $agent_rq
  84. * @param MemRq $mem_rq
  85. * @param RoleRq $role_rq
  86. * @param OrderRq $order_rq
  87. *
  88. * @return bool|int|string
  89. */
  90. public function updateDayMem(
  91. Common $com_rq,
  92. Device $device_rq,
  93. Game $game_rq,
  94. Channel $agent_rq,
  95. MemRq $mem_rq,
  96. RoleRq $role_rq,
  97. OrderRq $order_rq
  98. ) {
  99. $_order_id = $order_rq->getOrderId();
  100. $_is_switch = OrderConst::PAY_SWITCH_NO; //默认不切换
  101. $_mem_data = MemCache::ins()->getInfoById($mem_rq->getMemId());
  102. if (!empty($_mem_data) && OrderConst::PAY_SWITCH_YES == $_mem_data['is_switch']) {
  103. $_is_switch = OrderConst::PAY_SWITCH_YES;
  104. } elseif (!empty($_order_id)) {
  105. $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_id);
  106. if (!empty($_order_data) && OrderConst::PAY_SWITCH_YES == $_order_data['is_switch']) {
  107. $_is_switch = OrderConst::PAY_SWITCH_YES;
  108. }
  109. }
  110. $_model = new DayMemLogModel();
  111. $_map['date'] = date('Y-m-d', $com_rq->getTs());
  112. $_map['mem_id'] = $mem_rq->getMemId();
  113. /* 计算今日登陆次数 */
  114. $_sum_login_cnt = $_model->getSumLoginCnt($_map);
  115. $_map['app_id'] = $com_rq->getAppId();
  116. $_data = $_model->getDetail($_map);
  117. if (empty($_data)) {
  118. $this->setIsNew(1);
  119. $this->setDate($_map['date']);
  120. $this->setMemId($_map['mem_id']);
  121. $this->setAppId($_map['app_id']);
  122. $this->setAgentId($agent_rq->getCh());
  123. $this->setRegTime($mem_rq->getRegTime());
  124. $_days = Time::timeDateDiff($mem_rq->getRegTime(), $mem_rq->getLoginTime());
  125. $this->setRegDays($_days);
  126. $_role_days = (new MgRoleModel())->getRoleDays($mem_rq->getMgMemId());
  127. $this->setRoleDays($_role_days);
  128. $this->setDeviceId($device_rq->getDeviceId());
  129. $_device_id = $device_rq->getDeviceId();
  130. if (!empty($_device_id)) {
  131. $this->setDeviceCnt(1);
  132. }
  133. if (MemConst::STATUS_NORMAL == $mem_rq->getStatus()) {
  134. /* 状态未2 表示已授权 */
  135. $this->setAuthCnt(1);
  136. }
  137. $this->setLoginCnt(1);
  138. $this->setSumLoginCnt($_sum_login_cnt + 1);
  139. $this->setSumMoney($order_rq->getProductPrice());
  140. $this->setFirstPayTime($order_rq->getPayTime());
  141. $this->setLastPayTime($order_rq->getPayTime());
  142. $this->setLastMoney($order_rq->getProductPrice());
  143. if (!empty($_order_id)) {
  144. $this->setOrderCnt(1);
  145. if (OrderConst::PAY_STATUS_SUC == $order_rq->getStatus()) {
  146. $this->setOrderSucCnt(1);
  147. }
  148. }
  149. $this->setLastLoginIp($device_rq->getIp());
  150. if (OrderConst::PAY_SWITCH_YES == $_is_switch) {
  151. $_rs = (new DmlSwitchModel())->insertLog($this->toArray());
  152. }
  153. $_rs = $_model->insertLog($this->toArray());
  154. return $_rs;
  155. } else {
  156. $this->setDataFromDayMem($_data);
  157. if ($device_rq->getDeviceId() && $device_rq->getDeviceId() != $this->getDeviceId()) {
  158. $this->setDeviceId($device_rq->getDeviceId());
  159. $_device_id = $device_rq->getDeviceId();
  160. if (!empty($_device_id)) {
  161. $this->setDeviceCnt($this->getDeviceCnt() + 1);
  162. }
  163. }
  164. if ($this->getIsLogin()) {
  165. $this->setLoginCnt($this->getLoginCnt() + 1);
  166. if (MemConst::STATUS_NORMAL == $mem_rq->getStatus()) {
  167. /* 状态未2 表示已授权 */
  168. $this->setAuthCnt($this->getAuthCnt() + 1);
  169. }
  170. $this->setSumLoginCnt($_sum_login_cnt + 1);
  171. $this->setLastLoginIp($device_rq->getIp());
  172. }
  173. $_money = $order_rq->getProductPrice();
  174. if (!empty($_money)) {
  175. $this->setOrderCnt($this->getOrderCnt() + 1);
  176. $_sum_money = $this->getSumMoney();
  177. if (!empty($_sum_money)) {
  178. $this->setFirstPayTime($order_rq->getPayTime());
  179. }
  180. if (OrderConst::PAY_STATUS_SUC == $order_rq->getStatus()) {
  181. $this->setSumMoney($_sum_money + $order_rq->getProductPrice());
  182. $this->setLastPayTime($order_rq->getPayTime());
  183. $this->setLastMoney($order_rq->getProductPrice());
  184. $this->setOrderSucCnt($this->getOrderSucCnt() + 1);
  185. }
  186. }
  187. $_role_days = (new MgRoleModel())->getRoleDays($mem_rq->getMgMemId());
  188. if (!empty($_role_days) && $_role_days != $this->getRoleDays()) {
  189. $this->setRoleDays($_role_days);
  190. }
  191. if (OrderConst::PAY_SWITCH_YES == $_is_switch) {
  192. (new DmlSwitchModel())->updateLog($this->toArray(), $_data['id']);
  193. }
  194. return $_model->updateLog($this->toArray(), $_data['id']);
  195. }
  196. }
  197. /**
  198. * 从Day_mem设置数据
  199. *
  200. * @param $data
  201. */
  202. public function setDataFromDayMem($data) {
  203. if (empty($data)) {
  204. return;
  205. }
  206. $this->setDate($data['date']);
  207. $this->setMemId($data['mem_id']);
  208. $this->setAppId($data['app_id']);
  209. $this->setAgentId($data['agent_id']);
  210. $this->setRegTime($data['reg_time']);
  211. $this->setRegDays($data['reg_days']);
  212. $this->setDeviceId($data['device_id']);
  213. $this->setDeviceCnt($data['device_cnt']);
  214. $this->setLoginCnt($data['login_cnt']);
  215. $this->setSumMoney($data['sum_money']);
  216. $this->setFirstPayTime($data['first_pay_time']);
  217. $this->setLastPayTime($data['last_pay_time']);
  218. $this->setLastMoney($data['last_money']);
  219. $this->setOrderCnt($data['order_cnt']);
  220. $this->setOrderSucCnt($data['order_suc_cnt']);
  221. $this->setLastLoginIp($data['last_login_ip']);
  222. $this->setAuthCnt($data['auth_cnt']);
  223. }
  224. /**
  225. * @return string
  226. */
  227. public function getDate() {
  228. return $this->date;
  229. }
  230. /**
  231. * @param string $date
  232. */
  233. public function setDate($date) {
  234. $this->date = $date;
  235. }
  236. /**
  237. * @return int
  238. */
  239. public function getMemId() {
  240. return $this->mem_id;
  241. }
  242. /**
  243. * @param int $mem_id
  244. */
  245. public function setMemId($mem_id) {
  246. $this->mem_id = $mem_id;
  247. }
  248. /**
  249. * @return int
  250. */
  251. public function getAgentId() {
  252. return $this->agent_id;
  253. }
  254. /**
  255. * @param int $agent_id
  256. */
  257. public function setAgentId($agent_id) {
  258. $this->agent_id = $agent_id;
  259. }
  260. /**
  261. * @return int
  262. */
  263. public function getAppId() {
  264. return $this->app_id;
  265. }
  266. /**
  267. * @param int $app_id
  268. */
  269. public function setAppId($app_id) {
  270. $this->app_id = $app_id;
  271. }
  272. /**
  273. * @return int
  274. */
  275. public function getRegTime() {
  276. return $this->reg_time;
  277. }
  278. /**
  279. * @param int $reg_time
  280. */
  281. public function setRegTime($reg_time) {
  282. $this->reg_time = $reg_time;
  283. }
  284. /**
  285. * @return int
  286. */
  287. public function getRegDays() {
  288. return $this->reg_days;
  289. }
  290. /**
  291. * @param int $reg_days
  292. */
  293. public function setRegDays($reg_days) {
  294. $this->reg_days = $reg_days;
  295. }
  296. /**
  297. * @return int
  298. */
  299. public function getRoleDays() {
  300. return $this->role_days;
  301. }
  302. /**
  303. * @param int $role_days
  304. */
  305. public function setRoleDays($role_days) {
  306. $this->role_days = $role_days;
  307. }
  308. /**
  309. * @return string
  310. */
  311. public function getDeviceId() {
  312. return $this->device_id;
  313. }
  314. /**
  315. * @param string $device_id
  316. */
  317. public function setDeviceId($device_id) {
  318. $this->device_id = $device_id;
  319. }
  320. /**
  321. * @return int
  322. */
  323. public function getLoginCnt() {
  324. return $this->login_cnt;
  325. }
  326. /**
  327. * @param int $login_cnt
  328. */
  329. public function setLoginCnt($login_cnt) {
  330. $this->login_cnt = $login_cnt;
  331. }
  332. /**
  333. * @return float
  334. */
  335. public function getSumMoney() {
  336. return $this->sum_money;
  337. }
  338. /**
  339. * @param float $sum_money
  340. */
  341. public function setSumMoney($sum_money) {
  342. $this->sum_money = $sum_money;
  343. }
  344. /**
  345. * @return int
  346. */
  347. public function getFirstPayTime() {
  348. return $this->first_pay_time;
  349. }
  350. /**
  351. * @param int $first_pay_time
  352. */
  353. public function setFirstPayTime($first_pay_time) {
  354. $this->first_pay_time = $first_pay_time;
  355. }
  356. /**
  357. * @return int
  358. */
  359. public function getLastPayTime() {
  360. return $this->last_pay_time;
  361. }
  362. /**
  363. * @param int $last_pay_time
  364. */
  365. public function setLastPayTime($last_pay_time) {
  366. $this->last_pay_time = $last_pay_time;
  367. }
  368. /**
  369. * @return float
  370. */
  371. public function getLastMoney() {
  372. return $this->last_money;
  373. }
  374. /**
  375. * @param float $last_money
  376. */
  377. public function setLastMoney($last_money) {
  378. $this->last_money = $last_money;
  379. }
  380. /**
  381. * @return int
  382. */
  383. public function getOrderCnt() {
  384. return $this->order_cnt;
  385. }
  386. /**
  387. * @param int $order_cnt
  388. */
  389. public function setOrderCnt($order_cnt) {
  390. $this->order_cnt = $order_cnt;
  391. }
  392. /**
  393. * @return int
  394. */
  395. public function getOrderSucCnt() {
  396. return $this->order_suc_cnt;
  397. }
  398. /**
  399. * @param int $order_suc_cnt
  400. */
  401. public function setOrderSucCnt($order_suc_cnt) {
  402. $this->order_suc_cnt = $order_suc_cnt;
  403. }
  404. /**
  405. * @return string
  406. */
  407. public function getLastLoginIp() {
  408. return $this->last_login_ip;
  409. }
  410. /**
  411. * @param string $last_login_ip
  412. */
  413. public function setLastLoginIp($last_login_ip) {
  414. if (false == is_integer($last_login_ip)) {
  415. $last_login_ip = Ip::ipToLong($last_login_ip);
  416. }
  417. $this->last_login_ip = $last_login_ip;
  418. }
  419. /**
  420. * @return int
  421. */
  422. public function getDeviceCnt() {
  423. return $this->device_cnt;
  424. }
  425. /**
  426. * @param int $device_cnt
  427. */
  428. public function setDeviceCnt($device_cnt) {
  429. $this->device_cnt = $device_cnt;
  430. }
  431. /**
  432. * @param int $is_login
  433. */
  434. public function setIsLogin($is_login) {
  435. $this->is_login = $is_login;
  436. }
  437. /**
  438. * @return int
  439. */
  440. public function getIsLogin() {
  441. return $this->is_login;
  442. }
  443. /**
  444. * @return int
  445. */
  446. public function getSumLoginCnt() {
  447. return $this->sum_login_cnt;
  448. }
  449. /**
  450. * @param int $sum_login_cnt
  451. */
  452. public function setSumLoginCnt($sum_login_cnt) {
  453. $this->sum_login_cnt = $sum_login_cnt;
  454. }
  455. /**
  456. * @return int
  457. */
  458. public function getIsNew() {
  459. return $this->is_new;
  460. }
  461. /**
  462. * @param int $is_new
  463. */
  464. public function setIsNew($is_new) {
  465. $this->is_new = $is_new;
  466. }
  467. /**
  468. * @return int
  469. */
  470. public function getAuthCnt() {
  471. return $this->auth_cnt;
  472. }
  473. /**
  474. * @param int $auth_cnt
  475. */
  476. public function setAuthCnt($auth_cnt) {
  477. $this->auth_cnt = $auth_cnt;
  478. }
  479. }