Promotionpresell.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * 预售管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Db;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. *
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Promotionpresell extends AdminControl
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionpresell.lang.php');
  25. }
  26. /**
  27. * 预售列表
  28. */
  29. public function index()
  30. {
  31. $presell_model = model('presell');
  32. $condition = array();
  33. if (!empty(input('param.goods_name'))) {
  34. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  35. }
  36. if (!empty(input('param.store_name'))) {
  37. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  38. }
  39. if (input('param.state') != '' && in_array(input('param.state'), array(0, 1, 2, 3))) {
  40. $condition[] = array('presell_state', '=', intval(input('param.state')));
  41. }
  42. $presell_list = $presell_model->getPresellList($condition, 10, 'presell_id desc');
  43. foreach ($presell_list as $key => $val) {
  44. $presell_list[$key]['presell_state_text'] = $presell_model->getPresellStateText($val);
  45. $presell_list[$key] = array_merge($presell_list[$key], $presell_model->getPresellBtn($val));
  46. }
  47. View::assign('presell_list', $presell_list);
  48. View::assign('show_page', $presell_model->page_info->render());
  49. View::assign('presell_state_array', $presell_model->getPresellStateArray());
  50. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  51. $this->setAdminCurItem('presell_list');
  52. return View::fetch();
  53. }
  54. /**
  55. * 预售活动 取消
  56. */
  57. public function presell_end()
  58. {
  59. $presell_id = intval(input('param.presell_id'));
  60. $presell_model = model('presell');
  61. $presell_info = $presell_model->getPresellInfoByID($presell_id);
  62. if (!$presell_info) {
  63. ds_json_encode(10001, lang('param_error'));
  64. }
  65. if (!in_array($presell_info['presell_state'], array(1, 2))) { //只有未开始、进行中的活动可以取消
  66. ds_json_encode(10001, lang('presell_cant_cancel'));
  67. }
  68. try {
  69. Db::startTrans();
  70. //取消用户发起的活动
  71. $condition = array();
  72. $condition[] = array('goods_type', '=', 10);
  73. $condition[] = array('promotions_id', '=', $presell_id);
  74. $order_ids = Db::name('ordergoods')->where($condition)->column('order_id');
  75. if (!empty($order_ids)) {
  76. $order_model = model('order');
  77. $logic_order = model('order', 'logic');
  78. $condition = array();
  79. $condition[] = array('order_id', 'in', $order_ids);
  80. $condition[] = array('order_state', 'in', [ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST, ORDER_STATE_PAY]);
  81. $order_list = $order_model->getOrderList($condition);
  82. if (!empty($order_list)) {
  83. foreach ($order_list as $order_info) {
  84. $logic_order->changeOrderStateCancel($order_info, 'admin', $this->admin_info['admin_name'], '管理员取消预售活动');
  85. }
  86. }
  87. }
  88. if (!$presell_model->cancelPresell(array('presell_id' => $presell_id))) {
  89. throw new \think\Exception(lang('presell_edit_fail'), 10006);
  90. }
  91. } catch (\Exception $e) {
  92. Db::rollback();
  93. ds_json_encode(10001, $e->getMessage());
  94. }
  95. Db::commit();
  96. $this->log('预售活动取消,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
  97. ds_json_encode(10000, lang('ds_common_op_succ'));
  98. }
  99. /**
  100. * 拼团活动 删除
  101. */
  102. public function presell_del()
  103. {
  104. $presell_id = intval(input('param.presell_id'));
  105. $presell_model = model('presell');
  106. $presell_info = $presell_model->getPresellInfoByID($presell_id);
  107. if (!$presell_info) {
  108. ds_json_encode(10001, lang('param_error'));
  109. }
  110. /**
  111. * 指定拼团活动删除
  112. */
  113. $result = $presell_model->delPresell(array('presell_id' => $presell_id));
  114. if ($result) {
  115. $this->log('预售活动删除,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
  116. ds_json_encode(10000, lang('ds_common_op_succ'));
  117. } else {
  118. ds_json_encode(10001, lang('ds_common_op_fail'));
  119. }
  120. }
  121. /**
  122. * 预售套餐管理
  123. */
  124. public function presell_quota()
  125. {
  126. $presellquota_model = model('presellquota');
  127. $condition = array();
  128. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  129. $presellquota_list = $presellquota_model->getPresellquotaList($condition, 10, 'presellquota_endtime desc');
  130. View::assign('presellquota_list', $presellquota_list);
  131. View::assign('show_page', $presellquota_model->page_info->render());
  132. $this->setAdminCurItem('presell_quota');
  133. return View::fetch();
  134. }
  135. /**
  136. * 预售设置
  137. */
  138. public function presell_setting()
  139. {
  140. if (!(request()->isPost())) {
  141. $setting = rkcache('config', true);
  142. View::assign('setting', $setting);
  143. return View::fetch();
  144. } else {
  145. $promotion_presell_price = intval(input('post.promotion_presell_price'));
  146. if ($promotion_presell_price < 0) {
  147. $this->error(lang('param_error'));
  148. }
  149. $config_model = model('config');
  150. $update_array = array();
  151. $update_array['promotion_presell_price'] = $promotion_presell_price;
  152. $result = $config_model->editConfig($update_array);
  153. if ($result) {
  154. $this->log('修改预售套餐价格为' . $promotion_presell_price . '元');
  155. dsLayerOpenSuccess(lang('setting_save_success'));
  156. } else {
  157. $this->error(lang('setting_save_fail'));
  158. }
  159. }
  160. }
  161. protected function getAdminItemList()
  162. {
  163. $menu_array = array(
  164. array(
  165. 'name' => 'presell_list', 'text' => lang('presell_list'), 'url' => (string) url('Promotionpresell/index')
  166. ), array(
  167. 'name' => 'presell_quota', 'text' => lang('presell_quota'),
  168. 'url' => (string) url('Promotionpresell/presell_quota')
  169. ), array(
  170. 'name' => 'presell_setting',
  171. 'text' => lang('presell_setting'),
  172. 'url' => "javascript:dsLayerOpen('" . (string) url('Promotionpresell/presell_setting') . "','" . lang('presell_setting') . "')"
  173. ),
  174. );
  175. return $menu_array;
  176. }
  177. }