Sellervoucher.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. * DSMall多用户商城
  9. * ============================================================================
  10. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  11. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Sellervoucher extends BaseSeller {
  19. private $quotastate_arr;
  20. private $templatestate_arr;
  21. public function initialize() {
  22. parent::initialize(); // TODO: Change the autogenerated stub
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervoucher.lang.php');
  24. if (config('ds_config.voucher_allow') != 1) {
  25. $this->error(lang('voucher_unavailable'), 'seller/index');
  26. }
  27. //套餐状态
  28. $this->quotastate_arr = array(
  29. 'activity' => array(1, lang('voucher_quotastate_activity')),
  30. 'cancel' => array(2, lang('voucher_quotastate_cancel')),
  31. 'expire' => array(3, lang('voucher_quotastate_expire'))
  32. );
  33. //代金券模板状态
  34. $this->templatestate_arr = array(
  35. 'usable' => array(1, lang('voucher_templatestate_usable')),
  36. 'disabled' => array(2, lang('voucher_templatestate_disabled'))
  37. );
  38. View::assign('quotastate_arr', $this->quotastate_arr);
  39. View::assign('templatestate_arr', $this->templatestate_arr);
  40. }
  41. public function templatelist() {
  42. //检查过期的代金券模板状态设为失效
  43. $this->check_voucher_template_expire();
  44. $voucher_model = model('voucher');
  45. if (check_platform_store()) {
  46. View::assign('isPlatformStore', true);
  47. } else {
  48. //查询是否存在可用套餐
  49. $current_quota = $voucher_model->getVoucherquotaCurrent(session('store_id'));
  50. View::assign('current_quota', $current_quota);
  51. }
  52. //查询列表
  53. $param = array();
  54. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  55. if (trim(input('param.txt_keyword'))) {
  56. $param[] = array('vouchertemplate_title', 'like', '%' . trim(input('param.txt_keyword')) . '%');
  57. }
  58. $select_state = intval(input('param.select_state'));
  59. if ($select_state) {
  60. $param[] = array('vouchertemplate_state', '=', $select_state);
  61. }
  62. if (input('param.txt_startdate')) {
  63. $param[] = array('vouchertemplate_enddate', '>=', strtotime(input('param.txt_startdate')));
  64. }
  65. if (input('param.txt_enddate')) {
  66. $param[] = array('vouchertemplate_startdate', '<=', strtotime(input('param.txt_enddate'))+86399);
  67. }
  68. $vouchertemplate_list = Db::name('vouchertemplate')->where($param)->order('vouchertemplate_id desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  69. View::assign('show_page', $vouchertemplate_list->render());
  70. $vouchertemplate_list = $vouchertemplate_list->items();
  71. foreach ($vouchertemplate_list as $key => $val) {
  72. if (!$val['vouchertemplate_customimg']) {
  73. $vouchertemplate_list[$key]['vouchertemplate_customimg'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  74. } else {
  75. $vouchertemplate_list[$key]['vouchertemplate_customimg'] = ds_get_pic( ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') , $val['vouchertemplate_customimg']);
  76. }
  77. }
  78. $this->setSellerCurMenu('Sellervoucher');
  79. $this->setSellerCurItem('templatelist');
  80. View::assign('vouchertemplate_list', $vouchertemplate_list);
  81. return View::fetch($this->template_dir . 'index');
  82. }
  83. /**
  84. * 购买套餐
  85. */
  86. public function quotaadd() {
  87. if (request()->isPost()) {
  88. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  89. ds_json_encode(10001, lang('param_error'));
  90. }
  91. $quota_quantity = intval(input('post.quota_quantity'));
  92. if ($quota_quantity <= 0 || $quota_quantity > 12) {
  93. ds_json_encode(10001, lang('voucher_apply_num_error'));
  94. }
  95. //获取当前价格
  96. $current_price = intval(config('ds_config.promotion_voucher_price'));
  97. $voucher_model = model('voucher');
  98. //获取该用户已有套餐
  99. $current_quota = $voucher_model->getVoucherquotaCurrent(session('store_id'));
  100. $quota_add_time = 86400 * 30 * $quota_quantity;
  101. if (empty($current_quota)) {
  102. //生成套餐
  103. $param = array();
  104. $param['voucherquota_memberid'] = session('member_id');
  105. $param['voucherquota_membername'] = session('member_name');
  106. $param['voucherquota_storeid'] = session('store_id');
  107. $param['voucherquota_storename'] = session('store_name');
  108. $param['voucherquota_starttime'] = TIMESTAMP;
  109. $param['voucherquota_endtime'] = TIMESTAMP + $quota_add_time;
  110. $param['voucherquota_state'] = 1;
  111. $reault = Db::name('voucherquota')->insert($param);
  112. } else {
  113. $param = array();
  114. $param['voucherquota_endtime'] = Db::raw('voucherquota_endtime+' . $quota_add_time);
  115. $reault = Db::name('voucherquota')->where(array('voucherquota_id' => $current_quota['voucherquota_id']))->update($param);
  116. }
  117. //记录店铺费用
  118. $this->recordStorecost($current_price * $quota_quantity, lang('buy_voucher_package'));
  119. $this->recordSellerlog(lang('buy') . $quota_quantity . lang('voucher_plan') . $current_price . lang('ds_yuan'));
  120. if ($reault) {
  121. ds_json_encode(10000, lang('voucher_apply_buy_succ'));
  122. } else {
  123. ds_json_encode(10001, lang('ds_common_op_fail'));
  124. }
  125. } else {
  126. //输出导航
  127. $this->setSellerCurMenu('Sellervoucher');
  128. $this->setSellerCurItem('quotaadd');
  129. return View::fetch($this->template_dir . 'quota_add');
  130. }
  131. }
  132. /*
  133. * 代金券模版添加
  134. */
  135. public function templateadd() {
  136. $voucher_model = model('voucher');
  137. $isPlatformStore = check_platform_store();
  138. View::assign('isPlatformStore', $isPlatformStore);
  139. $quotainfo = array();
  140. if (!$isPlatformStore) {
  141. //查询当前可以使用的套餐
  142. $quotainfo = $voucher_model->getVoucherquotaCurrent(session('store_id'));
  143. if (empty($quotainfo)) {
  144. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  145. $quotainfo = array('voucherquota_id' => 0, 'voucherquota_starttime' => TIMESTAMP, 'voucherquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  146. } else {
  147. $this->error(lang('voucher_template_quotanull'), 'Sellervoucher/quotaadd');
  148. }
  149. }
  150. //查询该套餐下代金券模板列表
  151. $count = Db::name('vouchertemplate')->where(array('vouchertemplate_quotaid' => $quotainfo['voucherquota_id'], 'vouchertemplate_state' => $this->templatestate_arr['usable'][0]))->count();
  152. if ($count >= config('ds_config.voucher_storetimes_limit')) {
  153. $message = sprintf(lang('voucher_template_noresidual'), config('ds_config.voucher_storetimes_limit'));
  154. $this->error($message, 'Sellervoucher/templatelist');
  155. }
  156. }
  157. //查询面额列表
  158. $pricelist = Db::name('voucherprice')->order('voucherprice asc')->select()->toArray();
  159. if (empty($pricelist)) {
  160. $this->error(lang('voucher_template_pricelisterror'), 'Sellervoucher/templatelist');
  161. }
  162. if (request()->isPost()) {
  163. //验证提交的内容面额不能大于限额
  164. $data = [
  165. 'txt_template_title' => input('post.txt_template_title'),
  166. 'txt_template_total' => input('post.txt_template_total'),
  167. 'select_template_price' => input('post.select_template_price'),
  168. 'txt_template_limit' => input('post.txt_template_limit'),
  169. 'txt_template_describe' => input('post.txt_template_describe'),
  170. ];
  171. $sellervoucher_validate = ds_validate('sellervoucher');
  172. if (!$sellervoucher_validate->scene('templateadd')->check($data)) {
  173. $this->error($sellervoucher_validate->getError());
  174. }
  175. //金额验证
  176. $price = intval(input('post.select_template_price')) > 0 ? intval(input('post.select_template_price')) : 0;
  177. foreach ($pricelist as $k => $v) {
  178. if ($v['voucherprice'] == $price) {
  179. $chooseprice = $v; //取得当前选择的面额记录
  180. }
  181. }
  182. if (empty($chooseprice)) {
  183. $this->error(lang('voucher_template_pricelisterror'));
  184. }
  185. $limit = intval(input('post.txt_template_limit')) > 0 ? intval(input('post.txt_template_limit')) : 0;
  186. if ($price >= $limit) {
  187. $this->error(lang('voucher_template_price_error'));
  188. }
  189. $insert_arr = array();
  190. $insert_arr['vouchertemplate_title'] = trim(input('post.txt_template_title'));
  191. $insert_arr['vouchertemplate_desc'] = trim(input('post.txt_template_describe'));
  192. $insert_arr['vouchertemplate_startdate'] = TIMESTAMP; //默认代金券模板的有效期为当前时间
  193. if (input('post.txt_template_enddate')) {
  194. $enddate = strtotime(input('post.txt_template_enddate'));
  195. if (!$isPlatformStore && $enddate > $quotainfo['voucherquota_endtime']) {
  196. $enddate = $quotainfo['voucherquota_endtime'];
  197. }
  198. $insert_arr['vouchertemplate_enddate'] = $enddate;
  199. } else {//如果没有添加有效期则默认为套餐的结束时间
  200. if ($isPlatformStore)
  201. $insert_arr['vouchertemplate_enddate'] = TIMESTAMP + 2592000; // 自营店 默认30天到期
  202. else
  203. $insert_arr['vouchertemplate_enddate'] = $quotainfo['voucherquota_endtime'];
  204. }
  205. $insert_arr['vouchertemplate_price'] = $price;
  206. $insert_arr['vouchertemplate_limit'] = $limit;
  207. $insert_arr['vouchertemplate_store_id'] = session('store_id');
  208. $insert_arr['vouchertemplate_storename'] = session('store_name');
  209. $insert_arr['vouchertemplate_sc_id'] = intval(input('post.storeclass_id'));
  210. $insert_arr['vouchertemplate_creator_id'] = session('member_id');
  211. $insert_arr['vouchertemplate_state'] = $this->templatestate_arr['usable'][0];
  212. $insert_arr['vouchertemplate_total'] = intval(input('post.txt_template_total')) > 0 ? intval(input('post.txt_template_total')) : 0;
  213. $insert_arr['vouchertemplate_giveout'] = 0;
  214. $insert_arr['vouchertemplate_used'] = 0;
  215. $insert_arr['vouchertemplate_gettype'] = 1;
  216. $insert_arr['vouchertemplate_adddate'] = TIMESTAMP;
  217. $insert_arr['vouchertemplate_quotaid'] = isset($quotainfo['voucherquota_id']) ? $quotainfo['voucherquota_id'] : 0;
  218. $insert_arr['vouchertemplate_points'] = $chooseprice['voucherprice_defaultpoints'];
  219. $insert_arr['vouchertemplate_eachlimit'] = intval(input('post.eachlimit')) > 0 ? intval(input('post.eachlimit')) : 0;
  220. //自定义图片
  221. if (!empty($_FILES['customimg']['name'])) {
  222. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  223. $res=ds_upload_pic(ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id'),'customimg', $file_name);
  224. if($res['code']){
  225. $file_name=$res['data']['file_name'];
  226. $insert_arr['vouchertemplate_customimg'] = $file_name;
  227. }else{
  228. $this->error($res['msg']);
  229. }
  230. }
  231. $rs = Db::name('vouchertemplate')->insert($insert_arr);
  232. if ($rs) {
  233. $this->success(lang('ds_common_save_succ'), (string) url('Sellervoucher/templatelist'));
  234. } else {
  235. $this->error(lang('ds_common_save_fail'), (string) url('Sellervoucher/templatelist'));
  236. }
  237. } else {
  238. //店铺分类
  239. $store_class = rkcache('storeclass', true);
  240. View::assign('store_class', $store_class);
  241. //查询店铺详情
  242. $store_info = model('store')->getStoreInfoByID(session('store_id'));
  243. View::assign('store_info', $store_info);
  244. View::assign('type', 'add');
  245. View::assign('quotainfo', $quotainfo);
  246. View::assign('pricelist', $pricelist);
  247. $t_info = array(
  248. 'vouchertemplate_title' => '',
  249. 'vouchertemplate_price' => '',
  250. 'vouchertemplate_total' => '',
  251. 'vouchertemplate_limit' => '',
  252. 'vouchertemplate_desc' => '',
  253. 'vouchertemplate_customimg' => '',
  254. 'vouchertemplate_enddate' => '',
  255. 'vouchertemplate_eachlimit' => 0,
  256. 'vouchertemplate_sc_id' => '',
  257. );
  258. View::assign('t_info', $t_info);
  259. $this->setSellerCurMenu('Sellervoucher');
  260. $this->setSellerCurItem('templateadd');
  261. return View::fetch($this->template_dir . 'templateadd');
  262. }
  263. }
  264. /*
  265. * 代金券模版编辑
  266. */
  267. public function templateedit() {
  268. $t_id = intval(input('param.tid'));
  269. if ($t_id <= 0) {
  270. $this->error(lang('param_error'), (string) url('Sellervoucher/templatelist'));
  271. }
  272. //查询模板信息
  273. $param = array();
  274. $param[] = array('vouchertemplate_id', '=', $t_id);
  275. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  276. $param[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  277. $param[] = array('vouchertemplate_giveout', '<=', '0');
  278. $param[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
  279. $t_info = Db::name('vouchertemplate')->where($param)->find();
  280. if (empty($t_info)) {
  281. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  282. }
  283. $isPlatformStore = check_platform_store();
  284. View::assign('isPlatformStore', $isPlatformStore);
  285. $quotainfo = array();
  286. if (!$isPlatformStore) {
  287. //查询套餐信息
  288. $quotainfo = Db::name('voucherquota')->where(array(
  289. 'voucherquota_id' => $t_info['vouchertemplate_quotaid'],
  290. 'voucherquota_storeid' => session('store_id')
  291. ))->find();
  292. if (empty($quotainfo)) {
  293. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  294. $quotainfo = array('voucherquota_id' => 0, 'voucherquota_starttime' => TIMESTAMP, 'voucherquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  295. } else {
  296. $this->error(lang('voucher_template_quotanull'), 'Sellervoucher/quotaadd');
  297. }
  298. }
  299. }
  300. //查询面额列表
  301. $pricelist = Db::name('voucherprice')->order('voucherprice asc')->select()->toArray();
  302. if (empty($pricelist)) {
  303. $this->error(lang('voucher_template_pricelisterror'), 'Sellervoucher/templatelist');
  304. }
  305. if (request()->isPost()) {
  306. //验证提交的内容面额不能大于限额
  307. $data = [
  308. 'txt_template_title' => input('post.txt_template_title'),
  309. 'txt_template_total' => input('post.txt_template_total'),
  310. 'select_template_price' => input('post.select_template_price'),
  311. 'txt_template_limit' => input('post.txt_template_limit'),
  312. 'txt_template_describe' => input('post.txt_template_describe'),
  313. ];
  314. $sellervoucher_validate = ds_validate('sellervoucher');
  315. if (!$sellervoucher_validate->scene('templateedit')->check($data)) {
  316. $this->error($sellervoucher_validate->getError());
  317. }
  318. //金额验证
  319. $price = intval(input('post.select_template_price')) > 0 ? intval(input('post.select_template_price')) : 0;
  320. foreach ($pricelist as $k => $v) {
  321. if ($v['voucherprice'] == $price) {
  322. $chooseprice = $v; //取得当前选择的面额记录
  323. }
  324. }
  325. if (empty($chooseprice)) {
  326. $this->error(lang('voucher_template_pricelisterror'));
  327. }
  328. $limit = intval(input('post.txt_template_limit')) > 0 ? intval(input('post.txt_template_limit')) : 0;
  329. if ($price >= $limit) {
  330. $this->error(lang('voucher_template_price_error'));
  331. }
  332. $update_arr = array();
  333. $update_arr['vouchertemplate_title'] = trim(input('post.txt_template_title'));
  334. $update_arr['vouchertemplate_desc'] = trim(input('post.txt_template_describe'));
  335. if (input('post.txt_template_enddate')) {
  336. $enddate = strtotime(input('post.txt_template_enddate'));
  337. if (!$isPlatformStore && $enddate > $quotainfo['voucherquota_endtime']) {
  338. $enddate = $quotainfo['voucherquota_endtime'];
  339. }
  340. $update_arr['vouchertemplate_enddate'] = $enddate;
  341. } else {//如果没有添加有效期则默认为套餐的结束时间
  342. if ($isPlatformStore)
  343. $update_arr['vouchertemplate_enddate'] = TIMESTAMP + 2592000; // 自营店 默认30天到期
  344. else
  345. $update_arr['vouchertemplate_enddate'] = $quotainfo['voucherquota_endtime'];
  346. }
  347. $update_arr['vouchertemplate_price'] = $price;
  348. $update_arr['vouchertemplate_limit'] = $limit;
  349. $update_arr['vouchertemplate_sc_id'] = intval(input('post.storeclass_id'));
  350. $update_arr['vouchertemplate_state'] = intval(input('post.tstate')) == $this->templatestate_arr['usable'][0] ? $this->templatestate_arr['usable'][0] : $this->templatestate_arr['disabled'][0];
  351. $update_arr['vouchertemplate_total'] = intval(input('post.txt_template_total')) > 0 ? intval(input('post.txt_template_total')) : 0;
  352. $update_arr['vouchertemplate_points'] = $chooseprice['voucherprice_defaultpoints'];
  353. $update_arr['vouchertemplate_eachlimit'] = intval(input('post.eachlimit')) > 0 ? intval(input('post.eachlimit')) : 0;
  354. //自定义图片
  355. if (!empty($_FILES['customimg']['name'])) {
  356. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  357. $res=ds_upload_pic(ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id'),'customimg', $file_name);
  358. if($res['code']){
  359. $file_name=$res['data']['file_name'];
  360. //删除原图
  361. if (!empty($t_info['vouchertemplate_customimg'])) {//如果模板存在,则删除原模板图片
  362. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  363. }
  364. $update_arr['vouchertemplate_customimg'] = $file_name;
  365. }else{
  366. $this->error($res['msg']);
  367. }
  368. }
  369. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->update($update_arr);
  370. if ($rs) {
  371. $this->success(lang('ds_common_op_succ'), (string) url('Sellervoucher/templatelist'));
  372. } else {
  373. $this->error(lang('ds_common_op_fail'), (string) url('Sellervoucher/templatelist'));
  374. }
  375. } else {
  376. if (!$t_info['vouchertemplate_customimg']) {
  377. $t_info['vouchertemplate_customimg'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  378. } else {
  379. $t_info['vouchertemplate_customimg'] = ds_get_pic( ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') , $t_info['vouchertemplate_customimg']);
  380. }
  381. View::assign('type', 'edit');
  382. View::assign('t_info', $t_info);
  383. //店铺分类
  384. $store_class = rkcache('storeclass', true);
  385. View::assign('store_class', $store_class);
  386. //查询店铺详情
  387. $store_info = model('store')->getStoreInfoByID(session('store_id'));
  388. View::assign('store_info', $store_info);
  389. View::assign('quotainfo', $quotainfo);
  390. View::assign('pricelist', $pricelist);
  391. $this->setSellerCurMenu('Sellervoucher');
  392. $this->setSellerCurItem('templateedit');
  393. return View::fetch($this->template_dir . 'templateadd');
  394. }
  395. }
  396. /**
  397. * 删除代金券
  398. */
  399. public function templatedel() {
  400. $t_id = intval(input('param.tid'));
  401. if ($t_id <= 0) {
  402. ds_json_encode(10001, lang('param_error'));
  403. }
  404. //查询模板信息
  405. $param = array();
  406. $param[] = array('vouchertemplate_id', '=', $t_id);
  407. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  408. $param[] = array('vouchertemplate_giveout', '<=', '0'); //会员没领取过代金券才可删除
  409. $t_info = Db::name('vouchertemplate')->where($param)->find();
  410. if (empty($t_info)) {
  411. ds_json_encode(10001, lang('param_error'));
  412. }
  413. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->delete();
  414. if ($rs) {
  415. //删除自定义的图片
  416. if (trim($t_info['vouchertemplate_customimg'])) {
  417. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  418. }
  419. ds_json_encode(10000, lang('ds_common_del_succ'));
  420. } else {
  421. ds_json_encode(10001, lang('ds_common_del_fail'));
  422. }
  423. }
  424. /**
  425. * 查看代金券详细
  426. */
  427. public function templateinfo() {
  428. $t_id = intval(input('param.tid'));
  429. if ($t_id <= 0) {
  430. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  431. }
  432. //查询模板信息
  433. $param = array();
  434. $param['vouchertemplate_id'] = $t_id;
  435. $param['vouchertemplate_store_id'] = session('store_id');
  436. $t_info = Db::name('vouchertemplate')->where($param)->find();
  437. View::assign('t_info', $t_info);
  438. $this->setSellerCurMenu('Sellervoucher');
  439. $this->setSellerCurItem('templateinfo');
  440. return View::fetch($this->template_dir . 'template_info');
  441. }
  442. /*
  443. * 把代金券模版设为失效
  444. */
  445. private function check_voucher_template_expire($voucher_template_id = '') {
  446. $where_array = array();
  447. if (empty($voucher_template_id)) {
  448. $where_array[] = array('vouchertemplate_enddate', '<', TIMESTAMP);
  449. } else {
  450. $where_array[] = array('vouchertemplate_id', '=', $voucher_template_id);
  451. }
  452. $where_array[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  453. Db::name('vouchertemplate')->where($where_array)->update(array('vouchertemplate_state' => $this->templatestate_arr['disabled'][0]));
  454. }
  455. /**
  456. * 用户中心右边,小导航
  457. *
  458. * @param string $menu_type 导航类型
  459. * @param string $menu_key 当前导航的menu_key
  460. * @return
  461. */
  462. protected function getSellerItemList() {
  463. $menu_array = array();
  464. switch (request()->action()) {
  465. case 'templatelist':
  466. $menu_array = array(
  467. 1 => array(
  468. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  469. 'url' => (string) url('Sellervoucher/templatelist')
  470. ),
  471. );
  472. break;
  473. case 'quotaadd':
  474. $menu_array = array(
  475. array(
  476. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  477. 'url' => (string) url('Sellervoucher/templatelist')
  478. ), array(
  479. 'name' => 'quotaadd', 'text' => lang('voucher_applyadd'), 'url' => (string) url('Sellervoucher/quotaadd')
  480. )
  481. );
  482. break;
  483. case 'templateadd':
  484. $menu_array = array(
  485. 1 => array(
  486. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  487. 'url' => (string) url('Sellervoucher/templatelist')
  488. ), 2 => array(
  489. 'name' => 'templateadd', 'text' => lang('voucher_templateadd'),
  490. 'url' => (string) url('Sellervoucher/templateadd')
  491. ),
  492. );
  493. break;
  494. case 'templateedit':
  495. $menu_array = array(
  496. 1 => array(
  497. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  498. 'url' => (string) url('Sellervoucher/templatelist')
  499. ), 2 => array(
  500. 'name' => 'templateedit', 'text' => lang('voucher_templateedit'), 'url' => ''
  501. ),
  502. );
  503. break;
  504. case 'templateinfo':
  505. $menu_array = array(
  506. 1 => array(
  507. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  508. 'url' => (string) url('Sellervoucher/templatelist')
  509. ), 2 => array(
  510. 'name' => 'templateinfo', 'text' => lang('voucher_templateinfo'), 'url' => ''
  511. ),
  512. );
  513. break;
  514. }
  515. return $menu_array;
  516. }
  517. }