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