request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['status' => StatusEnum::ENABLED]; if (isset($get['activity_id']) && $get['activity_id'] > 0) { $where[] = ['id' => $get['activity_id']]; } try { $activity = AddonsCourseActivity::getOne($where, true, [], 'created_at desc'); if (empty($activity)) { throw new \Exception("活动不存在"); } if (empty($activity['goods_id'])) { throw new \Exception("活动未设置商品"); } $banners = []; if (!empty($activity['banners'])) { $banners = \Qiniu\json_decode($activity['banners']); } else { throw new \Exception("活动未设置广告图"); } $courseList = []; if (!empty($activity['course_id'])) { $idList = explode(",", trim($activity['course_id'])); $courseAll = AddonsCourse::getList($this->mall_id, $idList, 'id,name as course_name,logo,introduce'); $boughtIdsList = []; $courseIds = array_column($courseAll, 'id'); if (!empty($courseIds)) { $boughtList = AddonsCourseBought::find()->where(["mall_id" => $this->mall_id, "user_id" => $this->user_id, "status" => StatusEnum::ENABLED, 'is_pay' => CourseEnum::IS_PAY_YES])->andWhere(['IN', 'course_id', $courseIds])->asArray()->all(); $boughtIdsList = array_column($boughtList, 'course_id'); } foreach ($courseAll as $item) { $courseList[$item['id']] = $item; $courseList[$item['id']]['is_buy'] = 0; if (in_array($item['id'], $boughtIdsList)) { $courseList[$item['id']]['is_buy'] = 1; } } $courseList = array_values($courseList); } else { throw new \Exception("活动未设置课程"); } $data['banners'] = $banners; $data['courses'] = $courseList; $data['activity'] = $activity; } catch (\Exception $exception) { return $this->error($exception->getMessage()); } return $this->success('success', $data); } public function actionList() { try { $get = \Yii::$app->request->get(); $activity = AddonsCourseActivity::listPage([ 'select' => 'id,name,logo,goods_id', 'where' => [ ['mall_id' => $this->mall_id], ['=', 'status', StatusEnum::ENABLED] ], 'order' => 'id desc', 'limit' => $get['page_size'] ?? 10, ]); if ($activity['list']) { $activity['list'] = CourseActivityService::getList($activity['list'], $this->mall_id); } return $this->success('success', $activity); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }