12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?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,$class,$func,$payment_id,$body="订单付款",$payment_type=''){
- $payment=self::create([
- 'pay_type'=>$pay_type,
- 'class'=>$class,
- 'method'=>$func,
- '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);
- 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 'orders':
- Orders::makePayed($this['payment_id']);
- break;
- }
- }
- }
|