123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\common\model;
- use app\common\service\OrderPayService;
- use think\Log;
- use think\Model;
- /**
- * @property int pay_type
- * @property string order_no
- */
- class Payment extends Model
- {
- protected $autoWriteTimestamp=true;
- protected $type=[
- 'params'=>'json',
- ];
- public static function pay(User $user,$pay_type,$amount,$payment_id,$body="订单付款",$payment_type=''){
- $payment=self::create([
- 'pay_type'=>$pay_type,
- 'order_no'=>order_no(),
- 'amount'=>$amount,
- 'user_id'=>$user['id'],
- 'payment_type'=>$payment_type,
- 'payment_id'=>$payment_id,
- ]);
- $service=new OrderPayService();
- $service->setPayment($payment);
- $service->setBody($body);
- $service->setExpire($payment->getExpire());
- return $service->pay();
- }
- public function user(){
- return $this->belongsTo(User::class);
- }
- public function payed(){
- $this['pay_time']=time();
- $this->save();
- switch ($this['payment_type']){
- case (new Orders)->getTable():
- Orders::makePayed($this);
- break;
- }
- }
- public function getExpire(){
- switch ($this['payment_type']){
- case (new Orders)->getTable():
- return time()+Orders::EXP_PAY-60;
- default:
- return time()+3600;
- }
- }
- }
|