Promotionpresell.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Promotionpresell extends AdminControl {
  22. public function initialize() {
  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. $presell_model = model('presell');
  31. $condition = array();
  32. if (!empty(input('param.goods_name'))) {
  33. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  34. }
  35. if (!empty(input('param.store_name'))) {
  36. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  37. }
  38. if (input('param.state') != '' && in_array(input('param.state'), array(0, 1, 2, 3))) {
  39. $condition[] = array('presell_state', '=', intval(input('param.state')));
  40. }
  41. $presell_list = $presell_model->getPresellList($condition, 10, 'presell_id desc');
  42. foreach ($presell_list as $key => $val) {
  43. $presell_list[$key]['presell_state_text'] = $presell_model->getPresellStateText($val);
  44. $presell_list[$key] = array_merge($presell_list[$key], $presell_model->getPresellBtn($val));
  45. }
  46. View::assign('presell_list', $presell_list);
  47. View::assign('show_page', $presell_model->page_info->render());
  48. View::assign('presell_state_array', $presell_model->getPresellStateArray());
  49. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  50. $this->setAdminCurItem('presell_list');
  51. return View::fetch();
  52. }
  53. /**
  54. * 预售活动 取消
  55. */
  56. public function presell_end() {
  57. $presell_id = intval(input('param.presell_id'));
  58. $presell_model = model('presell');
  59. $presell_info = $presell_model->getPresellInfoByID($presell_id);
  60. if (!$presell_info) {
  61. ds_json_encode(10001, lang('param_error'));
  62. }
  63. if (!in_array($presell_info['presell_state'], array(1, 2))) {//只有未开始、进行中的活动可以取消
  64. ds_json_encode(10001, lang('presell_cant_cancel'));
  65. }
  66. try {
  67. Db::startTrans();
  68. //取消用户发起的活动
  69. $condition = array();
  70. $condition[] = array('goods_type', '=', 10);
  71. $condition[] = array('promotions_id', '=', $presell_id);
  72. $order_ids = Db::name('ordergoods')->where($condition)->column('order_id');
  73. if (!empty($order_ids)) {
  74. $order_model = model('order');
  75. $logic_order = model('order', 'logic');
  76. $condition = array();
  77. $condition[] = array('order_id', 'in', $order_ids);
  78. $condition[] = array('order_state', 'in', [ORDER_STATE_NEW,ORDER_STATE_DEPOSIT, ORDER_STATE_REST,ORDER_STATE_PAY]);
  79. $order_list = $order_model->getOrderList($condition);
  80. if (!empty($order_list)) {
  81. foreach ($order_list as $order_info) {
  82. $logic_order->changeOrderStateCancel($order_info, 'admin', $this->admin_info['admin_name'], '管理员取消预售活动');
  83. }
  84. }
  85. }
  86. if (!$presell_model->cancelPresell(array('presell_id' => $presell_id))) {
  87. throw new \think\Exception(lang('presell_edit_fail'), 10006);
  88. }
  89. } catch (\Exception $e) {
  90. Db::rollback();
  91. ds_json_encode(10001, $e->getMessage());
  92. }
  93. Db::commit();
  94. $this->log('预售活动取消,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
  95. ds_json_encode(10000, lang('ds_common_op_succ'));
  96. }
  97. /**
  98. * 拼团活动 删除
  99. */
  100. public function presell_del() {
  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. $presellquota_model = model('presellquota');
  123. $condition = array();
  124. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  125. $presellquota_list = $presellquota_model->getPresellquotaList($condition, 10, 'presellquota_endtime desc');
  126. View::assign('presellquota_list', $presellquota_list);
  127. View::assign('show_page', $presellquota_model->page_info->render());
  128. $this->setAdminCurItem('presell_quota');
  129. return View::fetch();
  130. }
  131. /**
  132. * 预售设置
  133. */
  134. public function presell_setting() {
  135. if (!(request()->isPost())) {
  136. $setting = rkcache('config', true);
  137. View::assign('setting', $setting);
  138. return View::fetch();
  139. } else {
  140. $promotion_presell_price = intval(input('post.promotion_presell_price'));
  141. if ($promotion_presell_price < 0) {
  142. $this->error(lang('param_error'));
  143. }
  144. $config_model = model('config');
  145. $update_array = array();
  146. $update_array['promotion_presell_price'] = $promotion_presell_price;
  147. $result = $config_model->editConfig($update_array);
  148. if ($result) {
  149. $this->log('修改预售套餐价格为' . $promotion_presell_price . '元');
  150. dsLayerOpenSuccess(lang('setting_save_success'));
  151. } else {
  152. $this->error(lang('setting_save_fail'));
  153. }
  154. }
  155. }
  156. protected function getAdminItemList() {
  157. $menu_array = array(
  158. array(
  159. 'name' => 'presell_list', 'text' => lang('presell_list'), 'url' => (string) url('Promotionpresell/index')
  160. ), array(
  161. 'name' => 'presell_quota', 'text' => lang('presell_quota'),
  162. 'url' => (string) url('Promotionpresell/presell_quota')
  163. ), array(
  164. 'name' => 'presell_setting',
  165. 'text' => lang('presell_setting'),
  166. 'url' => "javascript:dsLayerOpen('" . (string) url('Promotionpresell/presell_setting') . "','" . lang('presell_setting') . "')"
  167. ),
  168. );
  169. return $menu_array;
  170. }
  171. }