Sellervoucher.php 28 KB

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