Promotionxianshi.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /**
  3. * 秒杀
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. *
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Promotionxianshi extends AdminControl
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionxianshi.lang.php');
  25. }
  26. /**
  27. * 活动列表
  28. **/
  29. public function index()
  30. {
  31. //自动开启秒杀
  32. if (intval(input('param.promotion_allow')) === 1) {
  33. $config_model = model('config');
  34. $update_array = array();
  35. $update_array['promotion_allow'] = 1;
  36. $config_model->editConfig($update_array);
  37. }
  38. $xianshi_model = model('pxianshi');
  39. $condition = array();
  40. if (!empty(input('param.xianshi_name'))) {
  41. $condition[] = array('xianshi_name', 'like', '%' . input('param.xianshi_name') . '%');
  42. }
  43. if (!empty(input('param.store_name'))) {
  44. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  45. }
  46. if (!empty(input('param.state'))) {
  47. $condition[] = array('xianshi_state', '=', intval(input('param.state')));
  48. }
  49. $xianshi_list = $xianshi_model->getXianshiList($condition, 10, Db::raw('FIELD(xianshi_state, 1,0,2,3), xianshi_end_time desc'));
  50. View::assign('xianshi_list', $xianshi_list);
  51. View::assign('show_page', $xianshi_model->page_info->render());
  52. View::assign('xianshi_state_array', $xianshi_model->getXianshiStateArray());
  53. $this->setAdminCurItem('xianshi_list');
  54. // 输出自营店铺IDS
  55. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  56. View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
  57. return View::fetch();
  58. }
  59. /**
  60. * 秒杀活动取消
  61. **/
  62. public function xianshi_cancel()
  63. {
  64. $xianshi_id = intval(input('param.xianshi_id'));
  65. $xianshi_model = model('pxianshi');
  66. $result = $xianshi_model->cancelXianshi(array('xianshi_id' => $xianshi_id));
  67. if ($result) {
  68. $this->log('取消秒杀活动,活动编号' . $xianshi_id);
  69. ds_json_encode(10000, lang('ds_common_op_succ'));
  70. } else {
  71. ds_json_encode(10001, lang('ds_common_op_fail'));
  72. }
  73. }
  74. /**
  75. * 秒杀活动删除
  76. **/
  77. public function xianshi_del()
  78. {
  79. $xianshi_model = model('pxianshi');
  80. $xianshi_id = input('param.xianshi_id');
  81. $xianshi_id_array = ds_delete_param($xianshi_id);
  82. if ($xianshi_id_array === FALSE) {
  83. ds_json_encode(10001, lang('param_error'));
  84. }
  85. $condition = array(array('xianshi_id', 'in', $xianshi_id_array));
  86. $result = $xianshi_model->delXianshi($condition);
  87. if ($result) {
  88. $this->log('删除秒杀活动,活动编号' . $xianshi_id);
  89. ds_json_encode(10000, lang('ds_common_op_succ'));
  90. } else {
  91. ds_json_encode(10001, lang('ds_common_op_fail'));
  92. }
  93. }
  94. /**
  95. * 活动详细信息
  96. **/
  97. public function xianshi_detail()
  98. {
  99. $xianshi_id = intval(input('param.xianshi_id'));
  100. $xianshi_model = model('pxianshi');
  101. $xianshigoods_model = model('pxianshigoods');
  102. $xianshi_info = $xianshi_model->getXianshiInfoByID($xianshi_id);
  103. if (empty($xianshi_info)) {
  104. $this->error(lang('param_error'));
  105. }
  106. View::assign('xianshi_info', $xianshi_info);
  107. //获取秒杀商品列表
  108. $condition = array();
  109. $condition[] = array('xianshi_id', '=', $xianshi_id);
  110. $xianshigoods_list = $xianshigoods_model->getXianshigoodsExtendList($condition, 5);
  111. View::assign('xianshigoods_list', $xianshigoods_list);
  112. View::assign('show_page', $xianshigoods_model->page_info->render());
  113. return View::fetch();
  114. }
  115. /**
  116. * 套餐管理
  117. **/
  118. public function xianshi_quota()
  119. {
  120. $xianshiquota_model = model('pxianshiquota');
  121. $condition = array();
  122. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  123. $xianshiquota_list = $xianshiquota_model->getXianshiquotaList($condition, 10, 'xianshiquota_endtime desc');
  124. View::assign('xianshiquota_list', $xianshiquota_list);
  125. View::assign('show_page', $xianshiquota_model->page_info->render());
  126. $this->setAdminCurItem('xianshi_quota');
  127. return View::fetch();
  128. }
  129. /**
  130. * 设置
  131. **/
  132. public function xianshi_setting()
  133. {
  134. if (!(request()->isPost())) {
  135. $setting = rkcache('config', true);
  136. View::assign('setting', $setting);
  137. return View::fetch();
  138. } else {
  139. $promotion_xianshi_price = intval(input('post.promotion_xianshi_price'));
  140. if ($promotion_xianshi_price < 0) {
  141. $this->error(lang('param_error'));
  142. }
  143. $config_model = model('config');
  144. $update_array = array();
  145. $update_array['promotion_xianshi_price'] = $promotion_xianshi_price;
  146. $result = $config_model->editConfig($update_array);
  147. if ($result) {
  148. $this->log('修改秒杀价格为' . $promotion_xianshi_price . '元');
  149. dsLayerOpenSuccess(lang('setting_save_success'));
  150. } else {
  151. $this->error(lang('setting_save_fail'));
  152. }
  153. }
  154. }
  155. /**
  156. * ajax修改抢购信息
  157. */
  158. public function ajax()
  159. {
  160. $result = true;
  161. $update_array = array();
  162. $condition = array();
  163. switch (input('param.branch')) {
  164. case 'recommend':
  165. $pxianshigoods_model = model('pxianshigoods');
  166. $update_array['xianshigoods_recommend'] = input('param.value');
  167. $condition[] = array('xianshigoods_id', '=', input('param.id'));
  168. $result = $pxianshigoods_model->editXianshigoods($update_array, $condition);
  169. break;
  170. }
  171. if ($result) {
  172. echo 'true';
  173. exit;
  174. } else {
  175. echo 'false';
  176. exit;
  177. }
  178. }
  179. /*
  180. * 发送消息
  181. */
  182. private function send_message($member_id, $member_name, $message)
  183. {
  184. $param = array();
  185. $param['from_member_id'] = 0;
  186. $param['member_id'] = $member_id;
  187. $param['to_member_name'] = $member_name;
  188. $param['message_type'] = '1'; //表示为系统消息
  189. $param['msg_content'] = $message;
  190. $message_model = model('message');
  191. return $message_model->addMessage($param);
  192. }
  193. /**
  194. * 页面内导航菜单
  195. *
  196. * @param string $menu_key 当前导航的menu_key
  197. * @param array $array 附加菜单
  198. * @return
  199. */
  200. protected function getAdminItemList()
  201. {
  202. $menu_array = array(
  203. array(
  204. 'name' => 'xianshi_list', 'text' => lang('xianshi_list'), 'url' => (string)url('Promotionxianshi/index')
  205. ), array(
  206. 'name' => 'xianshi_quota', 'text' => lang('xianshi_quota'),
  207. 'url' => (string)url('Promotionxianshi/xianshi_quota')
  208. ), array(
  209. 'name' => 'xianshi_setting',
  210. 'text' => lang('xianshi_setting'),
  211. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionxianshi/xianshi_setting') . "','" . lang('xianshi_setting') . "')"
  212. ),
  213. );
  214. if (request()->action() == 'xianshi_detail')
  215. $menu_array[] = array(
  216. 'name' => 'xianshi_detail', 'text' => lang('xianshi_detail'),
  217. 'url' => (string)url('Promotionxianshi/xianshi_detail')
  218. );
  219. return $menu_array;
  220. }
  221. }