AccountLogModel.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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','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 floatval($value);
  32. }
  33. // 金额
  34. public function getRealMoneyAttribute()
  35. {
  36. return moneyFormat(abs($this->money),2);
  37. }
  38. // 类型
  39. public function getTypeNameAttribute()
  40. {
  41. $types = [1=>'订单付款',2=>'账户充值',3=>'订单退款',4=>'账户提现',5=>'账户提现驳回',6=>'平台调整',7=>'商家结算',8=>'收益奖励',9=>'其他',10=>'账户转账'];
  42. return isset($types[$this->type])?$types[$this->type]:'账户交易';
  43. }
  44. // 状态
  45. public function getStatusTextAttribute()
  46. {
  47. $statusArr = [1=>'交易成功',2=>'待处理',3=>'失败'];
  48. return isset($statusArr[$this->status])?$statusArr[$this->status]:'交易成功';
  49. }
  50. // 账单
  51. public function getBillAttribute()
  52. {
  53. if($this->type==4){
  54. return BalanceLogModel::where(['order_no'=>$this->source_order_no,'mark'=>1])
  55. ->select(['id','user_id','order_no','money','pay_at','pay_status','account_name','account','confirm_remark','transaction_id','confirm_at','create_time','status'])
  56. ->first();
  57. }else if($this->store_id>0 && $this->type == 7){
  58. return OrderModel::with(['user'])->where(['order_no'=>$this->source_order_no,'mark'=>1])
  59. ->select(['id','user_id','order_no','total','meeting_id','pay_total','pay_at','transaction_id','bonus','create_time','status'])
  60. ->first();
  61. }else{
  62. return '';
  63. }
  64. }
  65. /**
  66. * 用户
  67. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  68. */
  69. public function member()
  70. {
  71. return $this->hasOne(MemberModel::class, 'id','user_id')
  72. ->select(['id','mobile','realname','nickname','status']);
  73. }
  74. }