FundsRecord.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\admin\model;
  3. use app\BaseModel;
  4. use think\helper\Str;
  5. use think\facade\Lang;
  6. class FundsRecord extends BaseModel
  7. {
  8. protected $autoWriteTimestamp = true;
  9. protected $createTime = 'create_time';
  10. protected $updateTime = 'update_time';
  11. /**
  12. * transaction_type 订单类型
  13. * - recharge 充值
  14. * - withdraw 提现
  15. * - order 投注
  16. */
  17. public $transaction_type_list = [
  18. 'recharge' => '充值',
  19. 'withdraw' => '提现',
  20. 'order' => '投注',
  21. 'frozen_money' => '资金冻结',
  22. 'return_order' => '退款',
  23. ];
  24. public static function addData($data)
  25. {
  26. $data['transaction_id'] = Str::random(32);
  27. return static::create($data);
  28. }
  29. public static function getList($params, $user_code = '') {
  30. $query = FundsRecord::alias('funds_record')
  31. ->join('user', 'funds_record.user_id=user.user_id','left');
  32. if ($user_code != '') {
  33. $query = $query->where('user.user_code', $user_code);
  34. }
  35. if (!empty($params['user_id'])) {
  36. $query->where('funds_record.user_id', $params['user_id']);
  37. }
  38. if (!empty($params['transaction_type'])) {
  39. $query->where('funds_record.transaction_type', $params['transaction_type']);
  40. }
  41. if (!empty($params['transaction_id'])) {
  42. $query->where('funds_record.transaction_id', $params['transaction_id']);
  43. }
  44. if (!empty($params['start_time']) ) {
  45. $start_time = strtotime($params['start_time'] . " 00:00:00");
  46. $query->where('funds_record.create_time', '>=', $start_time);
  47. }
  48. if (!empty($params['end_time'])) {
  49. $end_time = strtotime($params['end_time'] . " 23:59:59");
  50. $query->where('funds_record.create_time', '<=', $end_time);
  51. }
  52. $params['page'] = $params['page'] ?? 1;
  53. $params['limit'] = $params['limit'] ?? 15;
  54. $count = $query->count();
  55. $list = $query->field(['funds_record.*'])
  56. ->limit($params['limit'])
  57. ->page($params['page'])
  58. ->order('funds_record.id', 'desc')
  59. ->select();
  60. return [
  61. 'transaction_type' => (new FundsRecord)->getTransactionTypeList(),
  62. 'count' => $count,
  63. 'list' => $list,
  64. ];
  65. }
  66. public function getTransactionTypeList()
  67. {
  68. $list = $this->transaction_type_list;
  69. foreach ($list as $key => &$value) {
  70. $value = Lang::get("messages.{$value}");
  71. }
  72. return $list;
  73. }
  74. }