UserBalanceLog.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\common\model;
  3. use fast\Asset;
  4. use fast\Http;
  5. use fast\Random;
  6. use think\Cache;
  7. use think\Log;
  8. use think\Model;
  9. use think\Request;
  10. class UserBalanceLog extends Model
  11. {
  12. protected $name = "user_balance_log";
  13. // 自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'create_time';
  17. protected $updateTime = 'update_time';
  18. protected $deleteTime = false;
  19. // 追加属性
  20. protected $append = [
  21. 'create_time_text',
  22. 'update_time_text'
  23. ];
  24. /*
  25. * 获取ETC的USDT价格
  26. */
  27. //0支付 1转让支付 2 转让收款 3 充值 4 提现
  28. const Popular = 0;
  29. const Payment = 1;
  30. const Receive = 2;
  31. const Recharge = 3;
  32. const Withdraw = 4;
  33. const Share = 5;
  34. /*
  35. * 支付状态
  36. * 0未支付 100支付中 200支付成功 400支付失败
  37. */
  38. public $pay_status = [
  39. '-1' => '全部',
  40. self::Popular => '热销支付',
  41. self::Payment => '转让支付',
  42. self::Receive => '转让收款',
  43. self::Recharge => '充值',
  44. self::Withdraw => '提现',
  45. self::Share => '分享',
  46. ];
  47. public static function getStatusList()
  48. {
  49. return [self::Popular => __('热销支付'), self::Payment => __('转让支付'), self::Receive => __('转让收款'), self::Recharge => __('充值'), self::Withdraw => __('提现'), self::Share => __('分享')];
  50. }
  51. /**
  52. * 更新钱包余额并添加账变记录
  53. * @param int $uid 用户ID
  54. * @param string $asset 资产类型
  55. * @param string $amount 金额 正:表示加 负:表示减
  56. * @param int $action 账变类型
  57. * @return void
  58. * @throws Exception
  59. */
  60. public static function changeWalletAccount(int $uid, int $type_id, string $amount, int $before, string $after, int $from_id, string $action = '+')
  61. {
  62. // 更新钱包余额
  63. UserModel::updateForRBalance($uid, $amount, $action);
  64. // 创建账变记录
  65. $insertRs = self::create([
  66. 'user_id' => $uid,
  67. 'from_id' => $from_id,
  68. 'type_id' => $type_id,
  69. 'amount' => $amount,
  70. 'before' => $before,
  71. 'after' => $after,
  72. 'action' => $action
  73. ]);
  74. if (empty($insertRs)) return false;
  75. }
  76. public function getCreateTimeTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  79. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  80. }
  81. public function getUpdateTimeTextAttr($value, $data)
  82. {
  83. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  84. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  85. }
  86. protected function setCreateTimeAttr($value)
  87. {
  88. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  89. }
  90. protected function setUpdateTimeAttr($value)
  91. {
  92. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  93. }
  94. }