<?php
namespace app\common\model;
use app\common\enum\OrderType as OrderTypeEnum;
class WxappPrepayId extends BaseModel
{
protected $name = 'wxapp_prepay_id';
public static function detail($orderId, $orderType = OrderTypeEnum::MASTER)
{
return (new static)->where('order_id', '=', $orderId)
->where('order_type', '=', $orderType)
->order(['create_time' => 'desc'])
->find();
}
public function updateUsedTimes()
{
return $this->setInc('used_times', 1);
}
public static function updatePayStatus($orderId, $orderType = OrderTypeEnum::MASTER)
{
$model = static::detail($orderId, $orderType);
if (empty($model)) {
return false;
}
return $model->save(['can_use_times' => 3, 'pay_status' => 1]);
}
}