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