AccountLogModel.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. use App\Services\RedisService;
  13. use Illuminate\Support\Facades\DB;
  14. /**
  15. * 行为日志-模型
  16. * @author laravel开发员
  17. * @since 2020/11/10
  18. * Class ActionLogModel
  19. * @package App\Models
  20. */
  21. class AccountLogModel extends BaseModel
  22. {
  23. // 设置数据表
  24. protected $table = null;
  25. // 自定义日志标题
  26. protected static $title = '';
  27. // 自定义日志内容
  28. protected static $content = '';
  29. public function __construct($table = null)
  30. {
  31. if ($table == null) {
  32. // 设置表名
  33. $this->table = 'account_log_' . date('Y');
  34. } else {
  35. $this->table = $table;
  36. }
  37. $this->initTable();
  38. }
  39. /**
  40. * 获取表
  41. * @param $date
  42. * @return bool
  43. */
  44. public function getTable($date='')
  45. {
  46. if($date){
  47. $tbl = env('DB_PREFIX', 'lev_') .'account_log_'. $date;
  48. return $this->tableExists($tbl)? 'account_log_'. $date : '';
  49. }
  50. return $this->table;
  51. }
  52. public function getTables()
  53. {
  54. $cacheKey = "caches:config:account_tables";
  55. $data = RedisService::get($cacheKey);
  56. if($data){
  57. return $data;
  58. }
  59. $tables = parent::getTablesList();
  60. $accountTables = [];
  61. if(empty($tables)){
  62. $accountTables = [$this->table];
  63. }else{
  64. foreach ($tables as $table){
  65. if(preg_match("/^account_log/", $table)){
  66. $accountTables[] = $table;
  67. }
  68. }
  69. }
  70. if($accountTables){
  71. krsort($accountTables);
  72. RedisService::set($cacheKey, $accountTables, rand(10, 20));
  73. }
  74. return $accountTables;
  75. }
  76. /**
  77. * 初始化行为日志表
  78. * @return string|null
  79. * @since 2020/11/10
  80. * @author laravel开发员
  81. */
  82. protected function initTable()
  83. {
  84. $tbl = env('DB_PREFIX', 'lev_') . $this->table;
  85. try {
  86. if (!$this->tableExists($tbl)) {
  87. $sql = "CREATE TABLE `{$tbl}` (
  88. `id` int(10) NOT NULL AUTO_INCREMENT,
  89. `user_id` int NOT NULL DEFAULT '0' COMMENT '用户ID',
  90. `merch_id` int NOT NULL DEFAULT '0' COMMENT '来源商家ID',
  91. `source_uid` int NOT NULL DEFAULT '0' COMMENT '来源关联用户ID',
  92. `source_order_no` varchar(30) NOT NULL DEFAULT '' COMMENT '来源订单号',
  93. `user_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '账户类型:1-用户,2-商家,3-技师,4-代理,5-平台',
  94. `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '交易类型:1-商城消费,2-服务消费,3-分销佣金/工资/商家收入,4-平台调整,5-充值,6-转账,7-消费退款,8-聊天付费,9-招聘付费,10-代理佣金,11-用户提现,12-商家提现,13-平台收入,14-商家保证金,99-其他',
  95. `coin_type` tinyint NOT NULL DEFAULT '1' COMMENT '币种账户类型:1-人民币,2-佣金,3-积分,4-余额,5-收益,6-其他',
  96. `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
  97. `balance` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '更改前余额',
  98. `date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  99. `create_time` int NOT NULL DEFAULT '0',
  100. `update_time` int NOT NULL DEFAULT '0',
  101. `transaction_id` varchar(64) NOT NULL DEFAULT '' COMMENT '涉及支付交易单号',
  102. `review_remark` varchar(150) NOT NULL DEFAULT '' COMMENT '审核备注',
  103. `remark` varchar(150) NOT NULL DEFAULT '' COMMENT '备注',
  104. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:1-已完成,2-待处理,3-失败/取消',
  105. `mark` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效:1-是,0-否',
  106. PRIMARY KEY (`id`),
  107. KEY `user_id` (`user_id`),
  108. KEY `shop_id` (`merch_id`),
  109. KEY `source_uid` (`source_uid`),
  110. KEY `type` (`type`),
  111. KEY `coin_type` (`coin_type`),
  112. KEY `mark` (`mark`),
  113. KEY `status` (`status`)
  114. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账户明细表';";
  115. DB::select($sql);
  116. }
  117. } catch (\Exception $exception){
  118. }
  119. return $tbl;
  120. }
  121. }