Exemplo n.º 1
0
 public function getEmployeesAction()
 {
     list($page, $sidx, $limit, $sord, $start) = getRequestParams();
     $model = M("User");
     $brand_id = get_brand_id();
     $condition = array("brand_id" => $brand_id, "is_brand" => 0);
     $valuesql = "select * from yoga_user a,yoga_user_extension b where a.brand_id={$brand_id} and a.is_brand=0 and a.id=b.id and a.invalid=1 ";
     $countsql = "select count(*) as count from yoga_user a,yoga_user_extension b where a.brand_id={$brand_id} and a.is_brand=0 and a.id=b.id and a.invalid=1 ";
     $filters = I("filters", '', '');
     $filters = json_decode($filters);
     $sql = "";
     if ($filters->groupOp == 'AND') {
         $rules = $filters->rules;
         foreach ($rules as $key => $value) {
             if ($value->field == "club" && $value->data != 0) {
                 $sql .= " and a.club_id " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "work_status" && $value->data != -1) {
                 $sql .= " and b.work_status " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "name_cn") {
                 $sql .= " and b.name_cn  like '%{$value->data}%'";
             }
             if ($value->field == "name_en") {
                 $sql .= " and b.name_en  like '%{$value->data}%'";
             }
             if ($value->field == "role" && $value->data != -1) {
                 $ids = M("AuthGroupAccess")->where("group_id=" . $value->data)->select();
                 $id = array();
                 foreach ($ids as $key => $value) {
                     $id[] = $value['uid'];
                 }
                 $ids = implode(",", $id);
                 $sql .= " and b.id in({$ids})";
             }
         }
     }
     $model = new \Think\Model();
     $countsql = $countsql . " " . $sql;
     $count = $model->query($countsql);
     $count = $count[0]["count"];
     $valuesql = $valuesql . " " . $sql . $tail . " order by a.{$sidx} {$sord} limit {$start},{$limit}";
     $ret = $model->query($valuesql);
     foreach ($ret as $key => $value) {
         $ret[$key]['role'] = D("User")->getRole($value['id']);
     }
     if ($count > 0 && $limit > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     $response = array("page" => $page, "total" => $total_pages, "records" => $count, "rows" => $ret);
     $this->ajaxReturn($response);
 }
Exemplo n.º 2
0
 public function queryAction()
 {
     list($page, $sidx, $limit, $sord, $start) = getRequestParams();
     //query member card
     $valuesql = "select a.* ,b.name,b.phone from yoga_card a,yoga_member_basic b where a.member_id=b.id ";
     $countsql = "select count(*) as count from yoga_card a,yoga_member_basic b where a.member_id=b.id ";
     $filters = I("filters", '', '');
     $filters = json_decode($filters);
     $sql = "";
     if ($filters->groupOp == 'AND') {
         $rules = $filters->rules;
         foreach ($rules as $key => $value) {
             if ($value->field == "card_number") {
                 $sql .= " and a.card_number " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "name") {
                 $sql .= " and b.name " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "phone") {
                 $sql .= " and b.phone " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
         }
     }
     $model = new \Think\Model();
     $countsql = $countsql . " " . $sql;
     $count = $model->query($countsql);
     $count = $count[0]["count"];
     $valuesql = $valuesql . " " . $sql . $tail . " order by {$sidx} {$sord} limit {$start},{$limit}";
     $ret = $model->query($valuesql);
     if ($count > 0 && $limit > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     $response = array("page" => $page, "total" => $total_pages, "records" => $count, "rows" => $ret);
     $this->ajaxReturn($response);
 }
 public function queryNewAction()
 {
     list($page, $sidx, $limit, $sord, $start) = getRequestParams();
     $filters = I("filters", '', '');
     if (empty($filters)) {
         $this->error("Error");
     }
     $brand_id = get_brand_id();
     $club_id = get_club_id();
     $valuesql = " select c.id as cid, a.*,c.start_time,c.end_time , c.free_rest as cfree_rest,c.rest_count as crest_count,c.card_type_extension, b.name as member_name,b.id as memberid ,b.phone from yoga_card a,yoga_member_basic b,yoga_contract c  where c.invalid=1 and  a.brand_id={$brand_id} and a.sale_club={$club_id} and a.member_id=b.id  and a.id=c.card_id";
     $countsql = "select count(*) as count from yoga_card a,yoga_member_basic b,yoga_contract c where c.invalid=1 and  a.brand_id={$brand_id} and a.sale_club={$club_id} and a.member_id=b.id  and a.id=c.card_id";
     if (is_user_brand()) {
         $valuesql = " select c.id  as cid,  a.*,c.start_time,c.end_time , c.card_type_extension,c.free_rest as cfree_rest,c.rest_count as crest_count, b.name as member_name,b.id as memberid ,b.phone from yoga_card a,yoga_member_basic b,yoga_contract c where c.invalid=1 and  a.brand_id={$brand_id}  and a.member_id=b.id  and a.id=c.card_id";
         $countsql = "select count(*) as count from yoga_card a,yoga_member_basic b,yoga_contract c where c.invalid=1 and  a.brand_id={$brand_id}  and a.member_id=b.id  and a.id=c.card_id";
     }
     $filters = json_decode($filters);
     $sql = "";
     if ($filters->groupOp == 'AND') {
         $rules = $filters->rules;
         foreach ($rules as $key => $value) {
             if ($value->field == "card_id") {
                 $sql .= " and a.card_number " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "name") {
                 $sql .= " and b.name " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "phone") {
                 $sql .= " and b.phone " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
         }
     }
     $model = new \Think\Model();
     $countsql = $countsql . " " . $sql;
     $count = $model->query($countsql);
     $count = $count[0]["count"];
     $valuesql = $valuesql . " " . $sql . " order by {$sidx} {$sord} limit {$start},{$limit}";
     $clubModel = M("Club");
     $ret = $model->query($valuesql);
     foreach ($ret as $key => $value) {
         $tempid = $ret[$key]['id'];
         $ret[$key]['id'] = $ret[$key]['cid'];
         $ret[$key]['cid'] = $tempid;
         $ret[$key]["card_type_extension"] = json_decode($ret[$key]["card_type_extension"]);
         $club = $clubModel->find($value['sale_club']);
         $ret[$key]['club_name'] = !empty($club) ? $club['club_name'] : "";
     }
     if ($count > 0 && $limit > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     $response = array("page" => $page, "total" => $total_pages, "records" => $count, "rows" => $ret);
     $this->ajaxReturn($response);
 }
Exemplo n.º 4
0
 public function queryAction()
 {
     list($page, $sidx, $limit, $sord, $start) = getRequestParams();
     $filters = I("filters", '', '');
     $brand_id = get_brand_id();
     $club_id = get_club_id();
     $valuesql = "select b.*,a.name,a.sex,a.phone ,c.card_number ,d.name as card_name,d.type as card_type ,d.price as card_type_price from yoga_contract b left join yoga_member_basic a on b.member_id=a.id left join yoga_card c on b.card_id=c.id left join yoga_card_type d  on b.card_type_id=d.id where b.brand_id= {$brand_id}  ";
     $countsql = "select count(*) as count from yoga_contract b left join yoga_member_basic a on b.member_id=a.id left join yoga_card c on b.card_id=c.id left join yoga_card_type d  on b.card_type_id=d.id where  b.brand_id= {$brand_id}  ";
     $filters = json_decode($filters);
     $sql = "";
     if ($filters->groupOp == 'AND') {
         $rules = $filters->rules;
         foreach ($rules as $key => $value) {
             if ($value->field == "mc_id" && !empty($value->data)) {
                 $sql .= " and b.mc_id " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "sale_club_id" && !empty($value->data)) {
                 $sql .= " and b.sale_club_id " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "start_time" && !empty($value->data)) {
                 $sql .= " and b.create_time  " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "end_time" && !empty($value->data)) {
                 $sql .= " and b.create_time  " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "card_type_id" && !empty($value->data)) {
                 $sql .= " and b.card_type_id " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "contract_number") {
                 $sql .= " and b.contract_number " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "card_number") {
                 $sql .= " and c.card_number " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "name") {
                 $sql .= " and a.name " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
             if ($value->field == "phone") {
                 $sql .= " and a.phone " . getOPerationMysql($value->op) . "  '{$value->data}'";
             }
         }
     }
     // $tail="  and a.id=b.member_id and b.brand_id=$brand_id  and b.contract_type=0 and b.card_id=c.id and b.card_type_id=d.id";
     $tail = "";
     $model = new \Think\Model();
     $countsql = $countsql . " " . $sql . $tail;
     $count = $model->query($countsql);
     $count = $count[0]["count"];
     $valuesql = $valuesql . " " . $sql . $tail . " order by {$sidx} {$sord} limit {$start},{$limit}";
     $ret = $model->query($valuesql);
     foreach ($ret as $key => $value) {
         $mc = M("UserExtension")->find($value['mc_id']);
         $recorder = M("UserExtension")->find($value['record_id']);
         $ret[$key]['mc_name'] = !empty($mc) ? $mc['name_cn'] : "NO MC!";
         $ret[$key]['recorder_name'] = !empty($recorder) ? $recorder['name_cn'] : "品牌帐号";
     }
     if ($count > 0 && $limit > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     $response = array("page" => $page, "total" => $total_pages, "records" => $count, "rows" => $ret);
     $this->ajaxReturn($response);
 }