| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\common\model;
- use fast\Asset;
- use fast\Http;
- use fast\Random;
- use think\Cache;
- use think\Log;
- use think\Model;
- use think\Request;
- class UserBalanceLog extends Model
- {
- protected $name = "user_balance_log";
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'create_time_text',
- 'update_time_text'
- ];
- /*
- * 获取ETC的USDT价格
- */
- //0支付 1转让支付 2 转让收款 3 充值 4 提现
- const Popular = 0;
- const Payment = 1;
- const Receive = 2;
- const Recharge = 3;
- const Withdraw = 4;
- const Share = 5;
- /*
- * 支付状态
- * 0未支付 100支付中 200支付成功 400支付失败
- */
- public $pay_status = [
- '-1' => '全部',
- self::Popular => '热销支付',
- self::Payment => '转让支付',
- self::Receive => '转让收款',
- self::Recharge => '充值',
- self::Withdraw => '提现',
- self::Share => '分享',
- ];
- public static function getStatusList()
- {
- return [self::Popular => __('热销支付'), self::Payment => __('转让支付'), self::Receive => __('转让收款'), self::Recharge => __('充值'), self::Withdraw => __('提现'), self::Share => __('分享')];
- }
- /**
- * 更新钱包余额并添加账变记录
- * @param int $uid 用户ID
- * @param string $asset 资产类型
- * @param string $amount 金额 正:表示加 负:表示减
- * @param int $action 账变类型
- * @return void
- * @throws Exception
- */
- public static function changeWalletAccount(int $uid, int $type_id, string $amount, int $before, string $after, int $from_id, string $action = '+')
- {
- // 更新钱包余额
- UserModel::updateForRBalance($uid, $amount, $action);
- // 创建账变记录
- $insertRs = self::create([
- 'user_id' => $uid,
- 'from_id' => $from_id,
- 'type_id' => $type_id,
- 'amount' => $amount,
- 'before' => $before,
- 'after' => $after,
- 'action' => $action
- ]);
- if (empty($insertRs)) return false;
- }
- public function getCreateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getUpdateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setCreateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setUpdateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- }
|