ActivityController.php 31 KB

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