WxappPrepayId.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model;
  3. use app\common\enum\OrderType as OrderTypeEnum;
  4. /**
  5. * 小程序prepay_id模型
  6. * Class WxappPrepayId
  7. * @package app\common\model
  8. */
  9. class WxappPrepayId extends BaseModel
  10. {
  11. protected $name = 'wxapp_prepay_id';
  12. /**
  13. * prepay_id 详情
  14. * @param int $orderId
  15. * @param int $orderType 订单类型
  16. * @return array|false|\PDOStatement|string|\think\Model|static
  17. */
  18. public static function detail($orderId, $orderType = OrderTypeEnum::MASTER)
  19. {
  20. return (new static)->where('order_id', '=', $orderId)
  21. ->where('order_type', '=', $orderType)
  22. ->order(['create_time' => 'desc'])
  23. ->find();
  24. }
  25. /**
  26. * 记录prepay_id使用次数
  27. * @return int|true
  28. * @throws \think\Exception
  29. */
  30. public function updateUsedTimes()
  31. {
  32. return $this->setInc('used_times', 1);
  33. }
  34. /**
  35. * 更新prepay_id已付款状态
  36. * @param $orderId
  37. * @param $orderType
  38. * @return false|int
  39. */
  40. public static function updatePayStatus($orderId, $orderType = OrderTypeEnum::MASTER)
  41. {
  42. // 获取prepay_id记录
  43. $model = static::detail($orderId, $orderType);
  44. if (empty($model)) {
  45. return false;
  46. }
  47. // 更新记录
  48. return $model->save(['can_use_times' => 3, 'pay_status' => 1]);
  49. }
  50. }