MemberPointCoin.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/10/12
  6. * Time: 下午3:28
  7. */
  8. namespace app\frontend\modules\finance\models;
  9. use app\common\exceptions\AppException;
  10. use app\common\models\VirtualCoin;
  11. use app\common\services\finance\PointService;
  12. use app\frontend\models\MemberCoin;
  13. class MemberPointCoin extends MemberCoin
  14. {
  15. /**
  16. * 获取最多可用积分
  17. * @return mixed
  18. */
  19. public function getMaxUsableCoin()
  20. {
  21. return (new PointCoin)->setCoin($this->member->credit1);
  22. }
  23. public function lockCoin($coin)
  24. {
  25. if (bccomp($coin, $this->member->credit1) == 1) {
  26. $pointName = \Setting::get('shop.shop.credit1') ?: '积分';
  27. throw new AppException("用户(ID:{$this->member->uid})" . $pointName . "余额不足");
  28. }
  29. $this->member->credit1 -= $coin;
  30. }
  31. /**
  32. * @param VirtualCoin $coin
  33. * @param $data
  34. * @return bool
  35. * @throws \app\common\exceptions\ShopException
  36. */
  37. function consume(VirtualCoin $coin, $data)
  38. {
  39. $point_service = new PointService([
  40. 'point_income_type' => -1,
  41. 'point_mode' => PointService::POINT_MODE_BY,
  42. 'member_id' => $this->member->uid,
  43. 'point' => -$coin->getCoin(),
  44. 'remark' => '订单[' . $data['order_sn'] . ']抵扣[' . $coin->getMoney() . ']元'
  45. ]);
  46. $point_service->changePoint();
  47. return true;
  48. }
  49. }