BargainOrderSettledService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\api\service\order\settled;
  3. use app\common\enum\order\OrderSourceEnum;
  4. use app\common\model\settings\Setting as SettingModel;
  5. /**
  6. * 砍价订单结算服务类
  7. */
  8. class BargainOrderSettledService extends OrderSettledService
  9. {
  10. private $config;
  11. /**
  12. * 构造函数
  13. */
  14. public function __construct($user, $productList, $params)
  15. {
  16. parent::__construct($user, $productList, $params);
  17. // 订单来源
  18. $this->orderSource = [
  19. 'source' => OrderSourceEnum::BARGAIN,
  20. 'activity_id' => $productList[0]['activity_id']
  21. ];
  22. $this->config = SettingModel::getItem('bargain');
  23. // 自身构造,差异化规则
  24. $this->settledRule = array_merge($this->settledRule, [
  25. 'is_coupon' => $this->config['is_coupon'],
  26. 'is_agent' => $this->config['is_agent'],
  27. 'is_use_points' => $this->config['is_point'],
  28. 'is_user_grade' => false, // 会员等级折扣
  29. ]);
  30. }
  31. /**
  32. * 验证订单商品的状态
  33. */
  34. public function validateProductList()
  35. {
  36. // 判断活动是否开启
  37. if (!$this->config['is_open']) {
  38. $this->error = "活动未开启";
  39. return false;
  40. }
  41. foreach ($this->productList as $product) {
  42. // 判断商品是否下架
  43. if ($product['product_status']['value'] != 10) {
  44. $this->error = "很抱歉,商品已下架";
  45. return false;
  46. }
  47. // 判断商品库存
  48. if ($product['total_num'] > $product['bargain_sku']['bargain_stock']) {
  49. $this->error = "很抱歉,商品库存不足";
  50. return false;
  51. }
  52. }
  53. return true;
  54. }
  55. }