HexiaoController.php 3.1 KB
<?php
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

class HexiaoController extends AdminBaseController{

  //核销页显示
  public function index(){

    return $this -> fetch();

  }

  //核销数据
  public function hxCancel(){

    $code = input('post.code');
    $ma = Db::name('coupons_user') -> where('code',$code) -> find();
    if($ma){
      $riqi = Db::name('coupons') -> where('id',$ma['cid']) -> find();
      $date =strtotime(date('y-m-d'));
      $begin = strtotime($riqi['startime']);
      $end = strtotime($riqi['endtime']);
      if($date >= $begin && $date <= $end ){

        //生日核销
      /*if ($riqi['type'] == 2) {
         $shegri = Db::name('members_user') -> where('id',$ma['uid']) -> find();
         $nian = mb_substr($shegri['birthday'],0,4);
         $yue = mb_substr($shegri['birthday'],5,2);
         $riaa = mb_substr($shegri['birthday'],8,2);
         $bir = $yue.$riaa;
           if ($bir == date('md')) {
            $update = Db::name('coupons_user') -> where('code',$code) -> update(['state' => 1]);
            return 1;
           }else{
            return 5;
           }

        }else{

        }*/
          $shijian = time();
          $code_zuixin = Db::name('coupons_user') -> where('code',$code) -> find();
          if($code_zuixin['state'] != 1){
              $update = Db::name('coupons_user') -> where('code',$code) -> update(['state' => 1,'time'=>$shijian]);
              if($update){
                  return 1;
              }else{
                  return 4;
              }
          }else{
              return 4;
          }



      }else{
        return 3;
      }
    }else{
      return 2;
    }

  }


  //已核销页
  public function yihexiao(){

    if($this ->request -> isPost()){
        $where = [
            "a.state" => 1
        ];
        if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
            $start_time = strtotime($_POST['start_time']);
            $end_time = strtotime($_POST['end_time']);
            $where['a.time'] = [['>=',$start_time],['<=',$end_time]];
        }
        $data = Db::name('coupons_user') -> alias('a') -> join('members_user b','a.uid=b.id','LEFT') -> where($where) -> order('a.time desc') -> select() -> toArray();
    }else{
        $data = Db::name('coupons_user') -> alias('a') -> join('members_user b','a.uid=b.id','LEFT') -> where('a.state=1') -> order('a.time desc') -> select() -> toArray();
    }

    foreach ($data as $key => $value) {
      $quan = Db::name('coupons') -> where('id',$value['cid']) -> find();
      $data[$key]['title'] = $quan['title'];
    }
    $this -> assign('data',$data);
    return $this -> fetch();

  }

  /**
   * 使用核销码获取身份证号
   */
    public function hexiao_idnum(){

        $code = $_POST['code'];
        $uid = Db::name('coupons_user') -> where('code',$code) -> find();
        $data = Db::name('members_user') -> where('id',$uid['uid']) -> find();
        if($data['id_num']){
            return $data['id_num'];
        }else{
            return false;
        }

    }






}




 ?>