MobileOrderRefundLog.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model;
  3. use app\admin\model\Admin;
  4. use think\Model;
  5. /**
  6. * 配置模型
  7. */
  8. class MobileOrderRefundLog extends Model
  9. {
  10. protected $autoWriteTimestamp=true;
  11. protected $updateTime=null;
  12. protected $append=[
  13. 'create_time_format',
  14. ];
  15. public function refunduser(){
  16. return $this->morphTo('refunduser',[
  17. 'admin'=>Admin::class,
  18. 'user' =>User::class,
  19. ]);
  20. }
  21. public function mobileOrder(){
  22. return $this->belongsTo(MobileOrder::class,'mobile_id','id')->setEagerlyType(0);
  23. }
  24. public static function withRefundUser(User $user,$data){
  25. return new self([
  26. 'refunduser_type'=>'user',
  27. 'refunduser_id'=>$user['id'],
  28. 'amount'=>$data['amount'],
  29. ]);
  30. }
  31. public static function withRefundAdmin(Admin $user,$data){
  32. return new self([
  33. 'refunduser_type'=>'admin',
  34. 'refunduser_id'=>$user['id'],
  35. 'amount'=>$data['amount'],
  36. ]);
  37. }
  38. public static function withRefund($type,$user,$data){
  39. return new self([
  40. 'refunduser_type'=>$type,
  41. 'refunduser_id'=>$user['id'],
  42. 'amount_user'=>$data['amount_user']??0,
  43. 'amount_backend'=>$data['amount'],
  44. 'reason'=>$data['refund_reason'],
  45. 'pass'=>$data['pass'],
  46. ]);
  47. }
  48. public function getCreateTimeFormatAttr($a,$b){
  49. return date('m/d H:i',$b['create_time']);
  50. }
  51. }