Payment.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\model;
  3. use app\common\service\OrderPayService;
  4. use think\Log;
  5. use think\Model;
  6. /**
  7. * @property int pay_type
  8. * @property string order_no
  9. */
  10. class Payment extends Model
  11. {
  12. protected $autoWriteTimestamp=true;
  13. protected $type=[
  14. 'params'=>'json',
  15. ];
  16. public static function pay(User $user,$pay_type,$amount,$class,$func,$payment_id,$body="订单付款",$payment_type=''){
  17. $payment=self::create([
  18. 'pay_type'=>$pay_type,
  19. 'class'=>$class,
  20. 'method'=>$func,
  21. 'order_no'=>order_no(),
  22. 'amount'=>$amount,
  23. 'user_id'=>$user['id'],
  24. 'payment_type'=>$payment_type,
  25. 'payment_id'=>$payment_id,
  26. ]);
  27. $service=new OrderPayService();
  28. $service->setPayment($payment);
  29. $service->setBody($body);
  30. return $service->pay();
  31. }
  32. public function user(){
  33. return $this->belongsTo(User::class);
  34. }
  35. public function payed(){
  36. $this['pay_time']=time();
  37. $this->save();
  38. switch ($this['payment_type']){
  39. case 'orders':
  40. Orders::makePayed($this['payment_id']);
  41. break;
  42. }
  43. }
  44. }