AccountLogModel.php 2.7 KB

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