WxappPrepayId.php 1.5 KB

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