Wang Chen 4 jaren geleden
bovenliggende
commit
ee68767b12

+ 6 - 1
app/Consts/ErrorConst.php

@@ -38,5 +38,10 @@ class ErrorConst
     const PUSH_FAIELD                       = '10008:推送失败,请联系管理员';
 
     // 业务相关
-    const QAPP_LOGIN_FREQUENTLY              = '10028:并发登录限制';
+    const QAPP_LOGIN_FREQUENTLY             = '10028:并发登录限制';
+
+    // 活动相关
+    const ACTIVITY_NOT_FOUND                = '20001:查询不到相关活动';
+    const ACTIVITY_NOT_START                = '20002:活动还未开始';
+    const ACTIVITY_IS_END                   = '20003:活动已经结束';
 }

+ 560 - 0
app/Http/Controllers/QuickApp/Activity/ActivityController.php

@@ -0,0 +1,560 @@
+<?php
+
+namespace App\Http\Controllers\QuickApp\Activity;
+
+use App\Consts\ErrorConst;
+use App\Http\Controllers\QuickApp\Activity\Transformers\ReBuildData;
+use App\Libs\ApiResponse;
+use App\Libs\Utils;
+use App\Modules\Activity\Services\ActivityService;
+use App\Modules\Channel\Services\ChannelService;
+use App\Modules\Product\Services\ProductService;
+use App\Modules\Subscribe\Services\OrderService;
+use Illuminate\Http\Request;
+use App\Http\Controllers\QuickApp\BaseController;
+use Redis;
+use DB;
+use Log;
+
+class ActivityController extends BaseController
+{
+    use ApiResponse;
+
+    //渠道自定义活动  可以多少充值
+    public function channelCustomActivity(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $token                          = $request->input('token');
+        $activity_info                  = ActivityService::getByToken($token);
+        $img                            = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
+        if ($activity_info && $activity_info->product_id) {
+            $customer_activity_info = DB::table('channel_custom_activity')->where('product_id', $activity_info->product_id)->select('setting')->first();
+            if ($customer_activity_info && $customer_activity_info->setting) {
+                $img = json_decode($customer_activity_info->setting, 1)['img'];
+            }
+            $from          = $request->input('fromtype', 'main');
+            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+            $uv_key        = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+            $pv_key        = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+            Redis::sadd($uv_key, $this->uid);
+            Redis::hincrby($pv_key, date('Y-m-d'), 1);
+            //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
+            //渠道不符合
+            if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
+                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
+            }
+            //活动未开始
+            if (time() < strtotime($activity_info->start_time)) {
+                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -3, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+            //活动结束
+            if (time() > strtotime($activity_info->end_time)) {
+                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+
+            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
+                $param = [
+                    'uid'                     => $this->uid,
+                    'distribution_channel_id' => $this->distribution_channel_id,
+                    'product_id'              => $activity_info->product_id,
+                    'activity_id'             => $activity_info->id,
+                    'fromtype'                => $from,
+                    'limit'                   => 100,
+                    'pay_redirect_url'        => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
+                ];
+                $url   = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+                return view('pay.activity.ChannelCustomerV1', ['url' => $url, 'img' => $img, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+        }
+        return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
+    }
+
+
+    public function commonActivity(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $token                          = $request->input('token');
+        $activity_info                  = ActivityService::getByToken($token);
+        if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
+            $imgs          = json_decode($activity_info->setting, 1);
+            $from          = $request->input('fromtype', 'main');
+            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+            $uv_key        = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+            $pv_key        = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+
+            $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
+            if ($request->input('redirect_url')) {
+                $redirect_url = $request->input('redirect_url');
+                $redirect_url = urldecode($redirect_url);
+            }
+            $product_id = $activity_info->product_id;
+            if ($activity_info->id == 6000) {
+                $imgs['page_bd_img'] = 'https://cdn-novel.iycdm.com/h5/activity-2019-04-29/bg2.jpg';
+                $product_id          = 5788;
+            }
+            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
+                Redis::sadd($uv_key, $this->uid);
+                Redis::hincrby($pv_key, date('Y-m-d'), 1);
+                $param = [
+                    'uid'                     => $this->uid,
+                    'distribution_channel_id' => $this->distribution_channel_id,
+                    'product_id'              => $product_id,
+                    'activity_id'             => $activity_info->id,
+                    'fromtype'                => $from,
+                    'pay_redirect_url'        => $redirect_url,
+                    'limit'                   => 100,
+                ];
+                $url   = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+
+                return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
+            } else if (time() <= strtotime($activity_info->start_time)) {
+                return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
+            } else {
+                return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
+            }
+        }
+        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+        return redirect()->to($default_url);
+    }
+
+    public function crmActivity(Request $request)
+    {
+        $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+
+        $token = $request->input('token');
+        if (!$token) {
+            return redirect()->to($default_url);
+        }
+        $activity_info = ActivityService::getByToken($token);
+        if (!$activity_info) {
+            return redirect()->to($default_url);
+        }
+        $crm          = $request->get('crm', 'crm');
+        $img          = \GuzzleHttp\json_decode($activity_info->setting, 1);
+        $param        = [
+            'uid'                     => $this->uid,
+            'distribution_channel_id' => $this->distribution_channel_id,
+            'product_id'              => $activity_info->product_id,
+            'activity_id'             => $activity_info->id,
+            'fromtype'                => 'crm',
+            'pay_redirect_url'        => $default_url . 'person',
+            'limit'                   => 100,
+            'crm'                     => $crm
+        ];
+        $product_info = ProductService::getProductSingle($activity_info->product_id);
+        $url          = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+        $fee          = $product_info->price * 100 + $product_info->given;
+        return view('crm.crmActivity', ['url' => $url, 'img' => $img['button'], 'fee' => $fee]);
+    }
+
+
+    public function crmYearActivity(Request $request)
+    {
+        $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+
+        $activity_info = ActivityService::getById(11378);
+        if (!$activity_info) {
+            return redirect()->to($default_url);
+        }
+        $crm = $request->get('crm', 'crm_year_activity');
+
+        $param = [
+            'uid'                     => $this->uid,
+            'distribution_channel_id' => $this->distribution_channel_id,
+            'product_id'              => $activity_info->product_id,
+            'activity_id'             => $activity_info->id,
+            'fromtype'                => 'crm',
+            'pay_redirect_url'        => $default_url . 'person',
+            'limit'                   => 100,
+            'crm'                     => $crm
+        ];
+
+        $url             = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+        $is_get          = 0;
+        $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_info->id)->count();
+        if ($discount_coupon) {
+            $is_get = 1;
+        } else {
+            DB::table('discount_coupons')->insert([
+                'uid'         => $this->uid,
+                'activity_id' => $activity_info->id,
+                'created_at'  => date('Y-m-d H:i:s'),
+                'updated_at'  => date('Y-m-d H:i:s')
+            ]);
+        }
+        return view('crm.crmYearActivityV2', ['url' => $url, 'is_get' => $is_get]);
+    }
+
+    public function channelCustomActivityV3(Request $request)
+    {
+        $uid        = $this->uid;
+        $token      = $request->get('token');
+        $from       = $request->input('fromtype', 'main');
+        $channelId  = (int)$this->distribution_channel_id;
+        $activity   = ActivityService::getByToken($token);
+        $activityId = getProp($activity, 'id');
+        if (!$activityId || !getProp($activity, 'setting') || (int)getProp($activity, 'create_type') !== 5
+            || (int)getProp($activity, 'distribution_channel_id') !== $channelId) {
+            Utils::throwError(ErrorConst::ACTIVITY_NOT_FOUND);
+        }
+
+        // 活动开始时间判断
+        if (getProp($activity, 'start_time') > date('Y-m-d H:i:s')) {
+            Utils::throwError(ErrorConst::ACTIVITY_NOT_START);
+        }
+
+        // 活动结束时间判断
+        if (getProp($activity, 'end_time') < date('Y-m-d H:i:s')) {
+            Utils::throwError(ErrorConst::ACTIVITY_IS_END);
+        }
+
+        // 活动统计
+        $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+        $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+        $uv_key        = sprintf($uv_key_format, $activityId, $channelId, date('Y-m-d'));
+        $pv_key        = sprintf($pv_key_format, $activityId, $channelId);
+        Redis::sadd($uv_key, $uid);
+        Redis::hincrby($pv_key, date('Y-m-d'), 1);
+
+        // 获取支付相关信息
+        $settingJson     = getProp($activity, 'setting');
+        $setting         = json_decode($settingJson, true);
+        $settingProducts = getProp($setting, 'product_info');
+        $productIds      = array_column($settingProducts, 'product_id');
+        $products        = ProductService::getProductsByIds($productIds);
+
+        // 组装返回数据
+        $data = compact('uid', 'activity', 'products', 'setting', 'settingProducts', 'from');
+        return $this->success($data, [new ReBuildData(), 'buildActivityDetail']);
+    }
+
+    public function channelCustomActivityV2(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $token                          = $request->get('token');
+        $activity_info                  = ActivityService::getByToken($token);
+        if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting) &&
+            $activity_info->create_type == 5 &&
+            $activity_info->distribution_channel_id == $this->distribution_channel_id
+        ) {
+            $setting        = json_decode($activity_info->setting, 1);
+            $select_options = 1;
+            $page           = 'pay.activity-template.channelCommonTemplate';
+            if (isset($setting['product_info']) && count($setting['product_info']) > 1) {
+                $select_options = 2;
+                $page           = 'pay.activity-template.channelCommonTemplate2';
+            }
+            $from          = $request->input('fromtype', 'main');
+            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+            $uv_key        = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+            $pv_key        = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+
+            $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
+            if ($request->input('redirect_url')) {
+                $redirect_url = $request->input('redirect_url');
+                $redirect_url = urldecode($redirect_url);
+            }
+
+            $imgs         = [
+                'page_bd_img'        => $setting['page_bd_img'],
+                'page_btn_pre_img'   => $setting['page_btn_pre_img'],
+                'page_btn_doing_img' => $setting['page_btn_doing_img'],
+                'page_btn_end_img'   => $setting['page_btn_end_img']
+            ];
+            $bg_color     = $setting['page_bd_color'];
+            $product_id   = $activity_info->product_id;
+            $product_info = ProductService::getProductSingle($product_id);
+            $limit_times  = (!isset($setting['limit_times']) || !$setting['limit_times']) ? 100 : $setting['limit_times'];
+            $tip          = '';
+            if ($limit_times != '100' && $product_info->type != 'YEAR_ORDER') {
+                $tip = sprintf('活动期间充%s送%s限购%s次', (float)$product_info->price, $product_info->given / 100, $limit_times);
+            }
+
+            $price           = $product_info->price;
+            $given           = $product_info->given / 100;
+            $tip_list        = [];
+            $pay_option_list = [];
+            if ($select_options == 2) {
+                foreach ($setting['product_info'] as $product_item) {
+                    $product_detail = ProductService::getProductSingle($product_item['product_id']);
+                    if ($product_item['limit']) {
+                        $tip_list[] = sprintf('活动期间充%s送%s限购%s次', (float)$product_detail->price, $product_detail->given / 100, $product_item['limit']);
+                    } else {
+                        $tip_list[] = sprintf('活动期间充%s送%s不限次数', (float)$product_detail->price, $product_detail->given / 100);
+
+                    }
+                    $pay_option_list[] = [
+                        'price' => (float)$product_detail->price,
+                        'given' => $product_detail->given / 100,
+                        'total' => (int)($product_detail->price * 100) + $product_detail->given,
+                        'url'   => 'javascript:void(0)'
+                    ];
+                }
+            }
+            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
+                Redis::sadd($uv_key, $this->uid);
+                Redis::hincrby($pv_key, date('Y-m-d'), 1);
+                if ($select_options == 1) {
+                    $param = [
+                        'uid'                     => $this->uid,
+                        'distribution_channel_id' => $this->distribution_channel_id,
+                        'product_id'              => $product_id,
+                        'activity_id'             => $activity_info->id,
+                        'fromtype'                => $from,
+                        'pay_redirect_url'        => $redirect_url,
+                        'limit'                   => $limit_times,
+                    ];
+                    $url   = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+                } else {
+                    $url = '';
+                    foreach ($setting['product_info'] as $k => $product_item) {
+                        $param = [
+                            'uid'                     => $this->uid,
+                            'distribution_channel_id' => $this->distribution_channel_id,
+                            'product_id'              => $product_item['product_id'],
+                            'activity_id'             => $activity_info->id,
+                            'fromtype'                => $from,
+                            'pay_redirect_url'        => $redirect_url,
+                            'limit'                   => $product_item['limit'],
+                        ];
+                        if ($k == 0) {
+                            $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+                        }
+                        $pay_option_list[$k]['url'] = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+                    }
+                }
+                return view($page, ['url'      => $url, 'code' => 0, 'img' => $imgs, 'bg_color' => $bg_color, 'tip' => $tip, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
+                                    'end_time' => date('Y年m月d日', strtotime($activity_info->end_time)), 'price' => $price, 'given' => $given, 'pay_option_list' => $pay_option_list, 'tip_list' => $tip_list]);
+            } else if (time() <= strtotime($activity_info->start_time)) {
+                return view($page, ['url'      => 'javascript:void(0)', 'code' => 1, 'img' => $imgs, 'bg_color' => $bg_color, 'tip' => $tip, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
+                                    'end_time' => date('Y年m月d日', strtotime($activity_info->end_time)), 'price' => $price, 'given' => $given, 'pay_option_list' => $pay_option_list, 'tip_list' => $tip_list]);
+            } else {
+                return view($page, ['url'      => 'javascript:void(0)', 'code' => 2, 'img' => $imgs, 'bg_color' => $bg_color, 'tip' => $tip, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
+                                    'end_time' => date('Y年m月d日', strtotime($activity_info->end_time)), 'price' => $price, 'given' => $given, 'pay_option_list' => $pay_option_list, 'tip_list' => $tip_list]);
+            }
+        }
+        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+        return redirect()->to($default_url);
+    }
+
+    public function commonActivityV2(Request $request)
+    {
+        $token                          = $request->get('token');
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $activity_info                  = ActivityService::getByToken($token);
+        $default_url                    = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+        if (!$activity_info) return redirect()->to($default_url);
+        if (!in_array($activity_info->create_type, [1, 2, 3, 4])) {
+            return redirect()->to($default_url);
+        }
+        //内部站点的活动
+        if ($activity_info->create_type == 2 && !isInnerSites($this->distribution_channel_id)) {
+            return redirect()->to($default_url);
+        }
+        //外部站点活动
+        if ($activity_info->create_type == 3 && isInnerSites($this->distribution_channel_id)) {
+            return redirect()->to($default_url);
+        }
+        //单独站点
+        if ($activity_info->create_type == 7 && $this->distribution_channel_id != $activity_info->distribution_channel_id) {
+            return redirect()->to($default_url);
+        }
+        $setting      = json_decode($activity_info->setting, 1);
+        $product_info = $setting['products'];
+        //$product_info = stripslashes($product_info);
+        //$product_info = json_decode($product_info,1);
+        if (!$product_info) {
+            return redirect()->to($default_url);
+        }
+        $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
+        if ($request->get('redirect_url')) {
+            $redirect_url = $request->input('redirect_url');
+            $redirect_url = urldecode($redirect_url);
+        }
+
+        $from     = $request->get('fromtype', 'main');
+        $count    = count($product_info);
+        $bg_color = $setting['page_bd_color'];
+        //统计
+        $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+        $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+        $uv_key        = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+        $pv_key        = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+
+        if ($count > 5 || $count < 1) return redirect()->to($default_url);
+        if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
+            Redis::sadd($uv_key, $this->uid);
+            Redis::hincrby($pv_key, date('Y-m-d'), 1);
+            $activity_status = 0;
+        } else if (time() <= strtotime($activity_info->start_time)) {
+            $activity_status = 1;
+        } else {
+            $activity_status = 2;
+        }
+        $tips                   = explode("\n", $setting['rule']);
+        $imgs                   = [
+            'page_bd_img'        => $setting['page_bd_img'],
+            'page_btn_pre_img'   => $setting['page_btn_pre_img'],
+            'page_btn_doing_img' => $setting['page_btn_doing_img'],
+            'page_btn_end_img'   => $setting['page_btn_end_img']
+        ];
+        $title                  = $activity_info->name;
+        $page                   = 'pay.activity-template.commonTemplate';
+        $page_config            = [];
+        $default_select_product = $product_info[0]['id'];
+        foreach ($product_info as $value) {
+            if ($value['is_default']) $default_select_product = $value['id'];
+        }
+        $default_select_product_link = '';
+        foreach ($product_info as $item) {
+            $param = [
+                'uid'                     => $this->uid,
+                'distribution_channel_id' => $this->distribution_channel_id,
+                'product_id'              => $item['id'],
+                'activity_id'             => $activity_info->id,
+                'fromtype'                => $from,
+                'pay_redirect_url'        => $redirect_url,
+                'limit'                   => isset($item['limit_times']) ? $item['limit_times'] : 100,
+            ];
+            if ($activity_status == 0) {
+                $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+            } else {
+                $url = 'javascript:void(0)';
+            }
+            $page_config[] = [
+                'unselected_img' => $item['unselected_img'],
+                'selected_img'   => $item['selected_img'],
+                'url'            => $url,
+                'is_select'      => $item['id'] == $default_select_product ? 1 : 0
+            ];
+            if ($item['id'] == $default_select_product) {
+                $default_select_product_link = $url;
+            }
+        }
+
+        $data = ['code'         => $activity_status, 'img' => $imgs,
+                 'bg_color'     => $bg_color, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
+                 'end_time'     => date('Y年m月d日', strtotime($activity_info->end_time)), 'tips' => $tips,
+                 'page_config'  => $page_config, 'title' => $title,
+                 'default_link' => $default_select_product_link
+        ];
+
+        return view($page, $data);
+
+    }
+
+    private function getPayUrlByChannelId()
+    {
+        $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
+        $pay_url = getPayUrl($channel->pay_merchant_id);
+        return $pay_url;
+    }
+
+    public function pageSpreadActivity(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $activity_id                    = 49365;
+        $product_id                     = 14835;
+        $from                           = $request->input('fromtype', 'main');
+        $uv_key_format                  = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+        $pv_key_format                  = 'activity:%s:distribution_channel_id:%s:pv';
+        $uv_key                         = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
+        $pv_key                         = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
+
+        $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
+        if ($request->get('redirect_url')) {
+            $redirect_url = $request->get('redirect_url');
+            $redirect_url = urldecode($redirect_url);
+        }
+        $limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
+
+        Redis::sadd($uv_key, $this->uid);
+        Redis::hincrby($pv_key, date('Y-m-d'), 1);
+        $param       = [
+            'uid'                     => $this->uid,
+            'distribution_channel_id' => $this->distribution_channel_id,
+            'product_id'              => $product_id,
+            'activity_id'             => $activity_id,
+            'fromtype'                => $from,
+            'pay_redirect_url'        => $redirect_url,
+            'limit'                   => 1,
+        ];
+        $url         = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+        $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 18, 'given' => 10, 'get' => 2800, 'limit' => 1];
+        if ($limit_status) {
+            //充值过了
+            $result_data = ['url' => 'javascript:void(0)', 'class' => 'unpay', 'text' => '充值次数已达上限', 'price' => 18, 'given' => 10, 'get' => '2800', 'limit' => 1];
+        }
+        return view('pay.activity.pageSpreadAvtivity', $result_data);
+    }
+
+    public function channelYearNew288(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $id                             = 53536;
+        $activity_info                  = ActivityService::getById($id);
+        if ($activity_info && $activity_info->product_id) {
+            $from          = $request->input('fromtype', 'main');
+            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+            $uv_key        = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+            $pv_key        = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+            Redis::sadd($uv_key, $this->uid);
+            Redis::hincrby($pv_key, date('Y-m-d'), 1);
+
+            $param   = [
+                'uid'                     => $this->uid,
+                'distribution_channel_id' => $this->distribution_channel_id,
+                'product_id'              => $activity_info->product_id,
+                'activity_id'             => $activity_info->id,
+                'fromtype'                => $from,
+                'limit'                   => 0,
+                'pay_redirect_url'        => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
+            ];
+            $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
+            $pay_url = getPayUrl($channel->pay_merchant_id);
+            $url     = $pay_url . '?' . http_build_query($param);
+            return view('pay.activity.channelYearNew288', ['url' => $url]);
+        }
+        $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
+        return redirect()->to($url);
+    }
+
+    public function pageSpreadActivity28(Request $request)
+    {
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $activity_id                    = 60510;
+        $product_id                     = 15786;
+        $from                           = $request->input('fromtype', 'main');
+        $uv_key_format                  = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+        $pv_key_format                  = 'activity:%s:distribution_channel_id:%s:pv';
+        $uv_key                         = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
+        $pv_key                         = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
+
+        $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
+        if ($request->get('redirect_url')) {
+            $redirect_url = $request->get('redirect_url');
+            $redirect_url = urldecode($redirect_url);
+        }
+        //$limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
+
+        Redis::sadd($uv_key, $this->uid);
+        Redis::hincrby($pv_key, date('Y-m-d'), 1);
+        $param       = [
+            'uid'                     => $this->uid,
+            'distribution_channel_id' => $this->distribution_channel_id,
+            'product_id'              => $product_id,
+            'activity_id'             => $activity_id,
+            'fromtype'                => $from,
+            'pay_redirect_url'        => $redirect_url,
+            'limit'                   => 1,
+        ];
+        $url         = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
+        $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 28, 'given' => 28, 'get' => 5600, 'limit' => 0];
+        return view('pay.activity.pageSpreadAvtivity', $result_data);
+    }
+
+}

+ 65 - 0
app/Http/Controllers/QuickApp/Activity/Transformers/ReBuildData.php

@@ -0,0 +1,65 @@
+<?php
+
+
+namespace App\Http\Controllers\QuickApp\Activity\Transformers;
+
+
+class ReBuildData
+{
+    /**
+     * 组装活动详情页数据
+     * @param $param
+     * @return array
+     */
+    public function buildActivityDetail($param)
+    {
+        $activity = $param['activity'];
+        $result   = [
+            'uid'         => $param['uid'],
+            'name'        => getProp($activity, 'name'),
+            'startTime'   => getProp($activity, 'start_time'),
+            'endTime'     => getProp($activity, 'end_time'),
+            'from'        => $param['from'],
+            'activityId'  => getProp($activity, 'id'),
+            'payChannels' => [
+                'ali'    => 1,
+                'wechat' => 1,
+            ],
+            'products'    => $this->buildProducts($param['products'], $param['settingProducts'])
+        ];
+
+        return $result;
+    }
+
+    /**
+     * @param $products
+     * @param $settingProducts
+     * @return array
+     */
+    private function buildProducts($products, $settingProducts)
+    {
+        if (empty($products) || empty($settingProducts)) {
+            return [];
+        }
+
+        $result = [];
+        foreach ($settingProducts as $settingProduct) {
+            // 获取基本信息
+            $productId = getProp($settingProduct, 'product_id');
+            $limit     = getProp($settingProduct, 'limit');
+
+            // 支付产品信息
+            $product = collect($products)->firstWhere('id', $productId);
+
+            $result[] = [
+                'product_id' => $productId,
+                'limit'      => $limit,
+                'type'       => getProp($limit, 'type'),
+                'price'      => getProp($product, 'price'),
+                'total'      => getProp($product, 'given'),
+            ];
+        }
+
+        return $result;
+    }
+}

+ 4 - 1
app/Http/Routes/QuickApp/QuickAppRoutes.php

@@ -31,7 +31,7 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
 
         // 相似推荐
         Route::get('books/similar', 'Book\BookController@similarRecom');
-        
+
         //排行榜
         Route::get('books/rank', 'Book\BookController@rank');
     });
@@ -103,6 +103,9 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
         Route::get('shortcut/add', 'User\ShortcutController@add');
         //删除快捷方式
         Route::get('shortcut/delete', 'User\ShortcutController@delete');
+
+        //自定义活动
+        Route::get('activity/detail', 'Activity\ActivityController@channelCustomActivityV3');
     });
 
     // 推送

+ 9 - 3
app/Modules/Product/Models/Product.php

@@ -7,11 +7,11 @@ use Illuminate\Database\Eloquent\Model;
 class Product extends Model
 {
     protected $table = 'products';
-    protected $fillable = ['price', 'type', 'given', 'is_default', 'is_enabled', 'sequence','switch_to'];
+    protected $fillable = ['price', 'type', 'given', 'is_default', 'is_enabled', 'sequence', 'switch_to'];
 
     public static function getChargeProduct($template_type)
     {
-        return self::whereIn('products.type', ['TICKET_RECHARGE', 'YEAR_ORDER','NEW_USER'])
+        return self::whereIn('products.type', ['TICKET_RECHARGE', 'YEAR_ORDER', 'NEW_USER'])
             ->where('is_enabled', 1)
             ->where('template_type', $template_type)
             ->select(
@@ -33,11 +33,17 @@ class Product extends Model
      */
     public static function getProductGivenAmount($product_id)
     {
-        return self::where('id', $product_id)->select('given','price')->first();
+        return self::where('id', $product_id)->select('given', 'price')->first();
     }
 
     static function detail($id)
     {
         return self::find($id);
     }
+
+    public static function getProductsByIds($ids)
+    {
+        $result = self::whereIn('id', $ids)->get();
+        return $result ? $result->toArray() : [];
+    }
 }

+ 4 - 0
app/Modules/Product/Services/ProductService.php

@@ -32,6 +32,10 @@ class ProductService
         return $res;
     }
 
+    public static function getProductsByIds($ids) {
+        return Product::getProductsByIds($ids);
+    }
+
     public static function updateProductDefault($id, $default) {
         if($default){
             Product::where('id','!=',0)->update(['is_default'=>0]);