AccountLogModel.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /**
  13. * 账户明细-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class AccountLogModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'account_logs';
  22. protected $appends = ['bill','real_money','time_text','status_text','account_name','type_name'];
  23. // 时间
  24. public function getTimeTextAttribute()
  25. {
  26. return $this->create_time? datetime($this->create_time,'Y-m-d H:i:s') : '';
  27. }
  28. // 金额
  29. public function getMoneyAttribute($value)
  30. {
  31. return $this->account_type==1? moneyFormat($value,2): floatval($value);
  32. }
  33. public function getAfterMoneyAttribute($value)
  34. {
  35. return $this->account_type==1? moneyFormat($value,2): floatval($value);
  36. }
  37. // 金额
  38. public function getRealMoneyAttribute()
  39. {
  40. return moneyFormat(abs($this->money),2);
  41. }
  42. // 类型
  43. public function getTypeNameAttribute()
  44. {
  45. $types = [1=>'订单付款',2=>'账户充值',3=>'订单退款',4=>'账户提现',5=>'账户提现驳回',6=>'平台调整',7=>'商家结算',8=>'收益奖励',9=>'积分互转',99=>'其他'];
  46. return isset($types[$this->type])?$types[$this->type]:'账户交易';
  47. }
  48. // 账户类型
  49. public function getAccountNameAttribute()
  50. {
  51. $types = [1=>'收益余额',2=>'数字资产',3=>'报单积分',4=>'绿色积分'];
  52. return isset($types[$this->account_type])?$types[$this->account_type]:'账户余额';
  53. }
  54. // 状态
  55. public function getStatusTextAttribute()
  56. {
  57. $statusArr = [1=>'交易成功',2=>'待处理',3=>'失败'];
  58. return isset($statusArr[$this->status])?$statusArr[$this->status]:'交易成功';
  59. }
  60. // 账单
  61. public function getBillAttribute()
  62. {
  63. if($this->type==4){
  64. return BalanceLogModel::where(['order_no'=>$this->source_order_no,'mark'=>1])
  65. ->select(['id','user_id','order_no','money','pay_at','pay_type','receive_status','total','fee','actual_money','pool_money','pt_money','type','pay_status','package_info','mch_id','batch_id','account_name','account','confirm_remark','transaction_id','confirm_at','create_time','status'])
  66. ->first();
  67. }else if($this->store_id>0 && $this->type == 7){
  68. return OrderModel::with(['user'])->where(['order_no'=>$this->source_order_no,'mark'=>1])
  69. ->select(['id','user_id','order_no','total','type','pay_total','pay_status','pay_at','transaction_id','create_time','status'])
  70. ->first();
  71. }else{
  72. return '';
  73. }
  74. }
  75. /**
  76. * 用户
  77. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  78. */
  79. public function member()
  80. {
  81. return $this->hasOne(MemberModel::class, 'id','user_id')
  82. ->select(['id','mobile','realname','nickname','status']);
  83. }
  84. }