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