Mallvouchertemplate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Mallvouchertemplate extends AdminControl {
  18. private $quotastate_arr;
  19. private $templatestate_arr;
  20. public function initialize() {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/mallvouchertemplate.lang.php');
  23. if (config('ds_config.voucher_allow') != 1 || config('ds_config.points_isuse') != 1) {
  24. $this->error(lang('admin_voucher_unavailable'), 'operation/setting');
  25. }
  26. }
  27. /*
  28. * 代金券面额列表
  29. */
  30. public function mallvouchertemplatelist() {
  31. //获得代金券金额列表
  32. $mallvouchertemplate_model = model('mallvouchertemplate');
  33. $condition = array();
  34. $mallvouchertemplate_list = $mallvouchertemplate_model->getMallvouchertemplateList($condition,10);
  35. View::assign('mallvouchertemplate_list', $mallvouchertemplate_list);
  36. View::assign('show_page', $mallvouchertemplate_model->page_info->render());
  37. $this->setAdminCurItem('mallvouchertemplatelist');
  38. return View::fetch();
  39. }
  40. /*
  41. * 添加代金券页面
  42. */
  43. public function mallvouchertemplateadd() {
  44. if (request()->isPost()) {
  45. $mallvouchertemplate_model = model('mallvouchertemplate');
  46. $goodsclass_model = model('goodsclass');
  47. //获取代金券所属分类ID集
  48. $gc_id = intval(input('post.mallvouchertemplate_gcid'));
  49. if($gc_id == 0){
  50. $this->error(lang('admin_mallvouchertemplate_gc_error'));
  51. }
  52. $gc_ids = ',';
  53. $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
  54. foreach($goodsclasslist as $key => $val){
  55. $gc_ids .= $val['gc_id'].',';
  56. }
  57. $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
  58. $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
  59. $data = [
  60. 'mallvouchertemplate_price' => $price,
  61. 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
  62. 'mallvouchertemplate_gcid' => $gc_id,
  63. 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
  64. 'mallvouchertemplate_limit' => $limit,
  65. 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
  66. 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
  67. 'mallvouchertemplate_gcidarr' => $gc_ids,
  68. 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
  69. 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
  70. 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
  71. ];
  72. if ($price >= $limit) {
  73. $this->error(lang('admin_mallvouchertemplate_limit_error'));
  74. }
  75. $rs = $mallvouchertemplate_model->addmallvouchertemplate($data);
  76. if ($rs) {
  77. $this->log(lang('ds_add') . lang('admin_mallvouchertemplate_add') . '[' . $data['mallvouchertemplate_title'] . ']');
  78. $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
  79. } else {
  80. $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
  81. }
  82. }
  83. else {
  84. $mallvouchertemplate_info = array(
  85. 'mallvouchertemplate_startdate' => TIMESTAMP,
  86. 'mallvouchertemplate_enddate' => TIMESTAMP+3600*24*7,
  87. 'mallvouchertemplate_gcid' => '',
  88. 'mallvouchertemplate_quantity' => '',
  89. 'mallvouchertemplate_eachlimit'=>''
  90. );
  91. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  92. View::assign('gc_list', $gc_list);
  93. View::assign('info', $mallvouchertemplate_info);
  94. View::assign('action', 'add');
  95. $this->setAdminCurItem('mallvouchertemplateadd');
  96. return View::fetch();
  97. }
  98. }
  99. /*
  100. * 添加代金券页面
  101. */
  102. public function mallvouchertemplateedit() {
  103. $id = intval(input('param.mallvouchertemplate_id'));
  104. if ($id <= 0) {
  105. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  106. }
  107. if (request()->isPost()) {
  108. $mallvouchertemplate_model = model('mallvouchertemplate');
  109. $goodsclass_model = model('goodsclass');
  110. //获取代金券所属分类ID集
  111. $gc_id = intval(input('post.mallvouchertemplate_gcid'));
  112. if($gc_id == 0){
  113. $this->error(lang('admin_mallvouchertemplate_gc_error'));
  114. }
  115. $gc_ids = ',';
  116. if($gc_id > 0){
  117. $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
  118. foreach($goodsclasslist as $key => $val){
  119. $gc_ids .= $val['gc_id'].',';
  120. }
  121. }
  122. $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
  123. $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
  124. $updata = [
  125. 'mallvouchertemplate_price' => $price,
  126. 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
  127. 'mallvouchertemplate_gcid' => $gc_id,
  128. 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
  129. 'mallvouchertemplate_limit' => $limit,
  130. 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
  131. 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
  132. 'mallvouchertemplate_gcidarr' => $gc_ids,
  133. 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
  134. 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
  135. 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
  136. ];
  137. if ($price >= $limit) {
  138. $this->error(lang('admin_mallvouchertemplate_limit_error'));
  139. }
  140. $condition = array();
  141. $condition[] = array('mallvouchertemplate_id','=',$id);
  142. $rs = $mallvouchertemplate_model->editMallvouchertemplate($condition,$updata);
  143. if ($rs) {
  144. $this->log(lang('ds_edit') . lang('admin_mallvouchertemplate_edit') . '[' . $updata['mallvouchertemplate_title'] . ']');
  145. $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
  146. } else {
  147. $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
  148. }
  149. }else {
  150. $mallvouchertemplate_model = model('mallvouchertemplate');
  151. $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
  152. if (empty($mallvouchertemplate_info)) {
  153. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  154. }
  155. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  156. View::assign('gc_list', $gc_list);
  157. View::assign('info', $mallvouchertemplate_info);
  158. View::assign('action', 'edit');
  159. $this->setAdminCurItem('mallvouchertemplateedit');
  160. return View::fetch();
  161. }
  162. }
  163. /*
  164. * 查看代金券面额
  165. */
  166. public function mallvouchertemplateview() {
  167. $id = intval(input('param.mallvouchertemplate_id'));
  168. if ($id <= 0) {
  169. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  170. }
  171. $mallvouchertemplate_model = model('mallvouchertemplate');
  172. $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
  173. if (empty($mallvouchertemplate_info)) {
  174. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  175. }
  176. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  177. View::assign('gc_list', $gc_list);
  178. View::assign('info', $mallvouchertemplate_info);
  179. View::assign('action', 'view');
  180. $this->setAdminCurItem('mallvouchertemplateview');
  181. return View::fetch('mallvouchertemplateview');
  182. }
  183. /*
  184. * 删除代金券面额
  185. */
  186. public function drop() {
  187. $mallvouchertemplate_id = trim(input('param.mallvouchertemplate_id'));
  188. if (empty($mallvouchertemplate_id)) {
  189. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  190. }
  191. $mallvouchertemplate_model = model('mallvouchertemplate');
  192. $condition = array();
  193. $condition[] = array('mallvouchertemplate_id','in', $mallvouchertemplate_id);
  194. $rs = $mallvouchertemplate_model->delMallvouchertemplate($condition);
  195. if ($rs) {
  196. $this->log(lang('ds_del') . lang('admin_mallvouchertemplate_drop') . '[ID:' . $mallvouchertemplate_id . ']');
  197. ds_json_encode(10000, lang('ds_common_del_succ'));
  198. } else {
  199. ds_json_encode(10001, lang('ds_common_del_fail'));
  200. }
  201. }
  202. /**
  203. * 页面内导航菜单
  204. * @param string $menu_key 当前导航的menu_key
  205. * @param array $array 附加菜单
  206. * @return
  207. */
  208. protected function getAdminItemList() {
  209. $menu_array = array(
  210. array(
  211. 'name' => 'mallvouchertemplatelist',
  212. 'text' => lang('admin_mallvouchertemplate_manage'),
  213. 'url' => (string)url('Mallvouchertemplate/mallvouchertemplatelist')
  214. )
  215. );
  216. if (request()->action() == 'mallvouchertemplateadd' || request()->action() == 'mallvouchertemplatelist') {
  217. $menu_array[] = array(
  218. 'name' => 'mallvouchertemplateadd',
  219. 'text' => lang('admin_mallvouchertemplate_add'),
  220. 'url' => (string) url('Mallvouchertemplate/mallvouchertemplateadd')
  221. );
  222. }
  223. if (request()->action() == 'mallvouchertemplateview') {
  224. $menu_array[] = array(
  225. 'name' => 'mallvouchertemplateview',
  226. 'text' => lang('admin_mallvouchertemplate_view'),
  227. 'url' => ''
  228. );
  229. }
  230. if (request()->action() == 'mallvouchertemplateedit') {
  231. $menu_array[] = array(
  232. 'name' => 'mallvouchertemplateedit',
  233. 'text' => lang('admin_mallvouchertemplate_edit'),
  234. 'url' => ''
  235. );
  236. }
  237. return $menu_array;
  238. }
  239. }