Promotionbargain.php 9.2 KB

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