Sellervoucher.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. $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. $t_id = intval(input('param.tid'));
  271. if ($t_id <= 0) {
  272. $this->error(lang('param_error'), (string) url('Sellervoucher/templatelist'));
  273. }
  274. //查询模板信息
  275. $param = array();
  276. $param[] = array('vouchertemplate_id', '=', $t_id);
  277. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  278. $param[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  279. $param[] = array('vouchertemplate_giveout', '<=', '0');
  280. $param[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
  281. $t_info = Db::name('vouchertemplate')->where($param)->find();
  282. if (empty($t_info)) {
  283. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  284. }
  285. $isPlatformStore = check_platform_store();
  286. View::assign('isPlatformStore', $isPlatformStore);
  287. $quotainfo = array();
  288. if (!$isPlatformStore) {
  289. //查询套餐信息
  290. $quotainfo = Db::name('voucherquota')->where(array(
  291. 'voucherquota_id' => $t_info['vouchertemplate_quotaid'],
  292. 'voucherquota_storeid' => session('store_id')
  293. ))->find();
  294. if (empty($quotainfo)) {
  295. if (intval(config('ds_config.promotion_voucher_price')) == 0) {
  296. $quotainfo = array('voucherquota_id' => 0, 'voucherquota_starttime' => TIMESTAMP, 'voucherquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  297. } else {
  298. $this->error(lang('voucher_template_quotanull'), 'Sellervoucher/quotaadd');
  299. }
  300. }
  301. }
  302. //查询面额列表
  303. $pricelist = Db::name('voucherprice')->order('voucherprice asc')->select()->toArray();
  304. if (empty($pricelist)) {
  305. $this->error(lang('voucher_template_pricelisterror'), 'Sellervoucher/templatelist');
  306. }
  307. if (request()->isPost()) {
  308. //验证提交的内容面额不能大于限额
  309. $data = [
  310. 'txt_template_title' => input('post.txt_template_title'),
  311. 'txt_template_total' => input('post.txt_template_total'),
  312. 'select_template_price' => input('post.select_template_price'),
  313. 'txt_template_limit' => input('post.txt_template_limit'),
  314. 'txt_template_describe' => input('post.txt_template_describe'),
  315. ];
  316. $sellervoucher_validate = ds_validate('sellervoucher');
  317. if (!$sellervoucher_validate->scene('templateedit')->check($data)) {
  318. $this->error($sellervoucher_validate->getError());
  319. }
  320. //金额验证
  321. $price = intval(input('post.select_template_price')) > 0 ? intval(input('post.select_template_price')) : 0;
  322. foreach ($pricelist as $k => $v) {
  323. if ($v['voucherprice'] == $price) {
  324. $chooseprice = $v; //取得当前选择的面额记录
  325. }
  326. }
  327. if (empty($chooseprice)) {
  328. $this->error(lang('voucher_template_pricelisterror'));
  329. }
  330. $limit = intval(input('post.txt_template_limit')) > 0 ? intval(input('post.txt_template_limit')) : 0;
  331. if ($price >= $limit) {
  332. $this->error(lang('voucher_template_price_error'));
  333. }
  334. $update_arr = array();
  335. $update_arr['vouchertemplate_title'] = trim(input('post.txt_template_title'));
  336. $update_arr['vouchertemplate_desc'] = trim(input('post.txt_template_describe'));
  337. if (input('post.txt_template_enddate')) {
  338. $enddate = strtotime(input('post.txt_template_enddate'));
  339. if (!$isPlatformStore && $enddate > $quotainfo['voucherquota_endtime']) {
  340. $enddate = $quotainfo['voucherquota_endtime'];
  341. }
  342. $update_arr['vouchertemplate_enddate'] = $enddate;
  343. } else {//如果没有添加有效期则默认为套餐的结束时间
  344. if ($isPlatformStore)
  345. $update_arr['vouchertemplate_enddate'] = TIMESTAMP + 2592000; // 自营店 默认30天到期
  346. else
  347. $update_arr['vouchertemplate_enddate'] = $quotainfo['voucherquota_endtime'];
  348. }
  349. $update_arr['vouchertemplate_price'] = $price;
  350. $update_arr['vouchertemplate_limit'] = $limit;
  351. $update_arr['vouchertemplate_sc_id'] = intval(input('post.storeclass_id'));
  352. $update_arr['vouchertemplate_state'] = intval(input('post.tstate')) == $this->templatestate_arr['usable'][0] ? $this->templatestate_arr['usable'][0] : $this->templatestate_arr['disabled'][0];
  353. $update_arr['vouchertemplate_total'] = intval(input('post.txt_template_total')) > 0 ? intval(input('post.txt_template_total')) : 0;
  354. $update_arr['vouchertemplate_points'] = $chooseprice['voucherprice_defaultpoints'];
  355. $update_arr['vouchertemplate_eachlimit'] = intval(input('post.eachlimit')) > 0 ? intval(input('post.eachlimit')) : 0;
  356. $update_arr['vouchertemplate_if_private'] = intval(input('post.vouchertemplate_if_private'));
  357. //自定义图片
  358. if (!empty($_FILES['customimg']['name'])) {
  359. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  360. $res=ds_upload_pic(ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id'),'customimg', $file_name);
  361. if($res['code']){
  362. $file_name=$res['data']['file_name'];
  363. //删除原图
  364. if (!empty($t_info['vouchertemplate_customimg'])) {//如果模板存在,则删除原模板图片
  365. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  366. }
  367. $update_arr['vouchertemplate_customimg'] = $file_name;
  368. }else{
  369. $this->error($res['msg']);
  370. }
  371. }
  372. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->update($update_arr);
  373. if ($rs) {
  374. $this->success(lang('ds_common_op_succ'), (string) url('Sellervoucher/templatelist'));
  375. } else {
  376. $this->error(lang('ds_common_op_fail'), (string) url('Sellervoucher/templatelist'));
  377. }
  378. } else {
  379. if (!$t_info['vouchertemplate_customimg']) {
  380. $t_info['vouchertemplate_customimg'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  381. } else {
  382. $t_info['vouchertemplate_customimg'] = ds_get_pic( ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') , $t_info['vouchertemplate_customimg']);
  383. }
  384. View::assign('type', 'edit');
  385. View::assign('t_info', $t_info);
  386. //店铺分类
  387. $store_class = rkcache('storeclass', true);
  388. View::assign('store_class', $store_class);
  389. //查询店铺详情
  390. $store_info = model('store')->getStoreInfoByID(session('store_id'));
  391. View::assign('store_info', $store_info);
  392. View::assign('quotainfo', $quotainfo);
  393. View::assign('pricelist', $pricelist);
  394. $this->setSellerCurMenu('Sellervoucher');
  395. $this->setSellerCurItem('templateedit');
  396. return View::fetch($this->template_dir . 'templateadd');
  397. }
  398. }
  399. /**
  400. * 删除代金券
  401. */
  402. public function templatedel() {
  403. $t_id = intval(input('param.tid'));
  404. if ($t_id <= 0) {
  405. ds_json_encode(10001, lang('param_error'));
  406. }
  407. //查询模板信息
  408. $param = array();
  409. $param[] = array('vouchertemplate_id', '=', $t_id);
  410. $param[] = array('vouchertemplate_store_id', '=', session('store_id'));
  411. $param[] = array('vouchertemplate_giveout', '<=', '0'); //会员没领取过代金券才可删除
  412. $t_info = Db::name('vouchertemplate')->where($param)->find();
  413. if (empty($t_info)) {
  414. ds_json_encode(10001, lang('param_error'));
  415. }
  416. $rs = Db::name('vouchertemplate')->where(array('vouchertemplate_id' => $t_info['vouchertemplate_id']))->delete();
  417. if ($rs) {
  418. //删除自定义的图片
  419. if (trim($t_info['vouchertemplate_customimg'])) {
  420. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_VOUCHER . DIRECTORY_SEPARATOR . session('store_id') . DIRECTORY_SEPARATOR . $t_info['vouchertemplate_customimg']);
  421. }
  422. ds_json_encode(10000, lang('ds_common_del_succ'));
  423. } else {
  424. ds_json_encode(10001, lang('ds_common_del_fail'));
  425. }
  426. }
  427. /**
  428. * 查看代金券详细
  429. */
  430. public function templateinfo() {
  431. $t_id = intval(input('param.tid'));
  432. if ($t_id <= 0) {
  433. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  434. }
  435. //查询模板信息
  436. $param = array();
  437. $param['vouchertemplate_id'] = $t_id;
  438. $param['vouchertemplate_store_id'] = session('store_id');
  439. $t_info = Db::name('vouchertemplate')->where($param)->find();
  440. View::assign('t_info', $t_info);
  441. $this->setSellerCurMenu('Sellervoucher');
  442. $this->setSellerCurItem('templateinfo');
  443. return View::fetch($this->template_dir . 'template_info');
  444. }
  445. /**
  446. * 查看私密代金券领取地址
  447. */
  448. public function view() {
  449. $t_id = intval(input('param.tid'));
  450. if ($t_id <= 0) {
  451. $this->error(lang('param_error'), 'Sellervoucher/templatelist');
  452. }
  453. if(config('ds_config.h5_store_site_url')){
  454. $url = config('ds_config.h5_site_url').'/pages/member/voucher/VoucherPrivate?id='.$t_id;
  455. }else{
  456. $url = config('ds_config.h5_site_url').'/member/voucher_private?id='.$t_id;
  457. }
  458. View::assign('url', $url);
  459. return View::fetch($this->template_dir . 'view');
  460. }
  461. /*
  462. * 把代金券模版设为失效
  463. */
  464. private function check_voucher_template_expire($voucher_template_id = '') {
  465. $where_array = array();
  466. if (empty($voucher_template_id)) {
  467. $where_array[] = array('vouchertemplate_enddate', '<', TIMESTAMP);
  468. } else {
  469. $where_array[] = array('vouchertemplate_id', '=', $voucher_template_id);
  470. }
  471. $where_array[] = array('vouchertemplate_state', '=', $this->templatestate_arr['usable'][0]);
  472. Db::name('vouchertemplate')->where($where_array)->update(array('vouchertemplate_state' => $this->templatestate_arr['disabled'][0]));
  473. }
  474. /**
  475. * 用户中心右边,小导航
  476. *
  477. * @param string $menu_type 导航类型
  478. * @param string $menu_key 当前导航的menu_key
  479. * @return
  480. */
  481. protected function getSellerItemList() {
  482. $menu_array = array();
  483. switch (request()->action()) {
  484. case 'templatelist':
  485. $menu_array = array(
  486. 1 => array(
  487. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  488. 'url' => (string) url('Sellervoucher/templatelist')
  489. ),
  490. );
  491. break;
  492. case 'quotaadd':
  493. $menu_array = array(
  494. array(
  495. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  496. 'url' => (string) url('Sellervoucher/templatelist')
  497. ), array(
  498. 'name' => 'quotaadd', 'text' => lang('voucher_applyadd'), 'url' => (string) url('Sellervoucher/quotaadd')
  499. )
  500. );
  501. break;
  502. case 'templateadd':
  503. $menu_array = array(
  504. 1 => array(
  505. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  506. 'url' => (string) url('Sellervoucher/templatelist')
  507. ), 2 => array(
  508. 'name' => 'templateadd', 'text' => lang('voucher_templateadd'),
  509. 'url' => (string) url('Sellervoucher/templateadd')
  510. ),
  511. );
  512. break;
  513. case 'templateedit':
  514. $menu_array = array(
  515. 1 => array(
  516. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  517. 'url' => (string) url('Sellervoucher/templatelist')
  518. ), 2 => array(
  519. 'name' => 'templateedit', 'text' => lang('voucher_templateedit'), 'url' => ''
  520. ),
  521. );
  522. break;
  523. case 'templateinfo':
  524. $menu_array = array(
  525. 1 => array(
  526. 'name' => 'templatelist', 'text' => lang('ds_member_path_store_voucher'),
  527. 'url' => (string) url('Sellervoucher/templatelist')
  528. ), 2 => array(
  529. 'name' => 'templateinfo', 'text' => lang('voucher_templateinfo'), 'url' => ''
  530. ),
  531. );
  532. break;
  533. }
  534. return $menu_array;
  535. }
  536. }