param('uid')) ?? 0; $ad_plan = intval(Request::instance()->param('ad_plan')) ?? 0; // 广告计划ID LogService::info("AD:sucOperate:Params:" . json_encode(Request::instance()->param())); if (empty($uid) || empty($ad_plan)) { LogService::info("AD:sucOperate:参数有误,Params:" . json_encode(Request::instance()->param())); $this->success('互动成功'); } LogService::info("AD:".json_encode(Request::instance()->param())); //1.通过广告计划获取赠送的书币个数 $data_plan = AdPlanService::instance()->getWelfarePlan($ad_plan); $day_receive_num = !empty($data_plan['day_receive_num']) ? $data_plan['day_receive_num'] : 0; //广告计划中设置的每天互动次数 $give_kandian = !empty($data_plan['give_kandian']) ? $data_plan['give_kandian'] : 0; $redis_key = AdConstants::AD_WELFARE_SUC_NUM . date('Ymd') . ':' . $ad_plan . ':' . $uid; //2.给用户增加书币, 免费看点(带有效期) if($give_kandian){ $join_num = (int)Redis::instance()->get($redis_key); // 用户参与的次数 // 判断用户今日完成了几次互动 if ($join_num < $day_receive_num) { Redis::instance()->incr($redis_key); Redis::instance()->expire($redis_key, 86400); UserService::instance()->addFreeKanDian($uid, $give_kandian, time(), '活动福利'); LogService::info("AD:互动福利广告给用户" . $uid . "增加了" . $give_kandian . "看点"); }else{ LogService::info("AD:用户" . $uid . "已参与互动广告".$join_num."次,超过广告计划设置的次数".$day_receive_num.",不在加书币了。"); } }else{ LogService::error("AD:互动福利广告没有设置互动赠送的书币个数,广告ID:".$ad_plan); } $this->success('互动成功'); } /** * 操作成功返回的数据 * @param string $msg 提示信息 * @param mixed $data 要返回的数据 * @param string $type 输出类型 * @param array $header 发送的 Header 信息 */ protected function success($msg = '', $data = '', $type = 'json', array $header = []) { $this->result($data, 1, $msg, $type, $header); } /** * 操作失败返回的数据 * @param string $msg 提示信息 * @param mixed $data 要返回的数据 * @param string $type 输出类型 * @param array $header 发送的 Header 信息 */ protected function error($msg = '', $data = '', $type = 'json', array $header = []) { $this->result($data, 0, $msg, $type, $header); } /** * 返回封装后的 API 数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @param int $code 返回的 code * @param mixed $msg 提示信息 * @param string $type 返回数据格式 * @param array $header 发送的 Header 信息 * @return void * @throws HttpResponseException */ protected function result($data, $code = 0, $msg = '', $type = '', array $header = []) { $result = [ 'code' => $code, 'msg' => $msg, 'time' => Request::instance()->server('REQUEST_TIME'), 'data' => $data, ]; $type = $type ?: $this->getResponseType(); $response = Response::create($result, $type)->header($header); throw new HttpResponseException($response); } }