AccountLogModel.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Illuminate\Support\Facades\DB;
  13. /**
  14. * 账户明细-模型
  15. * @author laravel开发员
  16. * @since 2020/11/10
  17. * Class ActionLogModel
  18. * @package App\Models
  19. */
  20. class AccountLogModel extends BaseModel
  21. {
  22. // 设置数据表
  23. protected $table = null;
  24. // 自定义日志标题
  25. protected static $title = '';
  26. // 自定义日志内容
  27. protected static $content = '';
  28. public function __construct($table = null)
  29. {
  30. if ($table == null) {
  31. // 设置表名
  32. $this->table = 'account_log';
  33. } else {
  34. $this->table = $table;
  35. }
  36. $this->initTable();
  37. }
  38. /**
  39. * 获取表
  40. * @param $date
  41. * @return bool
  42. */
  43. public function getTable($date='')
  44. {
  45. if($date){
  46. $tbl = env('DB_PREFIX', 'lev_') .'account_log';
  47. return $this->tableExists($tbl)? 'account_log':'';
  48. }
  49. return $this->table;
  50. }
  51. /**
  52. * 用户
  53. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  54. */
  55. public function member()
  56. {
  57. return $this->hasOne(MemberModel::class, 'id','user_id')
  58. ->where(['mark'=>1])
  59. ->select(['id','nickname as name','mobile']);
  60. }
  61. /**
  62. * 司机
  63. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  64. */
  65. public function driver()
  66. {
  67. return $this->hasOne(DriverModel::class, 'id','user_id')
  68. ->where(['mark'=>1])
  69. ->select(['id','realname as name','mobile']);
  70. }
  71. /**
  72. *
  73. * @return string|null
  74. * @since 2020/11/10
  75. * @author laravel开发员
  76. */
  77. protected function initTable()
  78. {
  79. $tbl = env('DB_PREFIX', 'lev_') . $this->table;
  80. try {
  81. if (!$this->tableExists($tbl)) {
  82. $sql = "CREATE TABLE `{$tbl}` (
  83. `id` int(10) NOT NULL AUTO_INCREMENT,
  84. `user_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户ID/司机ID',
  85. `source_id` int(10) NOT NULL DEFAULT '0' COMMENT '关联用户或数据ID',
  86. `source_order_no` varchar(30) NOT NULL DEFAULT '' COMMENT '关联订单号',
  87. `user_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '账户类型:1-用户,2-司机,3-代理,4-平台',
  88. `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '交易类型:1-普通消费,2-VIP升级消费,3-分销佣金,4-平台调整,5-充值,6-诚意金,7-退款,8-余额提现,9-接单收入,10-在线奖金,11-红包奖励,12-在线奖金提现,99-其他',
  89. `coin_type` tinyint(2) NOT NULL DEFAULT '1' COMMENT '币种账户类型:1-人民币,3-通证积分,4-余额,5-奖励,99-其他',
  90. `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
  91. `balance` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '更改前余额',
  92. `date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  93. `create_time` int(10) NOT NULL DEFAULT '0',
  94. `update_time` int(10) NOT NULL DEFAULT '0',
  95. `transaction_id` varchar(64) NOT NULL DEFAULT '' COMMENT '涉及支付交易单号',
  96. `remark` varchar(150) NOT NULL DEFAULT '' COMMENT '备注',
  97. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:1-已完成,2-待处理,3-失败/取消',
  98. `mark` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效:1-是,0-否',
  99. PRIMARY KEY (`id`),
  100. KEY `user_id` (`user_id`),
  101. KEY `source_id` (`source_id`),
  102. KEY `type` (`type`),
  103. KEY `coin_type` (`coin_type`),
  104. KEY `mark` (`mark`),
  105. KEY `status` (`status`)
  106. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账户明细表';";
  107. DB::select($sql);
  108. }
  109. } catch (\Exception $exception){
  110. }
  111. return $tbl;
  112. }
  113. }