Bale.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\bale\shop\controller;
  13. use app\shop\controller\BaseShop;
  14. use addon\bale\model\Bale as BaleModel;
  15. /**
  16. * 打包一口价
  17. * @author Administrator
  18. *
  19. */
  20. class Bale extends BaseShop
  21. {
  22. /**
  23. * 活动列表
  24. * @return array|mixed
  25. */
  26. public function lists()
  27. {
  28. if (request()->isAjax()) {
  29. $page = input('page', 1);
  30. $page_size = input('page_size', PAGE_LIST_ROWS);
  31. $status = input('status', '');
  32. $name = input('name', '');
  33. $condition = [
  34. [ 'site_id', '=', $this->site_id ]
  35. ];
  36. if ($status !== '') {
  37. $condition[] = [ 'status', '=', $status ];
  38. }
  39. if (!empty($name)) {
  40. $condition[] = [ 'name', 'like', '%' . $name . '%' ];
  41. }
  42. $start_time = input('start_time', '');
  43. $end_time = input('end_time', '');
  44. if ($start_time && !$end_time) {
  45. $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
  46. } elseif (!$start_time && $end_time) {
  47. $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
  48. } elseif ($start_time && $end_time) {
  49. $start_timestamp = date_to_time($start_time);
  50. $end_timestamp = date_to_time($end_time);
  51. $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
  52. $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
  53. $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
  54. $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
  55. }
  56. $bale = new BaleModel();
  57. $list = $bale->getBalePageList($condition, $page, $page_size);
  58. return $list;
  59. } else {
  60. return $this->fetch("bale/lists");
  61. }
  62. }
  63. /**
  64. * 添加活动
  65. * @return mixed
  66. */
  67. public function add()
  68. {
  69. if (request()->isAjax()) {
  70. $bale = new BaleModel();
  71. $res = $bale->addBale([
  72. 'site_id' => $this->site_id,
  73. 'name' => input('name', ''),
  74. 'num' => input('num', 0),
  75. 'price' => input('price', 0.00),
  76. 'goods_ids' => input('goods_ids', ''),
  77. 'sku_ids' => input('sku_ids', ''),
  78. 'start_time' => strtotime(input('start_time', 0)),
  79. 'end_time' => strtotime(input('end_time', 0)),
  80. 'shipping_fee_type' => input('shipping_fee_type', 0),
  81. ]);
  82. return $res;
  83. }
  84. return $this->fetch("bale/add");
  85. }
  86. /**
  87. * 编辑活动
  88. * @return mixed
  89. */
  90. public function edit()
  91. {
  92. $bale = new BaleModel();
  93. if (request()->isAjax()) {
  94. $res = $bale->editBale([
  95. 'bale_id' => input('bale_id'),
  96. 'site_id' => $this->site_id,
  97. 'name' => input('name', ''),
  98. 'num' => input('num', 0),
  99. 'price' => input('price', 0.00),
  100. 'goods_ids' => input('goods_ids', ''),
  101. 'sku_ids' => input('sku_ids', ''),
  102. 'start_time' => strtotime(input('start_time', 0)),
  103. 'end_time' => strtotime(input('end_time', 0)),
  104. 'shipping_fee_type' => input('shipping_fee_type', 0),
  105. ]);
  106. return $res;
  107. }
  108. $bale_id = input('bale_id', '');
  109. $info = $bale->getBaleDetail($bale_id, $this->site_id);
  110. if (empty($info[ 'data' ])) $this->error('未获取到活动信息');
  111. $this->assign('bale_info', $info[ 'data' ]);
  112. return $this->fetch("bale/edit");
  113. }
  114. /**
  115. * 详情
  116. */
  117. public function detail()
  118. {
  119. $bale_id = input('bale_id', '');
  120. $bale = new BaleModel();
  121. $info = $bale->getBaleDetail($bale_id, $this->site_id)[ 'data' ] ?? [];
  122. if (empty($info)) $this->error('未获取到活动信息');
  123. $this->assign('info', $info);
  124. return $this->fetch("bale/detail");
  125. }
  126. /**
  127. * 删除活动
  128. * @return array
  129. */
  130. public function delete()
  131. {
  132. if (request()->isAjax()) {
  133. $id = input('id', 0);
  134. $bale = new BaleModel();
  135. $res = $bale->deleteBale($id, $this->site_id);
  136. return $res;
  137. }
  138. }
  139. /**
  140. * 商品推广
  141. * return
  142. */
  143. public function baleUrl()
  144. {
  145. $bale_id = input('bale_id', '');
  146. $bale = new BaleModel();
  147. $res = $bale->urlQrcode('/pages_promotion/bale/detail', [ 'id' => $bale_id ], 'bale', $this->site_id);
  148. return $res;
  149. }
  150. public function closeBale()
  151. {
  152. $bale_id = input('id', '');
  153. $bale = new BaleModel();
  154. $res = $bale->closeBale($bale_id);
  155. return $res;
  156. }
  157. }