$mall_id], ['status' => StatusEnum::ENABLED] ]; if (!empty($params['type'])) { $where[] = ['type' => $params['type']]; } if (!empty($params['keyword'])) { $where[] = ['like', 'content', $params['keyword']]; } $ret = QiDingDongEvent::listPage([ 'where' => $where, 'limit' => $params['limit'] ?? 10, 'order' => 'id desc' ]); if (!empty(QiDingDongEvent::getStaticError())) return QiDingDongEvent::getStaticError(); if (!empty($ret['list'])) { foreach ($ret['list'] as &$item) { if (empty($item['err'])) $item['err'] = '[]'; $item['err'] = Json::decode($item['err']); $item['err_message'] = $item['err']['msg'] ?? '无错误信息'; } } return $ret; } public function exec(string $type, array $data, $is_compensate = false) { $model = new QiDingDongEvent(); $status = 200; $message = 'OK'; $model->err = []; $model->post = $data; $model->type = $type; try { $model->mall_id = SettingService::getMasterMall(); if (empty($model->mall_id)) throw new \Exception("还未设置主商城"); $config = (new SettingService())->get($model->mall_id); if (empty($config) || $config['app_key'] != $data['app_key']) { throw new \Exception("还未设置配置信息"); } $model->content = RequestHelper::decrypt($data, $model->mall_id); switch($model->type) { case 'goods': (new GoodsService())->eventUpdate($model); break; case 'order': (new OrderService())->eventUpdate($model); break; } } catch (\Exception $e) { $status = 500; $message = $e->getMessage(); $model->err = [ 'code' => $e->getCode(), 'msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), ]; } if (empty($model->content)) $model->content = []; if (!$is_compensate && !$model->save()) { \Yii::error($model->getErrorMessage() . " - " . __METHOD__); } // 记录数据 return [ 'status' => $status, 'msg' => 'OK', 'content' => [ 'msg' => $message ] ]; } public function compensate(int $mall_id, int $id) { try { $notice = QiDingDongEvent::findOne(['mall_id' => $mall_id, 'id' => $id]); if (empty($notice)) throw new \Exception("记录不存在"); // 重新执行 $ret = $this->exec($notice->type, $notice->post, true); if ($ret['status'] != 200) throw new \Exception($ret['content']['msg']); $notice->err = []; $notice->save(); return true; } catch (\Exception $e) { return $e->getMessage(); } } }