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