Promotionbargain.php 9.0 KB

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