NoticeValidate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace common\expand\alipay\order\notice\validate;
  3. use common\expand\alipay\AlipayValidateInterface;
  4. use common\models\order\Order;
  5. use Yii;
  6. class NoticeValidate implements AlipayValidateInterface
  7. {
  8. protected $data = [];
  9. public function __construct(array $data)
  10. {
  11. $this->data = $data;
  12. }
  13. /**
  14. * @return bool|array
  15. */
  16. public function valid()
  17. {
  18. if (empty($this->data['id'])) {
  19. Yii::error(sprintf("%s ID不能为空", __CLASS__));
  20. return false;
  21. }
  22. $mall_id = Order::find()->where(['id' => $this->data['id']])->select('mall_id')->scalar();
  23. if (!$mall_id) {
  24. Yii::error(sprintf("%s 订单不存在 %d", __CLASS__, $this->data['id']));
  25. return false;
  26. }
  27. // 判断是否有支付宝小程序
  28. $app_id = Yii::$app->services->setting->mall->get($mall_id, "alipay_mini.app_id");
  29. if (!$app_id) {
  30. Yii::error(sprintf("%s 不支持支付宝小程序 %d", __CLASS__, $mall_id));
  31. return false;
  32. }
  33. // 判断是否有开启通知
  34. if (!Yii::$app->services->setting->mall->get($mall_id, "notice_alipay.{$this->data['step_key']}")) {
  35. Yii::error(sprintf("%s 未开启通知 %d %s", __CLASS__, $mall_id, $this->data['step_key']));
  36. return false;
  37. }
  38. return array_merge($this->data, [
  39. 'mall_id' => $mall_id,
  40. 'ali_mini_app_id' => $app_id,
  41. ]);
  42. }
  43. }