ActivityController.php 31 KB

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