ActivityController.php 31 KB

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