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