ActivityController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Activity;
  3. use App\Cache\Activity\ActivityCache;
  4. use App\Consts\ErrorConst;
  5. use App\Http\Controllers\QuickApp\Activity\Transformers\ReBuildData;
  6. use App\Libs\ApiResponse;
  7. use App\Libs\Utils;
  8. use App\Modules\Activity\Services\ActivityService;
  9. use App\Modules\Channel\Services\ChannelService;
  10. use App\Modules\Product\Services\ProductService;
  11. use App\Modules\SendOrder\Models\QappSendOrder;
  12. use App\Modules\SendOrder\Models\QuickAppSendOrder;
  13. use App\Modules\Subscribe\Services\OrderService;
  14. use App\Modules\User\Models\QappChannelAccount;
  15. use App\Modules\User\Models\User;
  16. use Illuminate\Http\Request;
  17. use App\Http\Controllers\QuickApp\BaseController;
  18. use Redis;
  19. use DB;
  20. use Log;
  21. class ActivityController extends BaseController
  22. {
  23. use ApiResponse;
  24. //渠道自定义活动 可以多少充值
  25. public function channelCustomActivity(Request $request)
  26. {
  27. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  28. $token = $request->input('token');
  29. $activity_info = ActivityService::getByToken($token);
  30. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
  31. if ($activity_info && $activity_info->product_id) {
  32. $customer_activity_info = DB::table('channel_custom_activity')->where('product_id', $activity_info->product_id)->select('setting')->first();
  33. if ($customer_activity_info && $customer_activity_info->setting) {
  34. $img = json_decode($customer_activity_info->setting, 1)['img'];
  35. }
  36. $from = $request->input('fromtype', 'main');
  37. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  38. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  39. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  40. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  41. Redis::sadd($uv_key, $this->uid);
  42. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  43. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  44. //渠道不符合
  45. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  46. 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)]);
  47. }
  48. //活动未开始
  49. if (time() < strtotime($activity_info->start_time)) {
  50. 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)]);
  51. }
  52. //活动结束
  53. if (time() > strtotime($activity_info->end_time)) {
  54. 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)]);
  55. }
  56. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  57. $param = [
  58. 'uid' => $this->uid,
  59. 'distribution_channel_id' => $this->distribution_channel_id,
  60. 'product_id' => $activity_info->product_id,
  61. 'activity_id' => $activity_info->id,
  62. 'fromtype' => $from,
  63. 'limit' => 100,
  64. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  65. ];
  66. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  67. 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)]);
  68. }
  69. }
  70. 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)]);
  71. }
  72. public function commonActivity(Request $request)
  73. {
  74. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  75. $token = $request->input('token');
  76. $activity_info = ActivityService::getByToken($token);
  77. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
  78. $imgs = json_decode($activity_info->setting, 1);
  79. $from = $request->input('fromtype', 'main');
  80. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  81. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  82. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  83. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  84. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  85. if ($request->input('redirect_url')) {
  86. $redirect_url = $request->input('redirect_url');
  87. $redirect_url = urldecode($redirect_url);
  88. }
  89. $product_id = $activity_info->product_id;
  90. if ($activity_info->id == 6000) {
  91. $imgs['page_bd_img'] = 'https://cdn-novel.iycdm.com/h5/activity-2019-04-29/bg2.jpg';
  92. $product_id = 5788;
  93. }
  94. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  95. Redis::sadd($uv_key, $this->uid);
  96. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  97. $param = [
  98. 'uid' => $this->uid,
  99. 'distribution_channel_id' => $this->distribution_channel_id,
  100. 'product_id' => $product_id,
  101. 'activity_id' => $activity_info->id,
  102. 'fromtype' => $from,
  103. 'pay_redirect_url' => $redirect_url,
  104. 'limit' => 100,
  105. ];
  106. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  107. return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
  108. } else if (time() <= strtotime($activity_info->start_time)) {
  109. return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
  110. } else {
  111. return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
  112. }
  113. }
  114. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  115. return redirect()->to($default_url);
  116. }
  117. public function crmActivity(Request $request)
  118. {
  119. $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  120. $token = $request->input('token');
  121. if (!$token) {
  122. return redirect()->to($default_url);
  123. }
  124. $activity_info = ActivityService::getByToken($token);
  125. if (!$activity_info) {
  126. return redirect()->to($default_url);
  127. }
  128. $crm = $request->get('crm', 'crm');
  129. $img = \GuzzleHttp\json_decode($activity_info->setting, 1);
  130. $param = [
  131. 'uid' => $this->uid,
  132. 'distribution_channel_id' => $this->distribution_channel_id,
  133. 'product_id' => $activity_info->product_id,
  134. 'activity_id' => $activity_info->id,
  135. 'fromtype' => 'crm',
  136. 'pay_redirect_url' => $default_url . 'person',
  137. 'limit' => 100,
  138. 'crm' => $crm
  139. ];
  140. $product_info = ProductService::getProductSingle($activity_info->product_id);
  141. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  142. $fee = $product_info->price * 100 + $product_info->given;
  143. return view('crm.crmActivity', ['url' => $url, 'img' => $img['button'], 'fee' => $fee]);
  144. }
  145. public function crmYearActivity(Request $request)
  146. {
  147. $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  148. $activity_info = ActivityService::getById(11378);
  149. if (!$activity_info) {
  150. return redirect()->to($default_url);
  151. }
  152. $crm = $request->get('crm', 'crm_year_activity');
  153. $param = [
  154. 'uid' => $this->uid,
  155. 'distribution_channel_id' => $this->distribution_channel_id,
  156. 'product_id' => $activity_info->product_id,
  157. 'activity_id' => $activity_info->id,
  158. 'fromtype' => 'crm',
  159. 'pay_redirect_url' => $default_url . 'person',
  160. 'limit' => 100,
  161. 'crm' => $crm
  162. ];
  163. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  164. $is_get = 0;
  165. $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_info->id)->count();
  166. if ($discount_coupon) {
  167. $is_get = 1;
  168. } else {
  169. DB::table('discount_coupons')->insert([
  170. 'uid' => $this->uid,
  171. 'activity_id' => $activity_info->id,
  172. 'created_at' => date('Y-m-d H:i:s'),
  173. 'updated_at' => date('Y-m-d H:i:s')
  174. ]);
  175. }
  176. return view('crm.crmYearActivityV2', ['url' => $url, 'is_get' => $is_get]);
  177. }
  178. public function channelCustomActivityV3(Request $request)
  179. {
  180. $uid = $this->uid;
  181. $token = $request->get('token');
  182. $from = $request->input('fromtype', 'main');
  183. $channelId = (int)$this->distribution_channel_id;
  184. $activity = ActivityService::getByToken($token);
  185. $activityId = getProp($activity, 'id');
  186. myLog('activityDetail')->info('', compact('uid', 'token', 'channelId', 'activity'));
  187. if (!$activityId || !getProp($activity, 'setting') || (int)getProp($activity, 'create_type') !== 5 ||
  188. (int)getProp($activity, 'distribution_channel_id') !== $channelId) {
  189. Utils::throwError(ErrorConst::ACTIVITY_NOT_FOUND);
  190. }
  191. // 获取用户信息
  192. $user = User::getUser($this->uid);
  193. $sendOrderId = getProp($user, 'send_order_id');
  194. // 用户派单的信息是否跟创建该活动的子账号一致
  195. $qappAccountId = (int)getProp($activity, 'qapp_account_id');
  196. if ($qappAccountId && $sendOrderId) {
  197. $sendOrder = QappSendOrder::getSendOrderById($sendOrderId);
  198. $qappAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
  199. if ($qappAccountId !== (int)getProp($qappAccount, 'id')) {
  200. Utils::throwError(ErrorConst::ACTIVITY_INVALID);
  201. }
  202. }
  203. // 活动开始时间判断
  204. if (getProp($activity, 'start_time') > date('Y-m-d H:i:s')) {
  205. Utils::throwError(ErrorConst::ACTIVITY_NOT_START);
  206. }
  207. // 活动结束时间判断
  208. if (getProp($activity, 'end_time') < date('Y-m-d H:i:s')) {
  209. Utils::throwError(ErrorConst::ACTIVITY_IS_END);
  210. }
  211. // 活动pv、uv统计
  212. $date = date('Y-m-d');
  213. ActivityCache::incrActivityPv($activityId, $date);
  214. ActivityCache::zAddActivityUv($activityId, $date, $uid);
  215. // 获取支付相关信息
  216. $settingJson = getProp($activity, 'setting');
  217. $setting = json_decode($settingJson, true);
  218. $settingProducts = getProp($setting, 'product_info');
  219. $productIds = array_column($settingProducts, 'product_id');
  220. $products = ProductService::getProductsByIds($productIds);
  221. // 组装返回数据
  222. $data = compact('uid', 'activity', 'products', 'setting', 'settingProducts', 'from');
  223. return $this->success($data, [new ReBuildData(), 'buildActivityDetail']);
  224. }
  225. public function channelCustomActivityV2(Request $request)
  226. {
  227. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  228. $token = $request->get('token');
  229. $activity_info = ActivityService::getByToken($token);
  230. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting) &&
  231. $activity_info->create_type == 5 &&
  232. $activity_info->distribution_channel_id == $this->distribution_channel_id
  233. ) {
  234. $setting = json_decode($activity_info->setting, 1);
  235. $select_options = 1;
  236. $page = 'pay.activity-template.channelCommonTemplate';
  237. if (isset($setting['product_info']) && count($setting['product_info']) > 1) {
  238. $select_options = 2;
  239. $page = 'pay.activity-template.channelCommonTemplate2';
  240. }
  241. $from = $request->input('fromtype', 'main');
  242. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  243. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  244. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  245. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  246. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  247. if ($request->input('redirect_url')) {
  248. $redirect_url = $request->input('redirect_url');
  249. $redirect_url = urldecode($redirect_url);
  250. }
  251. $imgs = [
  252. 'page_bd_img' => $setting['page_bd_img'],
  253. 'page_btn_pre_img' => $setting['page_btn_pre_img'],
  254. 'page_btn_doing_img' => $setting['page_btn_doing_img'],
  255. 'page_btn_end_img' => $setting['page_btn_end_img']
  256. ];
  257. $bg_color = $setting['page_bd_color'];
  258. $product_id = $activity_info->product_id;
  259. $product_info = ProductService::getProductSingle($product_id);
  260. $limit_times = (!isset($setting['limit_times']) || !$setting['limit_times']) ? 100 : $setting['limit_times'];
  261. $tip = '';
  262. if ($limit_times != '100' && $product_info->type != 'YEAR_ORDER') {
  263. $tip = sprintf('活动期间充%s送%s限购%s次', (float)$product_info->price, $product_info->given / 100, $limit_times);
  264. }
  265. $price = $product_info->price;
  266. $given = $product_info->given / 100;
  267. $tip_list = [];
  268. $pay_option_list = [];
  269. if ($select_options == 2) {
  270. foreach ($setting['product_info'] as $product_item) {
  271. $product_detail = ProductService::getProductSingle($product_item['product_id']);
  272. if ($product_item['limit']) {
  273. $tip_list[] = sprintf('活动期间充%s送%s限购%s次', (float)$product_detail->price, $product_detail->given / 100, $product_item['limit']);
  274. } else {
  275. $tip_list[] = sprintf('活动期间充%s送%s不限次数', (float)$product_detail->price, $product_detail->given / 100);
  276. }
  277. $pay_option_list[] = [
  278. 'price' => (float)$product_detail->price,
  279. 'given' => $product_detail->given / 100,
  280. 'total' => (int)($product_detail->price * 100) + $product_detail->given,
  281. 'url' => 'javascript:void(0)'
  282. ];
  283. }
  284. }
  285. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  286. Redis::sadd($uv_key, $this->uid);
  287. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  288. if ($select_options == 1) {
  289. $param = [
  290. 'uid' => $this->uid,
  291. 'distribution_channel_id' => $this->distribution_channel_id,
  292. 'product_id' => $product_id,
  293. 'activity_id' => $activity_info->id,
  294. 'fromtype' => $from,
  295. 'pay_redirect_url' => $redirect_url,
  296. 'limit' => $limit_times,
  297. ];
  298. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  299. } else {
  300. $url = '';
  301. foreach ($setting['product_info'] as $k => $product_item) {
  302. $param = [
  303. 'uid' => $this->uid,
  304. 'distribution_channel_id' => $this->distribution_channel_id,
  305. 'product_id' => $product_item['product_id'],
  306. 'activity_id' => $activity_info->id,
  307. 'fromtype' => $from,
  308. 'pay_redirect_url' => $redirect_url,
  309. 'limit' => $product_item['limit'],
  310. ];
  311. if ($k == 0) {
  312. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  313. }
  314. $pay_option_list[$k]['url'] = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  315. }
  316. }
  317. 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)),
  318. '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]);
  319. } else if (time() <= strtotime($activity_info->start_time)) {
  320. 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)),
  321. '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]);
  322. } else {
  323. 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)),
  324. '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]);
  325. }
  326. }
  327. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  328. return redirect()->to($default_url);
  329. }
  330. public function commonActivityV2(Request $request)
  331. {
  332. $token = $request->get('token');
  333. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  334. $activity_info = ActivityService::getByToken($token);
  335. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  336. if (!$activity_info) return redirect()->to($default_url);
  337. if (!in_array($activity_info->create_type, [1, 2, 3, 4])) {
  338. return redirect()->to($default_url);
  339. }
  340. //内部站点的活动
  341. if ($activity_info->create_type == 2 && !isInnerSites($this->distribution_channel_id)) {
  342. return redirect()->to($default_url);
  343. }
  344. //外部站点活动
  345. if ($activity_info->create_type == 3 && isInnerSites($this->distribution_channel_id)) {
  346. return redirect()->to($default_url);
  347. }
  348. //单独站点
  349. if ($activity_info->create_type == 7 && $this->distribution_channel_id != $activity_info->distribution_channel_id) {
  350. return redirect()->to($default_url);
  351. }
  352. $setting = json_decode($activity_info->setting, 1);
  353. $product_info = $setting['products'];
  354. //$product_info = stripslashes($product_info);
  355. //$product_info = json_decode($product_info,1);
  356. if (!$product_info) {
  357. return redirect()->to($default_url);
  358. }
  359. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  360. if ($request->get('redirect_url')) {
  361. $redirect_url = $request->input('redirect_url');
  362. $redirect_url = urldecode($redirect_url);
  363. }
  364. $from = $request->get('fromtype', 'main');
  365. $count = count($product_info);
  366. $bg_color = $setting['page_bd_color'];
  367. //统计
  368. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  369. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  370. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  371. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  372. if ($count > 5 || $count < 1) return redirect()->to($default_url);
  373. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  374. Redis::sadd($uv_key, $this->uid);
  375. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  376. $activity_status = 0;
  377. } else if (time() <= strtotime($activity_info->start_time)) {
  378. $activity_status = 1;
  379. } else {
  380. $activity_status = 2;
  381. }
  382. $tips = explode("\n", $setting['rule']);
  383. $imgs = [
  384. 'page_bd_img' => $setting['page_bd_img'],
  385. 'page_btn_pre_img' => $setting['page_btn_pre_img'],
  386. 'page_btn_doing_img' => $setting['page_btn_doing_img'],
  387. 'page_btn_end_img' => $setting['page_btn_end_img']
  388. ];
  389. $title = $activity_info->name;
  390. $page = 'pay.activity-template.commonTemplate';
  391. $page_config = [];
  392. $default_select_product = $product_info[0]['id'];
  393. foreach ($product_info as $value) {
  394. if ($value['is_default']) $default_select_product = $value['id'];
  395. }
  396. $default_select_product_link = '';
  397. foreach ($product_info as $item) {
  398. $param = [
  399. 'uid' => $this->uid,
  400. 'distribution_channel_id' => $this->distribution_channel_id,
  401. 'product_id' => $item['id'],
  402. 'activity_id' => $activity_info->id,
  403. 'fromtype' => $from,
  404. 'pay_redirect_url' => $redirect_url,
  405. 'limit' => isset($item['limit_times']) ? $item['limit_times'] : 100,
  406. ];
  407. if ($activity_status == 0) {
  408. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  409. } else {
  410. $url = 'javascript:void(0)';
  411. }
  412. $page_config[] = [
  413. 'unselected_img' => $item['unselected_img'],
  414. 'selected_img' => $item['selected_img'],
  415. 'url' => $url,
  416. 'is_select' => $item['id'] == $default_select_product ? 1 : 0
  417. ];
  418. if ($item['id'] == $default_select_product) {
  419. $default_select_product_link = $url;
  420. }
  421. }
  422. $data = ['code' => $activity_status, 'img' => $imgs,
  423. 'bg_color' => $bg_color, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
  424. 'end_time' => date('Y年m月d日', strtotime($activity_info->end_time)), 'tips' => $tips,
  425. 'page_config' => $page_config, 'title' => $title,
  426. 'default_link' => $default_select_product_link
  427. ];
  428. return view($page, $data);
  429. }
  430. private function getPayUrlByChannelId()
  431. {
  432. $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
  433. $pay_url = getPayUrl($channel->pay_merchant_id);
  434. return $pay_url;
  435. }
  436. public function pageSpreadActivity(Request $request)
  437. {
  438. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  439. $activity_id = 49365;
  440. $product_id = 14835;
  441. $from = $request->input('fromtype', 'main');
  442. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  443. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  444. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  445. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  446. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  447. if ($request->get('redirect_url')) {
  448. $redirect_url = $request->get('redirect_url');
  449. $redirect_url = urldecode($redirect_url);
  450. }
  451. $limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
  452. Redis::sadd($uv_key, $this->uid);
  453. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  454. $param = [
  455. 'uid' => $this->uid,
  456. 'distribution_channel_id' => $this->distribution_channel_id,
  457. 'product_id' => $product_id,
  458. 'activity_id' => $activity_id,
  459. 'fromtype' => $from,
  460. 'pay_redirect_url' => $redirect_url,
  461. 'limit' => 1,
  462. ];
  463. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  464. $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 18, 'given' => 10, 'get' => 2800, 'limit' => 1];
  465. if ($limit_status) {
  466. //充值过了
  467. $result_data = ['url' => 'javascript:void(0)', 'class' => 'unpay', 'text' => '充值次数已达上限', 'price' => 18, 'given' => 10, 'get' => '2800', 'limit' => 1];
  468. }
  469. return view('pay.activity.pageSpreadAvtivity', $result_data);
  470. }
  471. public function channelYearNew288(Request $request)
  472. {
  473. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  474. $id = 53536;
  475. $activity_info = ActivityService::getById($id);
  476. if ($activity_info && $activity_info->product_id) {
  477. $from = $request->input('fromtype', 'main');
  478. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  479. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  480. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  481. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  482. Redis::sadd($uv_key, $this->uid);
  483. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  484. $param = [
  485. 'uid' => $this->uid,
  486. 'distribution_channel_id' => $this->distribution_channel_id,
  487. 'product_id' => $activity_info->product_id,
  488. 'activity_id' => $activity_info->id,
  489. 'fromtype' => $from,
  490. 'limit' => 0,
  491. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  492. ];
  493. $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
  494. $pay_url = getPayUrl($channel->pay_merchant_id);
  495. $url = $pay_url . '?' . http_build_query($param);
  496. return view('pay.activity.channelYearNew288', ['url' => $url]);
  497. }
  498. $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  499. return redirect()->to($url);
  500. }
  501. public function pageSpreadActivity28(Request $request)
  502. {
  503. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  504. $activity_id = 60510;
  505. $product_id = 15786;
  506. $from = $request->input('fromtype', 'main');
  507. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  508. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  509. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  510. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  511. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  512. if ($request->get('redirect_url')) {
  513. $redirect_url = $request->get('redirect_url');
  514. $redirect_url = urldecode($redirect_url);
  515. }
  516. //$limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
  517. Redis::sadd($uv_key, $this->uid);
  518. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  519. $param = [
  520. 'uid' => $this->uid,
  521. 'distribution_channel_id' => $this->distribution_channel_id,
  522. 'product_id' => $product_id,
  523. 'activity_id' => $activity_id,
  524. 'fromtype' => $from,
  525. 'pay_redirect_url' => $redirect_url,
  526. 'limit' => 1,
  527. ];
  528. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  529. $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 28, 'given' => 28, 'get' => 5600, 'limit' => 0];
  530. return view('pay.activity.pageSpreadAvtivity', $result_data);
  531. }
  532. }