Redpack.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * 同布赌注表
  4. * User: ben
  5. */
  6. class Sync_Redpack 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. parent::__construct('redpack', 'id', 'update_time_int');
  25. }
  26. protected function addNewRows($newRows) {
  27. foreach ($newRows as $k => $row) {
  28. $row['create_time'] = $this->formatDateTime($row['create_time']);
  29. $row['quantity_total_int'] = Eos::toNumber($row['quantity_total']);
  30. $row['quantity_left_int'] = Eos::toNumber($row['quantity_left']);
  31. $row['sender_id'] = $this->objBind->getUserIdBy($row['sender']);
  32. $newRows[$k] = $row;
  33. }
  34. parent::addNewRows($newRows);
  35. foreach ($newRows as $row) {
  36. // 初始化红包奖励队列
  37. $this->objRedpack->initReward($row, $this->objRedis);
  38. }
  39. }
  40. protected function updateRow($row, $priValue, $dbRow) {
  41. $row['create_time'] = $this->formatDateTime($row['create_time']);
  42. $row['quantity_total_int'] = Eos::toNumber($row['quantity_total']);
  43. $row['quantity_left_int'] = Eos::toNumber($row['quantity_left']);
  44. parent::updateRow($row, $priValue, $dbRow);
  45. // 红包结束计算最佳
  46. if ($dbRow['status'] == 0 && $row['status'] > 0) {
  47. try {
  48. $this->objRedpackLog->updateBest($row['transfer_trx_id']);
  49. } catch (Exception $e) {
  50. alermErrorMsg($e->getMessage());
  51. }
  52. }
  53. }
  54. }