Promotionbargain.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 Promotionbargain extends AdminControl
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionbargain.lang.php');
  25. }
  26. /**
  27. * 砍价列表
  28. */
  29. public function index()
  30. {
  31. $bargain_model = model('pbargain');
  32. $condition = array();
  33. if (!empty(input('param.bargain_name'))) {
  34. $condition[] = array('bargain_name', 'like', '%' . input('param.bargain_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('bargain_state', '=', intval(input('param.state')));
  41. }
  42. $bargain_list = $bargain_model->getBargainList($condition, 10, 'bargain_id desc');
  43. foreach ($bargain_list as $key => $val) {
  44. $bargain_list[$key]['bargain_state_text'] = $bargain_model->getBargainStateText($val);
  45. $bargain_list[$key] = array_merge($bargain_list[$key], $bargain_model->getBargainBtn($val));
  46. }
  47. View::assign('bargain_list', $bargain_list);
  48. View::assign('show_page', $bargain_model->page_info->render());
  49. View::assign('bargain_state_array', $bargain_model->getBargainStateArray());
  50. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  51. $this->setAdminCurItem('bargain_list');
  52. return View::fetch();
  53. }
  54. /**
  55. * 商品砍价订单列表
  56. */
  57. public function bargain_order()
  58. {
  59. $pbargainorder_model = model('pbargainorder');
  60. $bargain_id = intval(input('param.bargain_id'));
  61. $condition = array();
  62. $condition[] = array('bargain_id', '=', $bargain_id);
  63. if (input('param.bargainorder_state') != '') {
  64. $condition[] = array('bargainorder_state', '=', intval(input('param.bargainorder_state')));
  65. }
  66. $pbargainorder_list = $pbargainorder_model->getPbargainorderList($condition, 10); #获取开团信息
  67. View::assign('show_page', $pbargainorder_model->page_info->render());
  68. View::assign('pbargainorder_list', $pbargainorder_list);
  69. View::assign('bargainorder_state_array', $pbargainorder_model->getBargainorderStateArray());
  70. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  71. $this->setAdminCurItem('bargain_order');
  72. return View::fetch();
  73. }
  74. /**
  75. * 商品砍价记录列表
  76. */
  77. public function bargain_log()
  78. {
  79. $pbargainlog_model = model('pbargainlog');
  80. $bargainorder_id = intval(input('param.bargainorder_id'));
  81. $condition = array();
  82. $condition[] = array('bargainorder_id', '=', $bargainorder_id);
  83. $pbargainlog_list = $pbargainlog_model->getPbargainlogList($condition, 10); #获取砍价记录信息
  84. View::assign('show_page', $pbargainlog_model->page_info->render());
  85. View::assign('pbargainlog_list', $pbargainlog_list);
  86. return View::fetch();
  87. }
  88. /**
  89. * 砍价活动 取消
  90. */
  91. public function bargain_end()
  92. {
  93. $bargain_id = intval(input('param.bargain_id'));
  94. $pbargain_model = model('pbargain');
  95. $bargain_info = $pbargain_model->getBargainInfoByID($bargain_id);
  96. if (!$bargain_info) {
  97. ds_json_encode(10001, lang('param_error'));
  98. }
  99. if (!in_array($bargain_info['bargain_state'], array(1, 2))) { //只有未开始、进行中的活动可以取消
  100. ds_json_encode(10001, lang('bargain_cant_cancel'));
  101. }
  102. Db::startTrans();
  103. try {
  104. /**
  105. * 指定砍价活动结束
  106. */
  107. if (!$pbargain_model->cancelBargain(array('bargain_id' => $bargain_id))) {
  108. throw new \think\Exception(lang('bargain_edit_fail'), 10006);
  109. }
  110. if ($bargain_info['bargain_state']) {
  111. //取消用户发起的活动
  112. $pbargainorder_model = model('pbargainorder');
  113. $pbargainorder_model->lock = true;
  114. $pbargainorder_list = $pbargainorder_model->getPbargainorderList(array('bargainorder_state' => 1, 'bargain_id' => $bargain_id));
  115. if (!empty($pbargainorder_list) && !$pbargainorder_model->editPbargainorder(array('bargainorder_state' => 1, 'bargain_id' => $bargain_id), array('bargainorder_state' => 0))) {
  116. throw new \think\Exception(lang('user_bargain_edit_fail'), 10006);
  117. }
  118. }
  119. Db::commit();
  120. } catch (\Exception $e) {
  121. Db::rollback();
  122. ds_json_encode(10001, $e->getMessage());
  123. }
  124. $this->log('砍价活动取消,活动名称:' . $bargain_info['bargain_name'] . '活动编号:' . $bargain_id, 1);
  125. ds_json_encode(10000, lang('ds_common_op_succ'));
  126. }
  127. /**
  128. * 拼团活动 删除
  129. */
  130. public function bargain_del()
  131. {
  132. $bargain_id = intval(input('param.bargain_id'));
  133. $pbargain_model = model('pbargain');
  134. $bargain_info = $pbargain_model->getBargainInfoByID($bargain_id);
  135. if (!$bargain_info) {
  136. ds_json_encode(10001, lang('param_error'));
  137. }
  138. /**
  139. * 指定拼团活动删除
  140. */
  141. $result = $pbargain_model->delBargain(array('bargain_id' => $bargain_id));
  142. if ($result) {
  143. $this->log('砍价活动删除,活动名称:' . $bargain_info['bargain_name'] . '活动编号:' . $bargain_id, 1);
  144. ds_json_encode(10000, lang('ds_common_op_succ'));
  145. } else {
  146. ds_json_encode(10001, lang('ds_common_op_fail'));
  147. }
  148. }
  149. /**
  150. * 砍价套餐管理
  151. */
  152. public function bargain_quota()
  153. {
  154. $bargainquota_model = model('pbargainquota');
  155. $condition = array();
  156. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  157. $bargainquota_list = $bargainquota_model->getBargainquotaList($condition, 10, 'bargainquota_endtime desc');
  158. View::assign('bargainquota_list', $bargainquota_list);
  159. View::assign('show_page', $bargainquota_model->page_info->render());
  160. $this->setAdminCurItem('bargain_quota');
  161. return View::fetch();
  162. }
  163. /**
  164. * 砍价设置
  165. */
  166. public function bargain_setting()
  167. {
  168. if (!(request()->isPost())) {
  169. $setting = rkcache('config', true);
  170. View::assign('setting', $setting);
  171. return View::fetch();
  172. } else {
  173. $promotion_bargain_price = intval(input('post.promotion_bargain_price'));
  174. if ($promotion_bargain_price < 0) {
  175. $this->error(lang('param_error'));
  176. }
  177. $config_model = model('config');
  178. $update_array = array();
  179. $update_array['promotion_bargain_price'] = $promotion_bargain_price;
  180. $result = $config_model->editConfig($update_array);
  181. if ($result) {
  182. $this->log('修改砍价套餐价格为' . $promotion_bargain_price . '元');
  183. dsLayerOpenSuccess(lang('setting_save_success'));
  184. } else {
  185. $this->error(lang('setting_save_fail'));
  186. }
  187. }
  188. }
  189. protected function getAdminItemList()
  190. {
  191. $menu_array = array(
  192. array(
  193. 'name' => 'bargain_list', 'text' => lang('bargain_list'), 'url' => (string)url('Promotionbargain/index')
  194. ), array(
  195. 'name' => 'bargain_quota', 'text' => lang('bargain_quota'),
  196. 'url' => (string)url('Promotionbargain/bargain_quota')
  197. ), array(
  198. 'name' => 'bargain_setting',
  199. 'text' => lang('bargain_setting'),
  200. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionbargain/bargain_setting') . "','" . lang('bargain_setting') . "')"
  201. ),
  202. );
  203. if (request()->action() == 'bargain_detail') {
  204. $menu_array[] = array(
  205. 'name' => 'bargain_detail', 'text' => lang('bargain_detail'),
  206. 'url' => (string)url('Promotionbargain/bargain_detail')
  207. );
  208. }
  209. return $menu_array;
  210. }
  211. }