Promotionwholesale.php 8.3 KB

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