'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'course_id' => 'Course ID', 'amount' => '支付金额', 'buy_type' => '课程购买方式,1:单独购买,2:商品赠送', 'order_id' => '购买该课程的订单 id,课程订单 id 或者公共订单 id', 'is_pay' => '状态,1:已支付,0:未支付', 'status' => '状态 0禁用,1启用,-1是删除', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getCourse() { return $this->hasOne(AddonsCourse::class, ['id' => 'course_id']); } /** * 新增用户购买的课程 * * @return boolean * @throws \Exception */ public static function addBought($params, $order_id) { $bought = self::getOne([["order_id" => $order_id, "buy_type" => 1, "user_id" => $params['user_id'], 'status' => StatusEnum::ENABLED]]); if (empty($bought)) { $bought = new self(); $bought->mall_id = $params['mall_id']; $bought->user_id = $params['user_id']; $bought->course_id = $params['course_id']; $bought->amount = $params['price']; $bought->buy_type = 1; $bought->order_id = $order_id; if ($params['order_status'] > 0) $bought->is_pay = 1; if (!$bought->save()) self::$static_error = $bought->getErrorMessage();; } return true; } public static function checkIsBought($ids, $user_id) { $where[] = ['=', 'user_id', $user_id]; $where[] = ['in', 'course_id', $ids]; $where[] = ['=', 'is_pay', CourseEnum::IS_PAY_YES]; return self::lists(['where' => $where, 'index' => 'course_id', 'select' => 'course_id']); } }