Mallvouchertemplate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Mallvouchertemplate extends AdminControl
  16. {
  17. private $quotastate_arr;
  18. private $templatestate_arr;
  19. public function initialize()
  20. {
  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. //获得代金券金额列表
  33. $mallvouchertemplate_model = model('mallvouchertemplate');
  34. $condition = array();
  35. $mallvouchertemplate_list = $mallvouchertemplate_model->getMallvouchertemplateList($condition, 10);
  36. View::assign('mallvouchertemplate_list', $mallvouchertemplate_list);
  37. View::assign('show_page', $mallvouchertemplate_model->page_info->render());
  38. $this->setAdminCurItem('mallvouchertemplatelist');
  39. return View::fetch();
  40. }
  41. /*
  42. * 添加代金券页面
  43. */
  44. public function mallvouchertemplateadd()
  45. {
  46. if (request()->isPost()) {
  47. $mallvouchertemplate_model = model('mallvouchertemplate');
  48. $goodsclass_model = model('goodsclass');
  49. //获取代金券所属分类ID集
  50. $gc_id = intval(input('post.mallvouchertemplate_gcid'));
  51. if ($gc_id == 0) {
  52. $this->error(lang('admin_mallvouchertemplate_gc_error'));
  53. }
  54. $gc_ids = ',';
  55. $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
  56. foreach ($goodsclasslist as $key => $val) {
  57. $gc_ids .= $val['gc_id'] . ',';
  58. }
  59. $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
  60. $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
  61. $data = [
  62. 'mallvouchertemplate_price' => $price,
  63. 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
  64. 'mallvouchertemplate_gcid' => $gc_id,
  65. 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
  66. 'mallvouchertemplate_limit' => $limit,
  67. 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
  68. 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
  69. 'mallvouchertemplate_gcidarr' => $gc_ids,
  70. 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
  71. 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
  72. 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
  73. ];
  74. if ($price >= $limit) {
  75. $this->error(lang('admin_mallvouchertemplate_limit_error'));
  76. }
  77. $rs = $mallvouchertemplate_model->addmallvouchertemplate($data);
  78. if ($rs) {
  79. $this->log(lang('ds_add') . lang('admin_mallvouchertemplate_add') . '[' . $data['mallvouchertemplate_title'] . ']');
  80. $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
  81. } else {
  82. $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
  83. }
  84. } else {
  85. $mallvouchertemplate_info = array(
  86. 'mallvouchertemplate_startdate' => TIMESTAMP,
  87. 'mallvouchertemplate_enddate' => TIMESTAMP + 3600 * 24 * 7,
  88. 'mallvouchertemplate_gcid' => '',
  89. 'mallvouchertemplate_quantity' => '',
  90. 'mallvouchertemplate_eachlimit' => ''
  91. );
  92. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  93. View::assign('gc_list', $gc_list);
  94. View::assign('info', $mallvouchertemplate_info);
  95. View::assign('action', 'add');
  96. $this->setAdminCurItem('mallvouchertemplateadd');
  97. return View::fetch();
  98. }
  99. }
  100. /*
  101. * 添加代金券页面
  102. */
  103. public function mallvouchertemplateedit()
  104. {
  105. $id = intval(input('param.mallvouchertemplate_id'));
  106. if ($id <= 0) {
  107. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  108. }
  109. if (request()->isPost()) {
  110. $mallvouchertemplate_model = model('mallvouchertemplate');
  111. $goodsclass_model = model('goodsclass');
  112. //获取代金券所属分类ID集
  113. $gc_id = intval(input('post.mallvouchertemplate_gcid'));
  114. if ($gc_id == 0) {
  115. $this->error(lang('admin_mallvouchertemplate_gc_error'));
  116. }
  117. $gc_ids = ',';
  118. if ($gc_id > 0) {
  119. $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
  120. foreach ($goodsclasslist as $key => $val) {
  121. $gc_ids .= $val['gc_id'] . ',';
  122. }
  123. }
  124. $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
  125. $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
  126. $updata = [
  127. 'mallvouchertemplate_price' => $price,
  128. 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
  129. 'mallvouchertemplate_gcid' => $gc_id,
  130. 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
  131. 'mallvouchertemplate_limit' => $limit,
  132. 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
  133. 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
  134. 'mallvouchertemplate_gcidarr' => $gc_ids,
  135. 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
  136. 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
  137. 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
  138. ];
  139. if ($price >= $limit) {
  140. $this->error(lang('admin_mallvouchertemplate_limit_error'));
  141. }
  142. $condition = array();
  143. $condition[] = array('mallvouchertemplate_id', '=', $id);
  144. $rs = $mallvouchertemplate_model->editMallvouchertemplate($condition, $updata);
  145. if ($rs) {
  146. $this->log(lang('ds_edit') . lang('admin_mallvouchertemplate_edit') . '[' . $updata['mallvouchertemplate_title'] . ']');
  147. $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
  148. } else {
  149. $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
  150. }
  151. } else {
  152. $mallvouchertemplate_model = model('mallvouchertemplate');
  153. $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
  154. if (empty($mallvouchertemplate_info)) {
  155. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  156. }
  157. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  158. View::assign('gc_list', $gc_list);
  159. View::assign('info', $mallvouchertemplate_info);
  160. View::assign('action', 'edit');
  161. $this->setAdminCurItem('mallvouchertemplateedit');
  162. return View::fetch();
  163. }
  164. }
  165. /*
  166. * 查看代金券面额
  167. */
  168. public function mallvouchertemplateview()
  169. {
  170. $id = intval(input('param.mallvouchertemplate_id'));
  171. if ($id <= 0) {
  172. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  173. }
  174. $mallvouchertemplate_model = model('mallvouchertemplate');
  175. $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
  176. if (empty($mallvouchertemplate_info)) {
  177. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  178. }
  179. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  180. View::assign('gc_list', $gc_list);
  181. View::assign('info', $mallvouchertemplate_info);
  182. View::assign('action', 'view');
  183. $this->setAdminCurItem('mallvouchertemplateview');
  184. return View::fetch('mallvouchertemplateview');
  185. }
  186. /*
  187. * 删除代金券面额
  188. */
  189. public function drop()
  190. {
  191. $mallvouchertemplate_id = trim(input('param.mallvouchertemplate_id'));
  192. if (empty($mallvouchertemplate_id)) {
  193. $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
  194. }
  195. $mallvouchertemplate_model = model('mallvouchertemplate');
  196. $condition = array();
  197. $condition[] = array('mallvouchertemplate_id', 'in', $mallvouchertemplate_id);
  198. $rs = $mallvouchertemplate_model->delMallvouchertemplate($condition);
  199. if ($rs) {
  200. $this->log(lang('ds_del') . lang('admin_mallvouchertemplate_drop') . '[ID:' . $mallvouchertemplate_id . ']');
  201. ds_json_encode(10000, lang('ds_common_del_succ'));
  202. } else {
  203. ds_json_encode(10001, lang('ds_common_del_fail'));
  204. }
  205. }
  206. /**
  207. * 页面内导航菜单
  208. * @param string $menu_key 当前导航的menu_key
  209. * @param array $array 附加菜单
  210. * @return
  211. */
  212. protected function getAdminItemList()
  213. {
  214. $menu_array = array(
  215. array(
  216. 'name' => 'mallvouchertemplatelist',
  217. 'text' => lang('admin_mallvouchertemplate_manage'),
  218. 'url' => (string)url('Mallvouchertemplate/mallvouchertemplatelist')
  219. )
  220. );
  221. if (request()->action() == 'mallvouchertemplateadd' || request()->action() == 'mallvouchertemplatelist') {
  222. $menu_array[] = array(
  223. 'name' => 'mallvouchertemplateadd',
  224. 'text' => lang('admin_mallvouchertemplate_add'),
  225. 'url' => (string) url('Mallvouchertemplate/mallvouchertemplateadd')
  226. );
  227. }
  228. if (request()->action() == 'mallvouchertemplateview') {
  229. $menu_array[] = array(
  230. 'name' => 'mallvouchertemplateview',
  231. 'text' => lang('admin_mallvouchertemplate_view'),
  232. 'url' => ''
  233. );
  234. }
  235. if (request()->action() == 'mallvouchertemplateedit') {
  236. $menu_array[] = array(
  237. 'name' => 'mallvouchertemplateedit',
  238. 'text' => lang('admin_mallvouchertemplate_edit'),
  239. 'url' => ''
  240. );
  241. }
  242. return $menu_array;
  243. }
  244. }