MoneyLog.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 会员余额日志模型
  6. */
  7. class MoneyLog Extends Model
  8. {
  9. // 表名
  10. protected $name = 'user_money_log';
  11. // 开启自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = '';
  16. // 追加属性
  17. protected $append = [
  18. 'type_text',
  19. ];
  20. const TYPE_ORDER_PAY=1;
  21. const TYPE_CHARGE=2;
  22. const TYPE_TAKECASH=3;
  23. const TYPE_SETTLE=4;
  24. const TYPE_PROFIT=5;
  25. const TYPE_REFUND=6;
  26. const TYPE_TAKECASH_REJECT=7;
  27. const ADMIN=8;
  28. public static $types=[
  29. self::TYPE_ORDER_PAY=>'订单支付',
  30. self::TYPE_CHARGE=>'充值',
  31. self::TYPE_TAKECASH=>'提现',
  32. self::TYPE_TAKECASH_REJECT=>'提现驳回',
  33. self::TYPE_SETTLE=>'订单结算',
  34. self::TYPE_PROFIT=>'盈利',
  35. self::TYPE_REFUND=>'退款',
  36. self::ADMIN=>'后台变更',
  37. ];
  38. public function user(){
  39. return $this->belongsTo(User::class);
  40. }
  41. public function getTypeTextAttr($v, $d)
  42. {
  43. return self::$types[$d['type']]??'-';
  44. }
  45. /* protected static function init()
  46. {
  47. self::afterInsert(function (self $log){
  48. #结算的时候新增一条盈利记录
  49. if($log['type']==self::TYPE_SETTLE){
  50. $order=UserOrder::where('id',$log['order_id'])->find();
  51. if($order){
  52. self::create([
  53. 'type'=>self::TYPE_PROFIT,
  54. 'money'=>$log['money'],
  55. ]);
  56. }
  57. }
  58. });
  59. }*/
  60. }