123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- namespace app\admin\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Mallvouchertemplate extends AdminControl
- {
- private $quotastate_arr;
- private $templatestate_arr;
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/mallvouchertemplate.lang.php');
- if (config('ds_config.voucher_allow') != 1 || config('ds_config.points_isuse') != 1) {
- $this->error(lang('admin_voucher_unavailable'), 'operation/setting');
- }
- }
- /*
- * 代金券面额列表
- */
- public function mallvouchertemplatelist()
- {
- //获得代金券金额列表
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $condition = array();
- $mallvouchertemplate_list = $mallvouchertemplate_model->getMallvouchertemplateList($condition, 10);
- View::assign('mallvouchertemplate_list', $mallvouchertemplate_list);
- View::assign('show_page', $mallvouchertemplate_model->page_info->render());
- $this->setAdminCurItem('mallvouchertemplatelist');
- return View::fetch();
- }
- /*
- * 添加代金券页面
- */
- public function mallvouchertemplateadd()
- {
- if (request()->isPost()) {
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $goodsclass_model = model('goodsclass');
- //获取代金券所属分类ID集
- $gc_id = intval(input('post.mallvouchertemplate_gcid'));
- if ($gc_id == 0) {
- $this->error(lang('admin_mallvouchertemplate_gc_error'));
- }
- $gc_ids = ',';
- $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
- foreach ($goodsclasslist as $key => $val) {
- $gc_ids .= $val['gc_id'] . ',';
- }
- $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
- $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
- $data = [
- 'mallvouchertemplate_price' => $price,
- 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
- 'mallvouchertemplate_gcid' => $gc_id,
- 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
- 'mallvouchertemplate_limit' => $limit,
- 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
- 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
- 'mallvouchertemplate_gcidarr' => $gc_ids,
- 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
- 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
- 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
- ];
- if ($price >= $limit) {
- $this->error(lang('admin_mallvouchertemplate_limit_error'));
- }
- $rs = $mallvouchertemplate_model->addmallvouchertemplate($data);
- if ($rs) {
- $this->log(lang('ds_add') . lang('admin_mallvouchertemplate_add') . '[' . $data['mallvouchertemplate_title'] . ']');
- $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
- } else {
- $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
- }
- } else {
- $mallvouchertemplate_info = array(
- 'mallvouchertemplate_startdate' => TIMESTAMP,
- 'mallvouchertemplate_enddate' => TIMESTAMP + 3600 * 24 * 7,
- 'mallvouchertemplate_gcid' => '',
- 'mallvouchertemplate_quantity' => '',
- 'mallvouchertemplate_eachlimit' => ''
- );
- $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
- View::assign('gc_list', $gc_list);
- View::assign('info', $mallvouchertemplate_info);
- View::assign('action', 'add');
- $this->setAdminCurItem('mallvouchertemplateadd');
- return View::fetch();
- }
- }
- /*
- * 添加代金券页面
- */
- public function mallvouchertemplateedit()
- {
- $id = intval(input('param.mallvouchertemplate_id'));
- if ($id <= 0) {
- $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
- }
- if (request()->isPost()) {
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $goodsclass_model = model('goodsclass');
- //获取代金券所属分类ID集
- $gc_id = intval(input('post.mallvouchertemplate_gcid'));
- if ($gc_id == 0) {
- $this->error(lang('admin_mallvouchertemplate_gc_error'));
- }
- $gc_ids = ',';
- if ($gc_id > 0) {
- $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
- foreach ($goodsclasslist as $key => $val) {
- $gc_ids .= $val['gc_id'] . ',';
- }
- }
- $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
- $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
- $updata = [
- 'mallvouchertemplate_price' => $price,
- 'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
- 'mallvouchertemplate_gcid' => $gc_id,
- 'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
- 'mallvouchertemplate_limit' => $limit,
- 'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
- 'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
- 'mallvouchertemplate_gcidarr' => $gc_ids,
- 'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
- 'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
- 'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
- ];
- if ($price >= $limit) {
- $this->error(lang('admin_mallvouchertemplate_limit_error'));
- }
- $condition = array();
- $condition[] = array('mallvouchertemplate_id', '=', $id);
- $rs = $mallvouchertemplate_model->editMallvouchertemplate($condition, $updata);
- if ($rs) {
- $this->log(lang('ds_edit') . lang('admin_mallvouchertemplate_edit') . '[' . $updata['mallvouchertemplate_title'] . ']');
- $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
- } else {
- $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
- }
- } else {
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
- if (empty($mallvouchertemplate_info)) {
- $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
- }
- $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
- View::assign('gc_list', $gc_list);
- View::assign('info', $mallvouchertemplate_info);
- View::assign('action', 'edit');
- $this->setAdminCurItem('mallvouchertemplateedit');
- return View::fetch();
- }
- }
- /*
- * 查看代金券面额
- */
- public function mallvouchertemplateview()
- {
- $id = intval(input('param.mallvouchertemplate_id'));
- if ($id <= 0) {
- $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
- }
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
- if (empty($mallvouchertemplate_info)) {
- $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
- }
- $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
- View::assign('gc_list', $gc_list);
- View::assign('info', $mallvouchertemplate_info);
- View::assign('action', 'view');
- $this->setAdminCurItem('mallvouchertemplateview');
- return View::fetch('mallvouchertemplateview');
- }
- /*
- * 删除代金券面额
- */
- public function drop()
- {
- $mallvouchertemplate_id = trim(input('param.mallvouchertemplate_id'));
- if (empty($mallvouchertemplate_id)) {
- $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
- }
- $mallvouchertemplate_model = model('mallvouchertemplate');
- $condition = array();
- $condition[] = array('mallvouchertemplate_id', 'in', $mallvouchertemplate_id);
- $rs = $mallvouchertemplate_model->delMallvouchertemplate($condition);
- if ($rs) {
- $this->log(lang('ds_del') . lang('admin_mallvouchertemplate_drop') . '[ID:' . $mallvouchertemplate_id . ']');
- ds_json_encode(10000, lang('ds_common_del_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- }
- /**
- * 页面内导航菜单
- * @param string $menu_key 当前导航的menu_key
- * @param array $array 附加菜单
- * @return
- */
- protected function getAdminItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'mallvouchertemplatelist',
- 'text' => lang('admin_mallvouchertemplate_manage'),
- 'url' => (string)url('Mallvouchertemplate/mallvouchertemplatelist')
- )
- );
- if (request()->action() == 'mallvouchertemplateadd' || request()->action() == 'mallvouchertemplatelist') {
- $menu_array[] = array(
- 'name' => 'mallvouchertemplateadd',
- 'text' => lang('admin_mallvouchertemplate_add'),
- 'url' => (string) url('Mallvouchertemplate/mallvouchertemplateadd')
- );
- }
- if (request()->action() == 'mallvouchertemplateview') {
- $menu_array[] = array(
- 'name' => 'mallvouchertemplateview',
- 'text' => lang('admin_mallvouchertemplate_view'),
- 'url' => ''
- );
- }
- if (request()->action() == 'mallvouchertemplateedit') {
- $menu_array[] = array(
- 'name' => 'mallvouchertemplateedit',
- 'text' => lang('admin_mallvouchertemplate_edit'),
- 'url' => ''
- );
- }
- return $menu_array;
- }
- }
|