ShowPromotion.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\turntable\event;
  11. use think\facade\Db;
  12. /**
  13. * 活动展示
  14. */
  15. class ShowPromotion
  16. {
  17. /**
  18. * 活动展示
  19. * @param array $params
  20. * @return array
  21. */
  22. public function handle($params = [])
  23. {
  24. $data = [
  25. 'shop' => [
  26. [
  27. //插件名称
  28. 'name' => 'turntable',
  29. //店铺端展示分类 shop:营销活动 member:互动营销
  30. 'show_type' => 'member',
  31. //展示主题
  32. 'title' => '幸运抽奖',
  33. //展示介绍
  34. 'description' => '九宫格形式的抽奖',
  35. //展示图标
  36. 'icon' => 'addon/turntable/icon.png',
  37. //跳转链接
  38. 'url' => 'turntable://shop/turntable/lists',
  39. 'summary' => $this->summary($params)
  40. ]
  41. ]
  42. ];
  43. return $data;
  44. }
  45. /**
  46. * 营销活动概况
  47. * @param $params
  48. * @return array
  49. */
  50. private function summary($params)
  51. {
  52. if (empty($params)) {
  53. return [];
  54. }
  55. //获取活动数量
  56. if (isset($params[ 'count' ])) {
  57. $count = model("promotion_games")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'game_type', '=', 'turntable' ] ]);
  58. return [
  59. 'count' => $count
  60. ];
  61. }
  62. //获取限时类的活动
  63. if (isset($params[ 'summary' ])) {
  64. $list = model("promotion_games")->getList([
  65. [ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
  66. [ 'game_type', '=', 'turntable' ],
  67. [ 'site_id', '=', $params[ 'site_id' ] ],
  68. [ 'status', '<>', 2 ],
  69. [ 'status', '<>', 3 ]
  70. ], 'game_name as promotion_name,game_id as promotion_id,start_time,end_time');
  71. return !empty($list) ? [
  72. 'time_limit' => [
  73. 'count' => count($list),
  74. 'detail' => $list,
  75. 'color' => '#FF6666'
  76. ]
  77. ] : [];
  78. }
  79. }
  80. }