RedpackMeetOne.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * 同布红包(MeetOne侧链
  4. * User: ben
  5. */
  6. class Sync_RedpackMeetOne extends Sync_Base {
  7. protected $dbKey = 'dw_chat';
  8. protected $frequency = 1;
  9. protected $index = 4;
  10. protected $dataField = ['sender', 'status','num_left', 'quantity_left', 'quantity_left_int', 'transfer_trx_id', 'update_time_int'];
  11. private $objRedpack;
  12. private $objRedpackLog;
  13. private $objBind;
  14. /**
  15. * 清除数据的时间间隔
  16. * @var int
  17. */
  18. protected $clearTtl = 600;
  19. protected $clearAction = 'clearpack';
  20. public function __construct() {
  21. $this->objRedpack = new Redpack();
  22. $this->objRedpackLog = new RedpackLog();
  23. $this->objBind = new UserBindInfo;
  24. ENV === ENV_FORMAL && $GLOBALS['eosUrl'] = $GLOBALS['eosxURL']; // 改为MeetOne侧链
  25. parent::__construct('redpack', 'id', 'update_time_int', null, $GLOBALS['codeMeeMO'], ['net_id' => Eos::NET_MEETONE]);
  26. }
  27. protected function addNewRows($newRows) {
  28. foreach ($newRows as $k => $row) {
  29. $row['create_time'] = $this->formatDateTime($row['create_time']);
  30. $row['quantity_total_int'] = Eos::toNumber($row['quantity_total']);
  31. $row['quantity_left_int'] = Eos::toNumber($row['quantity_left']);
  32. $row['sender_id'] = $this->objBind->getUserIdBy($row['sender'], Account::TYPE_MEETONE);
  33. $row['net_id'] = Eos::NET_MEETONE;
  34. $newRows[$k] = $row;
  35. }
  36. parent::addNewRows($newRows);
  37. foreach ($newRows as $row) {
  38. // 初始化红包奖励队列
  39. $this->objRedpack->initReward($row, $this->objRedis, Eos::NET_MEETONE);
  40. }
  41. }
  42. protected function updateRow($row, $priValue, $dbRow) {
  43. $row['create_time'] = $this->formatDateTime($row['create_time']);
  44. $row['quantity_total_int'] = Eos::toNumber($row['quantity_total']);
  45. $row['quantity_left_int'] = Eos::toNumber($row['quantity_left']);
  46. parent::updateRow($row, $priValue, $dbRow);
  47. // 红包结束计算最佳
  48. if ($dbRow['status'] == 0 && $row['status'] > 0) {
  49. try {
  50. $this->objRedpackLog->updateBest($row['transfer_trx_id']);
  51. } catch (Exception $e) {
  52. alermErrorMsg($e->getMessage());
  53. }
  54. }
  55. }
  56. }