ActivityController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. if (!$activityId || !getProp($activity, 'setting') || (int)getProp($activity, 'create_type') !== 5 ||
  187. (int)getProp($activity, 'distribution_channel_id') !== $channelId) {
  188. Utils::throwError(ErrorConst::ACTIVITY_NOT_FOUND);
  189. }
  190. // 获取用户信息
  191. $user = User::getUser($this->uid);
  192. $sendOrderId = getProp($user, 'send_order_id');
  193. // 用户派单的信息是否跟创建该活动的子账号一致
  194. // $qappAccountId = (int)getProp($activity, 'qapp_account_id');
  195. // if ($qappAccountId && $sendOrderId) {
  196. // $sendOrder = QappSendOrder::getSendOrderById($sendOrderId);
  197. // $qappAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
  198. // if ($qappAccountId !== (int)getProp($qappAccount, 'id')) {
  199. // Utils::throwError(ErrorConst::ACTIVITY_INVALID);
  200. // }
  201. // }
  202. // 活动开始时间判断
  203. if (getProp($activity, 'start_time') > date('Y-m-d H:i:s')) {
  204. Utils::throwError(ErrorConst::ACTIVITY_NOT_START);
  205. }
  206. // 活动结束时间判断
  207. if (getProp($activity, 'end_time') < date('Y-m-d H:i:s')) {
  208. Utils::throwError(ErrorConst::ACTIVITY_IS_END);
  209. }
  210. // 活动pv、uv统计
  211. $date = date('Y-m-d');
  212. ActivityCache::incrActivityPv($activityId, $date);
  213. ActivityCache::zAddActivityUv($activityId, $date, $uid);
  214. // 获取支付相关信息
  215. $settingJson = getProp($activity, 'setting');
  216. $setting = json_decode($settingJson, true);
  217. $settingProducts = getProp($setting, 'product_info');
  218. $productIds = array_column($settingProducts, 'product_id');
  219. $products = ProductService::getProductsByIds($productIds);
  220. // 组装返回数据
  221. $data = compact('uid', 'activity', 'products', 'setting', 'settingProducts', 'from');
  222. return $this->success($data, [new ReBuildData(), 'buildActivityDetail']);
  223. }
  224. public function channelCustomActivityV2(Request $request)
  225. {
  226. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  227. $token = $request->get('token');
  228. $activity_info = ActivityService::getByToken($token);
  229. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting) &&
  230. $activity_info->create_type == 5 &&
  231. $activity_info->distribution_channel_id == $this->distribution_channel_id
  232. ) {
  233. $setting = json_decode($activity_info->setting, 1);
  234. $select_options = 1;
  235. $page = 'pay.activity-template.channelCommonTemplate';
  236. if (isset($setting['product_info']) && count($setting['product_info']) > 1) {
  237. $select_options = 2;
  238. $page = 'pay.activity-template.channelCommonTemplate2';
  239. }
  240. $from = $request->input('fromtype', 'main');
  241. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  242. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  243. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  244. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  245. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  246. if ($request->input('redirect_url')) {
  247. $redirect_url = $request->input('redirect_url');
  248. $redirect_url = urldecode($redirect_url);
  249. }
  250. $imgs = [
  251. 'page_bd_img' => $setting['page_bd_img'],
  252. 'page_btn_pre_img' => $setting['page_btn_pre_img'],
  253. 'page_btn_doing_img' => $setting['page_btn_doing_img'],
  254. 'page_btn_end_img' => $setting['page_btn_end_img']
  255. ];
  256. $bg_color = $setting['page_bd_color'];
  257. $product_id = $activity_info->product_id;
  258. $product_info = ProductService::getProductSingle($product_id);
  259. $limit_times = (!isset($setting['limit_times']) || !$setting['limit_times']) ? 100 : $setting['limit_times'];
  260. $tip = '';
  261. if ($limit_times != '100' && $product_info->type != 'YEAR_ORDER') {
  262. $tip = sprintf('活动期间充%s送%s限购%s次', (float)$product_info->price, $product_info->given / 100, $limit_times);
  263. }
  264. $price = $product_info->price;
  265. $given = $product_info->given / 100;
  266. $tip_list = [];
  267. $pay_option_list = [];
  268. if ($select_options == 2) {
  269. foreach ($setting['product_info'] as $product_item) {
  270. $product_detail = ProductService::getProductSingle($product_item['product_id']);
  271. if ($product_item['limit']) {
  272. $tip_list[] = sprintf('活动期间充%s送%s限购%s次', (float)$product_detail->price, $product_detail->given / 100, $product_item['limit']);
  273. } else {
  274. $tip_list[] = sprintf('活动期间充%s送%s不限次数', (float)$product_detail->price, $product_detail->given / 100);
  275. }
  276. $pay_option_list[] = [
  277. 'price' => (float)$product_detail->price,
  278. 'given' => $product_detail->given / 100,
  279. 'total' => (int)($product_detail->price * 100) + $product_detail->given,
  280. 'url' => 'javascript:void(0)'
  281. ];
  282. }
  283. }
  284. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  285. Redis::sadd($uv_key, $this->uid);
  286. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  287. if ($select_options == 1) {
  288. $param = [
  289. 'uid' => $this->uid,
  290. 'distribution_channel_id' => $this->distribution_channel_id,
  291. 'product_id' => $product_id,
  292. 'activity_id' => $activity_info->id,
  293. 'fromtype' => $from,
  294. 'pay_redirect_url' => $redirect_url,
  295. 'limit' => $limit_times,
  296. ];
  297. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  298. } else {
  299. $url = '';
  300. foreach ($setting['product_info'] as $k => $product_item) {
  301. $param = [
  302. 'uid' => $this->uid,
  303. 'distribution_channel_id' => $this->distribution_channel_id,
  304. 'product_id' => $product_item['product_id'],
  305. 'activity_id' => $activity_info->id,
  306. 'fromtype' => $from,
  307. 'pay_redirect_url' => $redirect_url,
  308. 'limit' => $product_item['limit'],
  309. ];
  310. if ($k == 0) {
  311. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  312. }
  313. $pay_option_list[$k]['url'] = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  314. }
  315. }
  316. 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)),
  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 if (time() <= strtotime($activity_info->start_time)) {
  319. 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)),
  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. } else {
  322. 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)),
  323. '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]);
  324. }
  325. }
  326. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  327. return redirect()->to($default_url);
  328. }
  329. public function commonActivityV2(Request $request)
  330. {
  331. $token = $request->get('token');
  332. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  333. $activity_info = ActivityService::getByToken($token);
  334. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  335. if (!$activity_info) return redirect()->to($default_url);
  336. if (!in_array($activity_info->create_type, [1, 2, 3, 4])) {
  337. return redirect()->to($default_url);
  338. }
  339. //内部站点的活动
  340. if ($activity_info->create_type == 2 && !isInnerSites($this->distribution_channel_id)) {
  341. return redirect()->to($default_url);
  342. }
  343. //外部站点活动
  344. if ($activity_info->create_type == 3 && isInnerSites($this->distribution_channel_id)) {
  345. return redirect()->to($default_url);
  346. }
  347. //单独站点
  348. if ($activity_info->create_type == 7 && $this->distribution_channel_id != $activity_info->distribution_channel_id) {
  349. return redirect()->to($default_url);
  350. }
  351. $setting = json_decode($activity_info->setting, 1);
  352. $product_info = $setting['products'];
  353. //$product_info = stripslashes($product_info);
  354. //$product_info = json_decode($product_info,1);
  355. if (!$product_info) {
  356. return redirect()->to($default_url);
  357. }
  358. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  359. if ($request->get('redirect_url')) {
  360. $redirect_url = $request->input('redirect_url');
  361. $redirect_url = urldecode($redirect_url);
  362. }
  363. $from = $request->get('fromtype', 'main');
  364. $count = count($product_info);
  365. $bg_color = $setting['page_bd_color'];
  366. //统计
  367. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  368. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  369. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  370. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  371. if ($count > 5 || $count < 1) return redirect()->to($default_url);
  372. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  373. Redis::sadd($uv_key, $this->uid);
  374. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  375. $activity_status = 0;
  376. } else if (time() <= strtotime($activity_info->start_time)) {
  377. $activity_status = 1;
  378. } else {
  379. $activity_status = 2;
  380. }
  381. $tips = explode("\n", $setting['rule']);
  382. $imgs = [
  383. 'page_bd_img' => $setting['page_bd_img'],
  384. 'page_btn_pre_img' => $setting['page_btn_pre_img'],
  385. 'page_btn_doing_img' => $setting['page_btn_doing_img'],
  386. 'page_btn_end_img' => $setting['page_btn_end_img']
  387. ];
  388. $title = $activity_info->name;
  389. $page = 'pay.activity-template.commonTemplate';
  390. $page_config = [];
  391. $default_select_product = $product_info[0]['id'];
  392. foreach ($product_info as $value) {
  393. if ($value['is_default']) $default_select_product = $value['id'];
  394. }
  395. $default_select_product_link = '';
  396. foreach ($product_info as $item) {
  397. $param = [
  398. 'uid' => $this->uid,
  399. 'distribution_channel_id' => $this->distribution_channel_id,
  400. 'product_id' => $item['id'],
  401. 'activity_id' => $activity_info->id,
  402. 'fromtype' => $from,
  403. 'pay_redirect_url' => $redirect_url,
  404. 'limit' => isset($item['limit_times']) ? $item['limit_times'] : 100,
  405. ];
  406. if ($activity_status == 0) {
  407. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  408. } else {
  409. $url = 'javascript:void(0)';
  410. }
  411. $page_config[] = [
  412. 'unselected_img' => $item['unselected_img'],
  413. 'selected_img' => $item['selected_img'],
  414. 'url' => $url,
  415. 'is_select' => $item['id'] == $default_select_product ? 1 : 0
  416. ];
  417. if ($item['id'] == $default_select_product) {
  418. $default_select_product_link = $url;
  419. }
  420. }
  421. $data = ['code' => $activity_status, 'img' => $imgs,
  422. 'bg_color' => $bg_color, 'start_time' => date('Y年m月d日', strtotime($activity_info->start_time)),
  423. 'end_time' => date('Y年m月d日', strtotime($activity_info->end_time)), 'tips' => $tips,
  424. 'page_config' => $page_config, 'title' => $title,
  425. 'default_link' => $default_select_product_link
  426. ];
  427. return view($page, $data);
  428. }
  429. private function getPayUrlByChannelId()
  430. {
  431. $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
  432. $pay_url = getPayUrl($channel->pay_merchant_id);
  433. return $pay_url;
  434. }
  435. public function pageSpreadActivity(Request $request)
  436. {
  437. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  438. $activity_id = 49365;
  439. $product_id = 14835;
  440. $from = $request->input('fromtype', 'main');
  441. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  442. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  443. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  444. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  445. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  446. if ($request->get('redirect_url')) {
  447. $redirect_url = $request->get('redirect_url');
  448. $redirect_url = urldecode($redirect_url);
  449. }
  450. $limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
  451. Redis::sadd($uv_key, $this->uid);
  452. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  453. $param = [
  454. 'uid' => $this->uid,
  455. 'distribution_channel_id' => $this->distribution_channel_id,
  456. 'product_id' => $product_id,
  457. 'activity_id' => $activity_id,
  458. 'fromtype' => $from,
  459. 'pay_redirect_url' => $redirect_url,
  460. 'limit' => 1,
  461. ];
  462. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  463. $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 18, 'given' => 10, 'get' => 2800, 'limit' => 1];
  464. if ($limit_status) {
  465. //充值过了
  466. $result_data = ['url' => 'javascript:void(0)', 'class' => 'unpay', 'text' => '充值次数已达上限', 'price' => 18, 'given' => 10, 'get' => '2800', 'limit' => 1];
  467. }
  468. return view('pay.activity.pageSpreadAvtivity', $result_data);
  469. }
  470. public function channelYearNew288(Request $request)
  471. {
  472. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  473. $id = 53536;
  474. $activity_info = ActivityService::getById($id);
  475. if ($activity_info && $activity_info->product_id) {
  476. $from = $request->input('fromtype', 'main');
  477. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  478. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  479. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  480. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  481. Redis::sadd($uv_key, $this->uid);
  482. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  483. $param = [
  484. 'uid' => $this->uid,
  485. 'distribution_channel_id' => $this->distribution_channel_id,
  486. 'product_id' => $activity_info->product_id,
  487. 'activity_id' => $activity_info->id,
  488. 'fromtype' => $from,
  489. 'limit' => 0,
  490. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  491. ];
  492. $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
  493. $pay_url = getPayUrl($channel->pay_merchant_id);
  494. $url = $pay_url . '?' . http_build_query($param);
  495. return view('pay.activity.channelYearNew288', ['url' => $url]);
  496. }
  497. $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  498. return redirect()->to($url);
  499. }
  500. public function pageSpreadActivity28(Request $request)
  501. {
  502. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  503. $activity_id = 60510;
  504. $product_id = 15786;
  505. $from = $request->input('fromtype', 'main');
  506. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  507. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  508. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  509. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  510. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  511. if ($request->get('redirect_url')) {
  512. $redirect_url = $request->get('redirect_url');
  513. $redirect_url = urldecode($redirect_url);
  514. }
  515. //$limit_status = OrderService::userParticipateActivityLimit($this->uid, $activity_id, $product_id, 1);
  516. Redis::sadd($uv_key, $this->uid);
  517. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  518. $param = [
  519. 'uid' => $this->uid,
  520. 'distribution_channel_id' => $this->distribution_channel_id,
  521. 'product_id' => $product_id,
  522. 'activity_id' => $activity_id,
  523. 'fromtype' => $from,
  524. 'pay_redirect_url' => $redirect_url,
  525. 'limit' => 1,
  526. ];
  527. $url = $this->getPayUrlByChannelId() . '?' . http_build_query($param);
  528. $result_data = ['url' => $url, 'class' => 'pay', 'text' => '立即充值', 'price' => 28, 'given' => 28, 'get' => 5600, 'limit' => 0];
  529. return view('pay.activity.pageSpreadAvtivity', $result_data);
  530. }
  531. }