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