Sellervoucher.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellervoucher extends BaseSeller {
  18. private $quotastate_arr;
  19. private $templatestate_arr;
  20. public function initialize() {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervoucher.lang.php');
  23. if (config('ds_config.voucher_allow') != 1) {
  24. $this->error(lang('voucher_unavailable'), 'seller/index');
  25. }
  26. //套餐状态
  27. $this->quotastate_arr = array(
  28. 'activity' => array(1, lang('voucher_quotastate_activity')),
  29. 'cancel' => array(2, lang('voucher_quotastate_cancel')),
  30. 'expire' => array(3, lang('voucher_quotastate_expire'))
  31. );
  32. //代金券模板状态
  33. $this->templatestate_arr = array(
  34. 'usable' => array(1, lang('voucher_templatestate_usable')),
  35. 'disabled' => array(2, lang('voucher_templatestate_disabled'))
  36. );
  37. View::assign('quotastate_arr', $this->quotastate_arr);
  38. View::assign('templatestate_arr', $this->templatestate_arr);
  39. }
  40. public function templatelist() {
  41. //检查过期的代金券模板状态设为失效
  42. $this->check_voucher_template_expire();
  43. $voucher_model = model('voucher');
  44. if (check_platform_store()) {
  45. View::assign('isPlatformStore', true);
  46. } else {
  47. //查询是否存在可用套餐
  48. $current_quota = $voucher_model->getVoucherquotaCurrent(session('store_id'));
  49. View::assign('current_quota', $current_quota);
  50. }
  51. //查询列表
  52. $param = array();
  53. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  54. if (trim(input('param.txt_keyword'))) {
  55. $param[] = array('vouchertemplate_title', 'like', '%' . trim(input('param.txt_keyword')) . '%');
  56. }
  57. $select_state = intval(input('param.select_state'));
  58. if ($select_state) {
  59. $param[] = array('vouchertemplate_state', '=', $select_state);
  60. }
  61. if (input('param.txt_startdate')) {
  62. $param[] = array('vouchertemplate_enddate', '>=', strtotime(input('param.txt_startdate')));
  63. }
  64. if (input('param.txt_enddate')) {
  65. $param[] = array('vouchertemplate_startdate', '<=', strtotime(input('param.txt_enddate'))+86399);
  66. }
  67. $vouchertemplate_list = Db::name('vouchertemplate')->where($param)->order('vouchertemplate_id desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  68. View::assign('show_page', $vouchertemplate_list->render());
  69. $vouchertemplate_list = $vouchertemplate_list->items();
  70. foreach ($vouchertemplate_list as $key => $val) {
  71. if (!$val['vouchertemplate_customimg']) {
  72. $vouchertemplate_list[$key]['vouchertemplate_customimg'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  73. } else {
  74. $vouchertemplate_list[$key]['vouchertemplate_customimg'] = ds_get_pic( ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') , $val['vouchertemplate_customimg']);
  75. }
  76. }
  77. $this->setSellerCurMenu('Sellervoucher');
  78. $this->setSellerCurItem('templatelist');
  79. View::assign('vouchertemplate_list', $vouchertemplate_list);
  80. return View::fetch($this->template_dir . 'index');
  81. }
  82. /**
  83. * 购买套餐
  84. */
  85. public function quotaadd() {
  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. $voucher_model = model('voucher');
  136. $isPlatformStore = check_platform_store();
  137. View::assign('isPlatformStore', $isPlatformStore);
  138. $quotainfo = array();
  139. if (!$isPlatformStore) {
  140. //查询当前可以使用的套餐
  141. $quotainfo = $voucher_model->getVoucherquotaCurrent(session('store_id'));
  142. if (empty($quotainfo)) {
  143. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  144. $quotainfo = array('voucherquota_id' => 0, 'voucherquota_starttime' => TIMESTAMP, 'voucherquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  145. } else {
  146. $this->error(lang('voucher_template_quotanull'), 'Sellervoucher/quotaadd');
  147. }
  148. }
  149. //查询该套餐下代金券模板列表
  150. $count = Db::name('vouchertemplate')->where(array('vouchertemplate_quotaid' => $quotainfo['voucherquota_id'], 'vouchertemplate_state' => $this->templatestate_arr['usable'][0]))->count();
  151. if ($count >= config('ds_config.voucher_storetimes_limit')) {
  152. $message = sprintf(lang('voucher_template_noresidual'), config('ds_config.voucher_storetimes_limit'));
  153. $this->error($message, 'Sellervoucher/templatelist');
  154. }
  155. }
  156. //查询面额列表
  157. $pricelist = Db::name('voucherprice')->order('voucherprice asc')->select()->toArray();
  158. if (empty($pricelist)) {
  159. $this->error(lang('voucher_template_pricelisterror'), 'Sellervoucher/templatelist');
  160. }
  161. if (request()->isPost()) {
  162. //验证提交的内容面额不能大于限额
  163. $data = [
  164. 'txt_template_title' => input('post.txt_template_title'),
  165. 'txt_template_total' => input('post.txt_template_total'),
  166. 'select_template_price' => input('post.select_template_price'),
  167. 'txt_template_limit' => input('post.txt_template_limit'),
  168. 'txt_template_describe' => input('post.txt_template_describe'),
  169. ];
  170. $sellervoucher_validate = ds_validate('sellervoucher');
  171. if (!$sellervoucher_validate->scene('templateadd')->check($data)) {
  172. $this->error($sellervoucher_validate->getError());
  173. }
  174. //金额验证
  175. $price = intval(input('post.select_template_price')) > 0 ? intval(input('post.select_template_price')) : 0;
  176. foreach ($pricelist as $k => $v) {
  177. if ($v['voucherprice'] == $price) {
  178. $chooseprice = $v; //取得当前选择的面额记录
  179. }
  180. }
  181. if (empty($chooseprice)) {
  182. $this->error(lang('voucher_template_pricelisterror'));
  183. }
  184. $limit = intval(input('post.txt_template_limit')) > 0 ? intval(input('post.txt_template_limit')) : 0;
  185. if ($price >= $limit) {
  186. $this->error(lang('voucher_template_price_error'));
  187. }
  188. $insert_arr = array();
  189. $insert_arr['vouchertemplate_title'] = trim(input('post.txt_template_title'));
  190. $insert_arr['vouchertemplate_desc'] = trim(input('post.txt_template_describe'));
  191. $insert_arr['vouchertemplate_startdate'] = TIMESTAMP; //默认代金券模板的有效期为当前时间
  192. if (input('post.txt_template_enddate')) {
  193. $enddate = strtotime(input('post.txt_template_enddate'));
  194. if (!$isPlatformStore && $enddate > $quotainfo['voucherquota_endtime']) {
  195. $enddate = $quotainfo['voucherquota_endtime'];
  196. }
  197. $insert_arr['vouchertemplate_enddate'] = $enddate;
  198. } else {//如果没有添加有效期则默认为套餐的结束时间
  199. if ($isPlatformStore)
  200. $insert_arr['vouchertemplate_enddate'] = TIMESTAMP + 2592000; // 自营店 默认30天到期
  201. else
  202. $insert_arr['vouchertemplate_enddate'] = $quotainfo['voucherquota_endtime'];
  203. }
  204. $insert_arr['vouchertemplate_price'] = $price;
  205. $insert_arr['vouchertemplate_limit'] = $limit;
  206. $insert_arr['vouchertemplate_store_id'] = session('store_id');
  207. $insert_arr['vouchertemplate_storename'] = session('store_name');
  208. $insert_arr['vouchertemplate_sc_id'] = intval(input('post.storeclass_id'));
  209. $insert_arr['vouchertemplate_creator_id'] = session('member_id');
  210. $insert_arr['vouchertemplate_state'] = $this->templatestate_arr['usable'][0];
  211. $insert_arr['vouchertemplate_total'] = intval(input('post.txt_template_total')) > 0 ? intval(input('post.txt_template_total')) : 0;
  212. $insert_arr['vouchertemplate_giveout'] = 0;
  213. $insert_arr['vouchertemplate_used'] = 0;
  214. $insert_arr['vouchertemplate_gettype'] = 1;
  215. $insert_arr['vouchertemplate_adddate'] = TIMESTAMP;
  216. $insert_arr['vouchertemplate_quotaid'] = isset($quotainfo['voucherquota_id']) ? $quotainfo['voucherquota_id'] : 0;
  217. $insert_arr['vouchertemplate_points'] = $chooseprice['voucherprice_defaultpoints'];
  218. $insert_arr['vouchertemplate_eachlimit'] = intval(input('post.eachlimit')) > 0 ? intval(input('post.eachlimit')) : 0;
  219. $insert_arr['vouchertemplate_if_private'] = intval(input('post.vouchertemplate_if_private'));
  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. 'vouchertemplate_if_private' => 0,
  258. );
  259. View::assign('t_info', $t_info);
  260. $this->setSellerCurMenu('Sellervoucher');
  261. $this->setSellerCurItem('templateadd');
  262. return View::fetch($this->template_dir . 'templateadd');
  263. }
  264. }
  265. /*
  266. * 代金券模版编辑
  267. */
  268. public function templateedit() {
  269. $t_id = intval(input('param.tid'));
  270. if ($t_id <= 0) {
  271. $this->error(lang('param_error'), (string) url('Sellervoucher/templatelist'));
  272. }
  273. //查询模板信息
  274. $param = array();
  275. $param[] = array('vouchertemplate_id', '=', $t_id);
  276. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  277. $param[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  278. $param[] = array('vouchertemplate_giveout', '<=', '0');
  279. $param[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
  280. $t_info = Db::name('vouchertemplate')->where($param)->find();
  281. if (empty($t_info)) {
  282. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  283. }
  284. $isPlatformStore = check_platform_store();
  285. View::assign('isPlatformStore', $isPlatformStore);
  286. $quotainfo = array();
  287. if (!$isPlatformStore) {
  288. //查询套餐信息
  289. $quotainfo = Db::name('voucherquota')->where(array(
  290. 'voucherquota_id' => $t_info['vouchertemplate_quotaid'],
  291. 'voucherquota_storeid' => session('store_id')
  292. ))->find();
  293. if (empty($quotainfo)) {
  294. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  295. $quotainfo = array('voucherquota_id' => 0, 'voucherquota_starttime' => TIMESTAMP, 'voucherquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  296. } else {
  297. $this->error(lang('voucher_template_quotanull'), 'Sellervoucher/quotaadd');
  298. }
  299. }
  300. }
  301. //查询面额列表
  302. $pricelist = Db::name('voucherprice')->order('voucherprice asc')->select()->toArray();
  303. if (empty($pricelist)) {
  304. $this->error(lang('voucher_template_pricelisterror'), 'Sellervoucher/templatelist');
  305. }
  306. if (request()->isPost()) {
  307. //验证提交的内容面额不能大于限额
  308. $data = [
  309. 'txt_template_title' => input('post.txt_template_title'),
  310. 'txt_template_total' => input('post.txt_template_total'),
  311. 'select_template_price' => input('post.select_template_price'),
  312. 'txt_template_limit' => input('post.txt_template_limit'),
  313. 'txt_template_describe' => input('post.txt_template_describe'),
  314. ];
  315. $sellervoucher_validate = ds_validate('sellervoucher');
  316. if (!$sellervoucher_validate->scene('templateedit')->check($data)) {
  317. $this->error($sellervoucher_validate->getError());
  318. }
  319. //金额验证
  320. $price = intval(input('post.select_template_price')) > 0 ? intval(input('post.select_template_price')) : 0;
  321. foreach ($pricelist as $k => $v) {
  322. if ($v['voucherprice'] == $price) {
  323. $chooseprice = $v; //取得当前选择的面额记录
  324. }
  325. }
  326. if (empty($chooseprice)) {
  327. $this->error(lang('voucher_template_pricelisterror'));
  328. }
  329. $limit = intval(input('post.txt_template_limit')) > 0 ? intval(input('post.txt_template_limit')) : 0;
  330. if ($price >= $limit) {
  331. $this->error(lang('voucher_template_price_error'));
  332. }
  333. $update_arr = array();
  334. $update_arr['vouchertemplate_title'] = trim(input('post.txt_template_title'));
  335. $update_arr['vouchertemplate_desc'] = trim(input('post.txt_template_describe'));
  336. if (input('post.txt_template_enddate')) {
  337. $enddate = strtotime(input('post.txt_template_enddate'));
  338. if (!$isPlatformStore && $enddate > $quotainfo['voucherquota_endtime']) {
  339. $enddate = $quotainfo['voucherquota_endtime'];
  340. }
  341. $update_arr['vouchertemplate_enddate'] = $enddate;
  342. } else {//如果没有添加有效期则默认为套餐的结束时间
  343. if ($isPlatformStore)
  344. $update_arr['vouchertemplate_enddate'] = TIMESTAMP + 2592000; // 自营店 默认30天到期
  345. else
  346. $update_arr['vouchertemplate_enddate'] = $quotainfo['voucherquota_endtime'];
  347. }
  348. $update_arr['vouchertemplate_price'] = $price;
  349. $update_arr['vouchertemplate_limit'] = $limit;
  350. $update_arr['vouchertemplate_sc_id'] = intval(input('post.storeclass_id'));
  351. $update_arr['vouchertemplate_state'] = intval(input('post.tstate')) == $this->templatestate_arr['usable'][0] ? $this->templatestate_arr['usable'][0] : $this->templatestate_arr['disabled'][0];
  352. $update_arr['vouchertemplate_total'] = intval(input('post.txt_template_total')) > 0 ? intval(input('post.txt_template_total')) : 0;
  353. $update_arr['vouchertemplate_points'] = $chooseprice['voucherprice_defaultpoints'];
  354. $update_arr['vouchertemplate_eachlimit'] = intval(input('post.eachlimit')) > 0 ? intval(input('post.eachlimit')) : 0;
  355. $update_arr['vouchertemplate_if_private'] = intval(input('post.vouchertemplate_if_private'));
  356. //自定义图片
  357. if (!empty($_FILES['customimg']['name'])) {
  358. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  359. $res=ds_upload_pic(ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id'),'customimg', $file_name);
  360. if($res['code']){
  361. $file_name=$res['data']['file_name'];
  362. //删除原图
  363. if (!empty($t_info['vouchertemplate_customimg'])) {//如果模板存在,则删除原模板图片
  364. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  365. }
  366. $update_arr['vouchertemplate_customimg'] = $file_name;
  367. }else{
  368. $this->error($res['msg']);
  369. }
  370. }
  371. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->update($update_arr);
  372. if ($rs) {
  373. $this->success(lang('ds_common_op_succ'), (string) url('Sellervoucher/templatelist'));
  374. } else {
  375. $this->error(lang('ds_common_op_fail'), (string) url('Sellervoucher/templatelist'));
  376. }
  377. } else {
  378. if (!$t_info['vouchertemplate_customimg']) {
  379. $t_info['vouchertemplate_customimg'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  380. } else {
  381. $t_info['vouchertemplate_customimg'] = ds_get_pic( ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') , $t_info['vouchertemplate_customimg']);
  382. }
  383. View::assign('type', 'edit');
  384. View::assign('t_info', $t_info);
  385. //店铺分类
  386. $store_class = rkcache('storeclass', true);
  387. View::assign('store_class', $store_class);
  388. //查询店铺详情
  389. $store_info = model('store')->getStoreInfoByID(session('store_id'));
  390. View::assign('store_info', $store_info);
  391. View::assign('quotainfo', $quotainfo);
  392. View::assign('pricelist', $pricelist);
  393. $this->setSellerCurMenu('Sellervoucher');
  394. $this->setSellerCurItem('templateedit');
  395. return View::fetch($this->template_dir . 'templateadd');
  396. }
  397. }
  398. /**
  399. * 删除代金券
  400. */
  401. public function templatedel() {
  402. $t_id = intval(input('param.tid'));
  403. if ($t_id <= 0) {
  404. ds_json_encode(10001, lang('param_error'));
  405. }
  406. //查询模板信息
  407. $param = array();
  408. $param[] = array('vouchertemplate_id', '=', $t_id);
  409. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  410. $param[] = array('vouchertemplate_giveout', '<=', '0'); //会员没领取过代金券才可删除
  411. $t_info = Db::name('vouchertemplate')->where($param)->find();
  412. if (empty($t_info)) {
  413. ds_json_encode(10001, lang('param_error'));
  414. }
  415. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->delete();
  416. if ($rs) {
  417. //删除自定义的图片
  418. if (trim($t_info['vouchertemplate_customimg'])) {
  419. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  420. }
  421. ds_json_encode(10000, lang('ds_common_del_succ'));
  422. } else {
  423. ds_json_encode(10001, lang('ds_common_del_fail'));
  424. }
  425. }
  426. /**
  427. * 查看代金券详细
  428. */
  429. public function templateinfo() {
  430. $t_id = intval(input('param.tid'));
  431. if ($t_id <= 0) {
  432. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  433. }
  434. //查询模板信息
  435. $param = array();
  436. $param['vouchertemplate_id'] = $t_id;
  437. $param['vouchertemplate_store_id'] = session('store_id');
  438. $t_info = Db::name('vouchertemplate')->where($param)->find();
  439. View::assign('t_info', $t_info);
  440. $this->setSellerCurMenu('Sellervoucher');
  441. $this->setSellerCurItem('templateinfo');
  442. return View::fetch($this->template_dir . 'template_info');
  443. }
  444. /**
  445. * 查看私密代金券领取地址
  446. */
  447. public function view() {
  448. $t_id = intval(input('param.tid'));
  449. if ($t_id <= 0) {
  450. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  451. }
  452. if(config('ds_config.h5_store_site_url')){
  453. $url = config('ds_config.h5_site_url').'/pages/member/voucher/VoucherPrivate?id='.$t_id;
  454. }else{
  455. $url = config('ds_config.h5_site_url').'/member/voucher_private?id='.$t_id;
  456. }
  457. View::assign('url', $url);
  458. return View::fetch($this->template_dir . 'view');
  459. }
  460. /*
  461. * 把代金券模版设为失效
  462. */
  463. private function check_voucher_template_expire($voucher_template_id = '') {
  464. $where_array = array();
  465. if (empty($voucher_template_id)) {
  466. $where_array[] = array('vouchertemplate_enddate', '<', TIMESTAMP);
  467. } else {
  468. $where_array[] = array('vouchertemplate_id', '=', $voucher_template_id);
  469. }
  470. $where_array[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  471. Db::name('vouchertemplate')->where($where_array)->update(array('vouchertemplate_state' => $this->templatestate_arr['disabled'][0]));
  472. }
  473. /**
  474. * 用户中心右边,小导航
  475. *
  476. * @param string $menu_type 导航类型
  477. * @param string $menu_key 当前导航的menu_key
  478. * @return
  479. */
  480. protected function getSellerItemList() {
  481. $menu_array = array();
  482. switch (request()->action()) {
  483. case 'templatelist':
  484. $menu_array = array(
  485. 1 => array(
  486. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  487. 'url' => (string) url('Sellervoucher/templatelist')
  488. ),
  489. );
  490. break;
  491. case 'quotaadd':
  492. $menu_array = array(
  493. array(
  494. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  495. 'url' => (string) url('Sellervoucher/templatelist')
  496. ), array(
  497. 'name' => 'quotaadd', 'text' => lang('voucher_applyadd'), 'url' => (string) url('Sellervoucher/quotaadd')
  498. )
  499. );
  500. break;
  501. case 'templateadd':
  502. $menu_array = array(
  503. 1 => array(
  504. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  505. 'url' => (string) url('Sellervoucher/templatelist')
  506. ), 2 => array(
  507. 'name' => 'templateadd', 'text' => lang('voucher_templateadd'),
  508. 'url' => (string) url('Sellervoucher/templateadd')
  509. ),
  510. );
  511. break;
  512. case 'templateedit':
  513. $menu_array = array(
  514. 1 => array(
  515. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  516. 'url' => (string) url('Sellervoucher/templatelist')
  517. ), 2 => array(
  518. 'name' => 'templateedit', 'text' => lang('voucher_templateedit'), 'url' => ''
  519. ),
  520. );
  521. break;
  522. case 'templateinfo':
  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' => 'templateinfo', 'text' => lang('voucher_templateinfo'), 'url' => ''
  529. ),
  530. );
  531. break;
  532. }
  533. return $menu_array;
  534. }
  535. }