<?php
namespace Home\Controller;
use OT\DataDictionary;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class IndexController extends HomeController {
//系统首页
public function index(){
if(IS_POST){
$ticketno = I('post.ticketno');
$ticketpw = I('post.ticketpw');
$checkcode = I('post.checkcode');
/* 检测验证码 */
if(!check_verify($checkcode)){
$this->error('验证码输入错误!');
}
$where = array(
'voucher_no' => $ticketno,
'voucher_pwd' => $ticketpw
);
$data = array();
$info = M('Voucher')->where($where)->find();
if($info['expiry_time'] < time()){
$this->error('无效的卡号或该卡暂没开通!');
}
if($info && $info['status'] == 0){
$voucher_cate = M('Voucher_category')->where(array('id'=>$info['voucher_cate_id']))->find();
if($voucher_cate && !$voucher_cate['status']){
$this->error('该系列礼品卡已停用!');
}
// $data['order_no'] = create_no();
// $data['voucher_no'] = $ticketno;
// $data['create_time'] = time();
// $where = array(
// 'voucher_no' => $ticketno,
// 'voucher_pwd' => $ticketpw
// );
// M('Voucher')->where($where)->save(array('status'=>1));
// $id = M('order')->add($data);
$this->success('验证成功,请填写邮寄信息!',U('mail_info',array('a'=>$ticketno,'b'=>$ticketpw)));
// if($id){
// $this->success('验证成功,请填写邮寄信息!',U('mail_info',array('a'=>$ticketno,'b'=>$ticketpw,'c'=>$id)));
// }else{
// $this->error('验证失败,请稍后再试!');
// }
}else{
$this->error('无效的提货号或该号码已被使用!');
}
}else{
$this->display();
}
}
/**
* [auth_query 真伪查询]
* @return [type] [description]
*/
public function auth_query(){
if(IS_POST){
$voucher_no = I('post.code');
$verify = I('post.checkcode');
/* 检测验证码 */
if(!check_verify($verify)){
$this->error('验证码输入错误!',U('auth_query'));
}
$where = array(
'voucher_no' => $voucher_no
);
$info = M('Voucher')->where($where)->find();
if($info && $info['status'] == 0){
$this->success('该提货号码真实有效!快去提取吧!','/viptihuo/',5);
}else{
$this->error('无效提货号码!',U('auth_query'));
}
}else{
$this->display();
}
}
/**
* [order 订单查询]
* @return [type] [description]
*/
public function order(){
if(IS_POST){
$voucher_no = I('post.code');
$mobile = I('post.mobile');
$verify = I('post.checkcode');
/* 检测验证码 */
if(!check_verify($verify)){
$this->error('验证码输入错误!',U('order'));
}
$where = array(
'voucher_no' => $voucher_no,
'consignee_mobile' => $mobile
);
$info = M('Order')->where($where)->find();
if($info){
$voucher = M('Voucher')->where(array('voucher_no'=>$voucher_no))->find();
if(empty($info['consignee_name']) || empty($info['consignee_province']) || empty($info['consignee_city']) || empty($info['consignee_county']) || empty($info['consignee_address']) || empty($info['consignee_mobile'])){
$this->assign('isshow',true);
}
$this->assign('voucher',$voucher);
$this->assign('info',$info);
$this->display();
}else{
$this->error('查无此订单的信息,请确认信息是否填写正确!');
}
}else{
$this->display();
}
}
/**
* [mail_info 邮寄信息]
* @Author hongyuan<34788974@qq.com>
* @DateTime 2018-09-15T08:33:28+0800
* @return [type] [description]
*/
public function mail_info(){
if(IS_POST){
$data = array();
$data['consignee_province'] = I('post.consignee_province');
$data['consignee_city'] = I('post.consignee_city');
$data['consignee_county'] = I('post.consignee_county');
$data['consignee_address'] = I('post.consignee_address');
$data['consignee_name'] = I('post.consignee_name');
$data['consignee_mobile'] = I('post.consignee_mobile');
$data['remark'] = I('post.remark');
$data['th_time'] = time();
if(empty($data['consignee_province'])){
$this->error('所属省份不能为空!');
}
if(empty($data['consignee_city'])){
$this->error('所属城市不能为空!');
}
// if(empty($data['consignee_county'])){
// $this->error('所属地区不能为空!');
// }
if(empty($data['consignee_address'])){
$this->error('收货地址不能为空!');
}
if(empty($data['consignee_name'])){
$this->error('后收货人姓名不能为空!');
}
if(empty($data['consignee_mobile'])){
$this->error('收货人手机不能为空!');
}
if(empty($data['th_time'])){
$this->error('提货时间不能为空!');
}
$voucher_no = I('post.a');
$order = M('order');
$data['order_no'] = create_no();
$data['voucher_no'] = $voucher_no;
$data['create_time'] = time();
$data['status'] = 0;
$id = $order->add($data);
if($id){
$map = array(
'voucher_no' => I('post.a'),
'voucher_pwd' => I('post.b')
);
M('Voucher')->where($map)->save(array('status'=>1));
$this->success('提货成功',U('result',array('a'=>$data['order_no']),0));
}else{
$this->error('网络原因,提交失败,请重新提交');
}
$info = $order->where($where)->find();
if($info['status'] == 1) $this->error('该订单已生成并发货,请勿重复操作!',U('index'));
if($info && $info['status'] == 0){
if($order->where($where)->save($data)){
$map = array(
'voucher_no' => I('post.a'),
'voucher_pwd' => I('post.b')
);
M('Voucher')->where($map)->save(array('status'=>1));
$this->success('提货成功',U('result',array('a'=>$info['order_no']),0));
}else{
$this->error('网络原因,提交失败,请重新提交');
}
}else{
$this->error('没有这个订单!');
}
}else{
$a = I('get.a');
$b = I('get.b');
if(empty($a) || empty($b)) $this->error('无效参数,请正确填写提货号码跟密码!',U('index'));
// $where = array(
// 'id' => $c,
// 'voucher_no' => $a
// );
// $order = M('order');
// $info = $order->where($where)->find();
// if(!$info) $this->error('该订单不存在!',U('index'));
// if($info['status'] == 1) $this->error('该订单已发货,请勿重复操作!',U('index'));
$this->display();
}
}
public function result(){
$order_no = I('get.a');
$this->assign('orderno',$order_no);
$this->display();
}
}