HexiaoController.php 1.7 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();
          $update = Db::name('coupons_user') -> where('code',$code) -> update(['state' => 1,'time'=>$shijian]);

          if($update){
              return 1;
          }else{
              return 4;
          }


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

  }


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

    $data = Db::name('coupons_user') -> alias('a') -> join('members_user b','a.uid=b.id','LEFT') -> where('a.state=1') -> select();
    dump($data);die;
    return $this -> fetch();

  }



}




 ?>