findByProductId($event['ProductSpuAudit']['product_id']); if (empty($audit)) throw new \Exception("商品不存在"); $audit->audit_status = $event['ProductSpuAudit']['status']; $audit->audit_reason = $event['ProductSpuAudit']['reason'] ?? ''; if (!$audit->save()) { throw new \Exception($audit->getErrorMessage()); } } /** * 上下架结果 * @param array $event * @return void * @throws \Exception */ public function listingResult(array $event) { $audit = $this->findByProductId($event['ProductSpuAudit']['product_id']); if (empty($audit)) throw new \Exception("商品不存在"); $audit->listing_status = $event['ProductSpuAudit']['status']; $audit->listing_reason = $event['ProductSpuAudit']['reason'] ?? ''; if (!$audit->save()) { throw new \Exception($audit->getErrorMessage()); } } /** * @param array $event * @return void * @throws \Exception */ public function updateResult(array $event) { switch ($event['ProductSpuAudit']['status']) { case WechatVideoShopGoodsUpdateStatusEnums::GOODS_UPDATE_STATUS_CHANGE: // 更新 $audit = $this->findByProductId($event['ProductSpuAudit']['product_id']); if (empty($audit)) throw new \Exception("商品不存在"); break; case WechatVideoShopGoodsUpdateStatusEnums::GOODS_UPDATE_STATUS_CREATE: // 新增 break; case WechatVideoShopGoodsUpdateStatusEnums::GOODS_UPDATE_STATUS_DELETE: // 删除 $audit = $this->findByProductId($event['ProductSpuAudit']['product_id']); if (empty($audit)) throw new \Exception("商品不存在"); break; } } /** * 通过productid获取本地商品 * @param $product_id * @return mixed|null */ protected function findByProductId($product_id) { return WechatVideoShopGoods::getOne([ ['product_id' => $product_id] ]); } }