Promotionxianshi.php 8.4 KB

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