Promotionpresell.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  14. * 网站地址: https://www.valimart.net/
  15. * ----------------------------------------------------------------------------
  16. *
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Promotionpresell extends AdminControl {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionpresell.lang.php');
  24. }
  25. /**
  26. * 预售列表
  27. */
  28. public function index() {
  29. $presell_model = model('presell');
  30. $condition = array();
  31. if (!empty(input('param.goods_name'))) {
  32. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  33. }
  34. if (!empty(input('param.store_name'))) {
  35. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  36. }
  37. if (input('param.state') != '' && in_array(input('param.state'), array(0, 1, 2, 3))) {
  38. $condition[] = array('presell_state', '=', intval(input('param.state')));
  39. }
  40. $presell_list = $presell_model->getPresellList($condition, 10, 'presell_id desc');
  41. foreach ($presell_list as $key => $val) {
  42. $presell_list[$key]['presell_state_text'] = $presell_model->getPresellStateText($val);
  43. $presell_list[$key] = array_merge($presell_list[$key], $presell_model->getPresellBtn($val));
  44. }
  45. View::assign('presell_list', $presell_list);
  46. View::assign('show_page', $presell_model->page_info->render());
  47. View::assign('presell_state_array', $presell_model->getPresellStateArray());
  48. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  49. $this->setAdminCurItem('presell_list');
  50. return View::fetch();
  51. }
  52. /**
  53. * 预售活动 取消
  54. */
  55. public function presell_end() {
  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. $presell_id = intval(input('param.presell_id'));
  101. $presell_model = model('presell');
  102. $presell_info = $presell_model->getPresellInfoByID($presell_id);
  103. if (!$presell_info) {
  104. ds_json_encode(10001, lang('param_error'));
  105. }
  106. /**
  107. * 指定拼团活动删除
  108. */
  109. $result = $presell_model->delPresell(array('presell_id' => $presell_id));
  110. if ($result) {
  111. $this->log('预售活动删除,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
  112. ds_json_encode(10000, lang('ds_common_op_succ'));
  113. } else {
  114. ds_json_encode(10001, lang('ds_common_op_fail'));
  115. }
  116. }
  117. /**
  118. * 预售套餐管理
  119. */
  120. public function presell_quota() {
  121. $presellquota_model = model('presellquota');
  122. $condition = array();
  123. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  124. $presellquota_list = $presellquota_model->getPresellquotaList($condition, 10, 'presellquota_endtime desc');
  125. View::assign('presellquota_list', $presellquota_list);
  126. View::assign('show_page', $presellquota_model->page_info->render());
  127. $this->setAdminCurItem('presell_quota');
  128. return View::fetch();
  129. }
  130. /**
  131. * 预售设置
  132. */
  133. public function presell_setting() {
  134. if (!(request()->isPost())) {
  135. $setting = rkcache('config', true);
  136. View::assign('setting', $setting);
  137. return View::fetch();
  138. } else {
  139. $promotion_presell_price = intval(input('post.promotion_presell_price'));
  140. if ($promotion_presell_price < 0) {
  141. $this->error(lang('param_error'));
  142. }
  143. $config_model = model('config');
  144. $update_array = array();
  145. $update_array['promotion_presell_price'] = $promotion_presell_price;
  146. $result = $config_model->editConfig($update_array);
  147. if ($result) {
  148. $this->log('修改预售套餐价格为' . $promotion_presell_price . '元');
  149. dsLayerOpenSuccess(lang('setting_save_success'));
  150. } else {
  151. $this->error(lang('setting_save_fail'));
  152. }
  153. }
  154. }
  155. protected function getAdminItemList() {
  156. $menu_array = array(
  157. array(
  158. 'name' => 'presell_list', 'text' => lang('presell_list'), 'url' => (string) url('Promotionpresell/index')
  159. ), array(
  160. 'name' => 'presell_quota', 'text' => lang('presell_quota'),
  161. 'url' => (string) url('Promotionpresell/presell_quota')
  162. ), array(
  163. 'name' => 'presell_setting',
  164. 'text' => lang('presell_setting'),
  165. 'url' => "javascript:dsLayerOpen('" . (string) url('Promotionpresell/presell_setting') . "','" . lang('presell_setting') . "')"
  166. ),
  167. );
  168. return $menu_array;
  169. }
  170. }