Пример #1
0
 public function testAction()
 {
     $data = array("member_id" => 99930601, "level" => 4, "score" => 100);
     M("YaaMember")->data($data)->add();
     $service = \Service\CService::factory("Image");
     $service->updateCer(99930601);
 }
Пример #2
0
 public function changePasswordAction($original_password, $new_password, $confirm_password)
 {
     $id = is_user_login();
     $userService = \Service\CService::factory("User");
     $ret = $userService->changePassword($id, $original_password, $new_password, $confirm_password);
     if ($ret) {
         cookie("sid", null);
         $this->success("密码修改成功,请重新登陆!", 'Home/Index/index');
     } else {
         $this->error($userService->getError());
     }
 }
Пример #3
0
 public function buyAction()
 {
     $member_id = I("member_id");
     $member = M("MemberBasic")->find(I("member_id"));
     if (empty($member)) {
         $this->error("member does not exist");
     }
     $use_recharge = I("use_recharge");
     $rules = array(array('pos', 'number', '请输入正确的pos金额!', 1), array('cash', 'number', '请输入正确的现金金额!', 1), array('check', 'number', '请输入正确的支票金额!', 1), array('network', 'number', '请输入正确的支票金额!', 1), array('netbank', 'number', '请输入正确的支票金额!', 1));
     $recharge = 0;
     if ($use_recharge == 1) {
         $recharge = $member['recharge'] > I("should_pay") ? I("should_pay") : $member['recharge'];
     }
     if ($use_recharge == 1 && $recharge != 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] - $recharge);
         $data = array("member_id" => $member_id, "value" => "-{$recharge}", "record_id" => is_user_login(), "description" => "购定金消费¥{$recharge},余额¥" . ($member['recharge'] - $recharge));
         $recharge_id = M("RechargeHistory")->data($data)->add();
     }
     $service = \Service\CService::factory("Financial");
     $mc_id = I("type") == 8 ? $member['pt_id'] : $member['mc_id'];
     $bill_id = $service->addBillProject(I("type"), 0, 0, $member_id, I("should_pay"), 0, get_brand_id(), is_user_login(), get_club_id(), $mc_id, I("description"));
     if (!$bill_id) {
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] + $recharge);
         if (isset($recharge_id)) {
             M("RechargeHistory")->delete($recharge_id);
         }
         $this->error($service->getError());
     }
     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), I('description'), I("cash"), I("pos"), I("check"), I("check_num"), get_club_id(), $recharge, I("network"), I("netbank"));
     if (!$ret) {
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] + $recharge);
         if (isset($recharge_id)) {
             M("RechargeHistory")->delete($recharge_id);
         }
         M("BillProject")->delete($bill_id);
         $this->error($service->getError());
     }
     if (I("type") == 8) {
         M("MemberBasic")->where(array("id" => $member_id))->setInc("pt_book_price", I("should_pay"));
     }
     if (I("type") == 9) {
         M("MemberBasic")->where(array("id" => $member_id))->setInc("contract_book_price", I("should_pay"));
     }
     // if(!empty($reason))
     // {
     // 	  $contract = M("PtContract")->find($contract_id);
     // 	  $data=array("extension"=>json_encode($contract),"reason"=>$reason,"record_id"=>is_user_login(),"club_id"=>get_club_id(),"brand_id"=>get_brand_id(),"type"=>1,"status"=>0);
     // 	  M("Review")->data($data)->add();
     // }
     $this->success("购买成功!", U("Cashier/Book/printreceipts/id/{$ret}"));
 }
 public function destroycardAction($id)
 {
     $model = M("Card");
     $card = M("Card")->find($id);
     if (empty($card)) {
         $this->error("card does not exist!");
     }
     if ($card['status'] == 5) {
         $this->error("非正常状态不能退卡!");
     }
     $member_id = $card['member_id'];
     $cards = D("Card")->getAllCards($member_id);
     if (count($cards) == 1 && $card['status'] != 4) {
         $this->error("此会员只有一张会员卡,不能单独退卡,请先进行退会操作!");
     }
     foreach ($cards as $key => $value) {
         if ($value['id'] != $id) {
             $new_id = $value['id'];
             break;
         }
     }
     $contracts = D("Contract")->getAllContract($id);
     foreach ($contracts as $key => $value) {
         D("Contract")->where("id=" . $value['id'])->setField(array("card_id" => $new_id));
     }
     $service = \Service\CService::factory("Financial");
     $bill_id = $service->addBillProject(10, 0, $id, $member_id, I("should_pay"), 0, get_brand_id(), is_user_login(), get_club_id(), 0, '');
     if (!$bill_id) {
         $this->error($service->getError());
     }
     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), '', I("should_pay"), 0, 0, 0, get_club_id(), 0);
     if (!$ret) {
         M("BillProject")->delete($bill_id);
         $this->error($service->getError());
     }
     $card['status'] = 5;
     // 销卡
     M("CardDel")->data($card)->add();
     M("Card")->where(array("id" => $id))->delete();
     // M("Card")->where(array("id"=>$id))->setField(array("status"=>5,"card_number"=>"-".$card['card_number']));
     $this->success("退卡成功!", U("Reception/Cardmanage/printreceipts/id/{$ret}"));
 }
Пример #5
0
 public function joinAction($member_id, $type, $card_type_id, $active_type, $present_day, $present_num, $start_time, $end_time, $price, $cash, $pos, $check, $check_num, $description, $card_number, $network, $netbank, $join_mc_id)
 {
     $model = D("Contract");
     if (!$model->create()) {
         $this->error($model->getError());
     }
     $member = M("MemberBasic")->find($member_id);
     if (empty($member)) {
         $this->error("此会员不存在!");
     }
     $cardModel = D("Card");
     $cardTypeModel = M("CardType");
     $cardType = $cardTypeModel->find($card_type_id);
     if (empty($cardType)) {
         $this->error("卡种不存在!");
     }
     $u = M("UserExtension")->find(is_user_login());
     $can_grant = $u['can_grant'];
     if ($cardType['min_price'] > I("price") && !$can_grant) {
         $grant_user_name = I("grant_user_name");
         $grant_user_password = I("grant_user_password");
         if (!empty($grant_user_name) && !empty($grant_user_password)) {
             $map = array('username' => $grant_user_name);
             $user = M("User")->where($map)->find();
             if (is_array($user)) {
                 /* 验证用户密码 */
                 if (ucenter_md5(I("grant_user_password"), C("MD5_SECRET_KEY")) === $user['password']) {
                     $extension = M("UserExtension")->find($user['id']);
                     if ($extension['work_status'] == 1) {
                         $this->error('授权用户无效!');
                     } else {
                     }
                 } else {
                     $this->error("授权无效");
                 }
             } else {
                 $this->error("授权无效");
             }
         } else {
             $this->error("收银过低");
         }
     }
     if (!empty($card_number) && $cardModel->isExist($card_number, get_brand_id())) {
         $this->error("卡号已存在!");
     }
     if (empty($card_number)) {
         //查看是否已经有卡了
         $cd = M("Card")->where(array("member_id" => $member_id))->find();
         if (!empty($cd)) {
             $card_number = $cd['card_number'];
             $card_id = $cd['id'];
         } else {
             $card_number = date("YmdHis") . rand(0, 10000);
             $card = array("free_rest" => I("free_rest"), "sale_club" => get_club_id(), "is_active" => I("active_type") != 2, "brand_id" => get_brand_id(), "card_number" => $card_number, "member_id" => $member_id);
             $card['update_time'] = getDbTime();
             $card_id = $cardModel->data($card)->add();
             if (get_club_id() == 1023) {
                 $max_card = M("Card")->where(array("sale_club" => get_club_id(), "is_auto_create" => 1))->order("card_number desc")->find();
                 if (empty($max_card)) {
                     $card_number = "1000001";
                 } else {
                     $card_number = $max_card['card_number'] + 1;
                 }
                 $card_number = preg_replace("/4/", "5", $card_number);
                 while (true) {
                     if ($cardModel->isExist($card_number, get_brand_id())) {
                         $card_number += 1;
                         $card_number = preg_replace("/4/", "5", $card_number);
                     } else {
                         break;
                     }
                 }
             } else {
                 $max_card = M("Card")->where(array("sale_club" => get_club_id(), "is_auto_create" => 1))->order("card_number desc")->find();
                 if (empty($max_card)) {
                     $card_number = get_club_id() . "000001";
                 } else {
                     $card_number = $max_card['card_number'] + 1;
                 }
                 $card_number = preg_replace("/4/", "5", $card_number);
                 while (true) {
                     if ($cardModel->isExist($card_number, get_brand_id())) {
                         $card_number += 1;
                         $card_number = preg_replace("/4/", "5", $card_number);
                     } else {
                         break;
                     }
                 }
                 //      	 $card_number=get_club_id().'0'. $card_id;
                 //      	 $card_number = pcard_idreg_replace("/4/", "5", $card_number);
                 // while(true)
                 // {
                 //         if($cardModel->isExist($card_number,get_brand_id()))
                 //         {
                 //                 $card_number.=rand(0,100);
                 //                 $card_number = preg_replace("/4/", "5", $card_number);
                 //         }
                 //         else
                 //         {
                 //                 break;
                 //         }
                 // }
             }
             $cardModel->where("id={$card_id}")->setField(array("card_number" => $card_number, "is_auto_create" => "1"));
         }
     } else {
         $card = array("free_rest" => I("free_rest"), "sale_club" => get_club_id(), "is_active" => I("active_type") != 2, "brand_id" => get_brand_id(), "card_number" => $card_number, "member_id" => $member_id);
         $card['update_time'] = getDbTime();
         $card_id = $cardModel->data($card)->add();
     }
     // $valid_time = $cardType['valid_time'];
     // if($cardType['type']==2)
     // {
     // 	$card["total_num"]=$cardType['valid_number']+$present_value;
     // 	$card["end_time"]=date('Y-m-d H:i:s',strtotime("+$valid_time month",strtotime($start_time)));
     // }
     // else
     // {
     // 	$card["end_time"]=date('Y-m-d H:i:s',strtotime("+$valid_time month",strtotime($start_time)+$present_value*24*60*60));
     // }
     //$cardModel->where("id=$card_id")->setField("card_number",$card_number);
     // if(empty($card_number))
     // {
     // 	$card_number=$card_id;
     // 	$cardModel->where(array("id"=>$card_id))->setField("card_number",$card_id);
     // }
     if (!$card_id) {
         $this->error("开卡失败,请稍后再试!");
     }
     $model->total_num = $cardType['valid_number'] + I("present_num");
     $model->sale_club_id = get_club_id();
     $model->card_id = $card_id;
     $payed = $cash + $check + $pos + $network + $netbank;
     $book_price = 0;
     if ($member['contract_book_price'] != 0) {
         $book_price = $price - $payed > $member['contract_book_price'] ? $member['contract_book_price'] : $price - $payed;
         $payed += $book_price;
     }
     $model->payed = $payed;
     $contract_number = date("YmdHis") . rand(0, 10000);
     $r_contract_number = I("contract_number");
     if (!empty($r_contract_number)) {
         $contract_number = I("contract_number");
     }
     $model->contract_number = $contract_number;
     $model->free_rest = I("free_rest");
     $model->free_trans = I("free_trans") == 1 || I("free_trans") == "true" ? 1 : 0;
     $model->mc_id = $join_mc_id;
     $model->card_type_extension = json_encode($cardType);
     if (get_brand_id() == 52 || get_brand_id() == 50) {
         $model->is_review = 1;
     }
     if (I('active_type') == 2) {
         unset($model->start_time);
         unset($model->end_time);
     }
     $contract_id = $model->add();
     if (!$contract_id) {
         $cardModel->delete($card_id);
         $this->error("Error");
     }
     if ($member['is_member'] == 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setField(array("mc_id" => $join_mc_id, "type" => 1, "maybuy" => 0, "hopeprice" => 0, "is_member" => 1, "join_time" => getDbTime()));
     } else {
         M("MemberBasic")->where(array("id" => $member_id))->setField(array("mc_id" => $join_mc_id, "type" => 1, "maybuy" => 0, "hopeprice" => 0));
     }
     $service = \Service\CService::factory("Financial");
     $bill_id = $service->addBillProject(0, 0, $contract_id, $member_id, $price, 0, get_brand_id(), is_user_login(), get_club_id(), $join_mc_id, $description);
     if (!$bill_id) {
         $cardModel->delete($card_id);
         $model->delete($contract_id);
         $this->error($service->getError());
     }
     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), $description, $cash, $pos, $check, $check_num, get_club_id(), 0, I("network"), I("netbank"));
     if (!$ret) {
         $cardModel->delete($card_id);
         $model->delete($contract_id);
         M("BillProject")->delete($bill_id);
         $this->error($service->getError());
     }
     if ($book_price != 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setDec("contract_book_price", $book_price);
         $bill_project = M("BillProject")->where(array("member_id" => $member_id, "type" => 9, "object_id" => 0))->select();
         $i = $book_price;
         foreach ($bill_project as $key => $value) {
             $i -= $value['paid'];
             M("BillProject")->where("id=" . $value['id'])->setField(array("object_id" => $contract_id));
             if ($i <= 0) {
                 break;
             }
         }
         M("BillProject")->where("id={$bill_id}")->setInc("paid", $book_price);
     }
     //cash history
     // $cashModel = M("CashHistory");
     // $cashModel->data(array("cash"=>I("cash"),"check"=>I("check"),"pos"=> I("pos"),"object_id"=>$contract_id,"price"=>I("should_pay"),"record_id"=>is_user_login(),"brand_id"=>get_brand_id()))->add();
     //contract history
     M("ContractHistory")->data(array("contract_id" => $contract_id, "extension" => json_encode(I("post."))))->add();
     //review
     $reason = "新增合同";
     if ($cardType['max_present_num'] < I("present_num")) {
         $reason .= ";新办卡赠送次数过多";
     }
     if ($cardType['max_present_day'] < I("present_day")) {
         $reason .= ";新办卡赠送天数过多";
     }
     if ($cardType['min_price'] > I("price")) {
         $reason .= ";新办卡收银过低";
     }
     if (!empty($reason)) {
         $contract = M("Contract")->find($contract_id);
         $data = array("extension" => json_encode($contract), "reason" => $reason, "record_id" => is_user_login(), "club_id" => get_club_id(), "brand_id" => get_brand_id(), "type" => 0, "status" => 0);
         M("Review")->data($data)->add();
     }
     $this->ajaxReturn(array("status" => 1, "card_id" => $card_number));
 }
Пример #6
0
 public function rechargeNewAction($member_id, $cash, $pos, $check, $check_num, $network, $netbank, $discount)
 {
     $memberModel = M("MemberBasic");
     $member = $memberModel->find($member_id);
     if (empty($member)) {
         $this->error("User is not exist!");
     }
     $model = D("RechargeHistory");
     if (!$model->create()) {
         $this->error($model->getError());
     }
     $model->record_id = is_user_login();
     $model->member_id = $member_id;
     $value = I("cash") + I("check") + I("pos") + I("network") + I("netbank");
     $recharge = $member['recharge'] + $value;
     $model->value = $value;
     $model->discount = $discount;
     $model->value_real = $value;
     $model->description = "充值¥{$value},折扣{$discount},余额¥{$recharge}";
     $id = $model->add();
     $service = \Service\CService::factory("Financial");
     $bill_id = $service->addBillProject(7, 0, $id, $member_id, I("cash") + I("pos") + I("check") + I("network") + I("netbank"), 0, get_brand_id(), is_user_login(), get_club_id(), $member['mc_id'], I("description"), $discount);
     if (!$bill_id) {
         $this->error($service->getError());
     }
     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), "充值¥{$value},折扣{$discount},余额¥{$recharge}" . I("description"), I("cash"), I("pos"), I("check"), I('check_num'), get_club_id(), 0, I("network"), I("netbank"));
     if (!$ret) {
         M("BillProject")->delete($bill_id);
         $this->error($service->getError());
     }
     $memberModel->where(array("id" => $member_id))->setField(array("recharge" => $recharge, "recharge_discount" => $discount));
     //       $cashModel = M("CashHistory");
     //       $cashModel->data(array("type"=>3,"cash"=>I("cash"),"check"=>I("check"),"pos"=> I("pos"),"object_id"=>$member_id,"price"=>0,"record_id"=>is_user_login(),"brand_id"=>get_brand_id(),"description"=>I("description"),"check_num"=>I('check_num')))->add();
     $this->ajaxReturn(array("status" => 1, "info" => "充值成功!", "recharge" => $recharge));
 }
 public function printAction($id)
 {
     $contract = D('PtContract')->relation(true)->find($id);
     $this->assign("contract", $contract);
     //pasy history
     $service = \Service\CService::factory("Financial");
     list($history, $count) = $service->getPayHistory("1", $id, 0, 999);
     $this->assign("history", $history);
     $club = M("Club")->find(get_club_id());
     $this->assign("club", $club);
     $this->assign("print_time", date('Y-m-d H:i:s'));
     $this->display();
 }
Пример #8
0
 public function queryConsumeAction()
 {
     $service = \Service\CService::factory("Member");
     list($page, $sidx, $limit, $sord, $start) = getRequestParams();
     $condition = array("brand_id" => get_brand_id());
     $filters = I("filters", '', '');
     $filters = json_decode($filters);
     if ($filters->groupOp == 'AND') {
         $rules = $filters->rules;
         $name = "";
         $phone = "";
         foreach ($rules as $key => $value) {
             if ($value->field == "club_id" && $value->data != -1) {
                 $condition["club_id"] = $value->data;
             } else {
                 if ($value->field == "name") {
                     $name = $value->data;
                 } else {
                     if ($value->field == "phone") {
                         $phone = $value->data;
                     } else {
                         if ($value->field == "contract_number") {
                             $contract = M("Contract")->where(array("contract_number" => $value->data))->find();
                             if (empty($contract)) {
                                 $response = array("page" => 0, "total" => 0, "records" => 0, "rows" => null);
                                 $this->ajaxReturn($response);
                             }
                             $condition["contract_id"] = $contract['id'];
                         } else {
                             if ($value->field == "card_number") {
                                 $card = M("Card")->where(array("card_number" => $value->data))->find();
                                 if (empty($card)) {
                                     $response = array("page" => 0, "total" => 0, "records" => 0, "rows" => null);
                                     $this->ajaxReturn($response);
                                 }
                                 $condition["card_id"] = $card['id'];
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($name) || !empty($phone)) {
             $members = $service->getMemberByBrand(get_brand_id(), $name, $phone);
             if (empty($members)) {
                 $response = array("page" => 0, "total" => 0, "records" => 0, "rows" => null);
                 $this->ajaxReturn($response);
             }
             $ids = "";
             foreach ($members as $k => $v) {
                 if ($k != 0) {
                     $ids .= ",";
                 }
                 $ids .= $v['id'];
             }
             $condition["member_id"] = array("in", $ids);
         }
     }
     $model = D("CheckHistory");
     $ret = $model->relation(true)->where($condition)->order("{$sidx} {$sord}")->limit("{$start},{$limit}")->select();
     $count = $model->where($condition)->count();
     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);
 }
Пример #9
0
 private function updateScore($member_id, $via, $extension)
 {
     //一周两次
     $start = date('Y-m-d 00:00:00', strtotime('last monday'));
     $end = date('Y-m-d 23:59:59', strtotime('next sunday'));
     $count = M("ScoreHistory")->where(array("member_id" => $member_id, "via" => 0, "create_time" => array("between", "{$start},{$end}")))->count();
     if ($count >= 2) {
         return;
     }
     $yaa = M("YaaMember")->find($member_id);
     if (empty($yaa)) {
         $level = 0;
         $historyscore = 0;
     } else {
         $level = $yaa['level'];
         $historyscore = $yaa['score'];
     }
     $classcore = $this->getScore($level, $via);
     $score = $classcore + $historyscore;
     $newlevel = $this->calLevel($score);
     $data = array("member_id" => $member_id, "level" => $newlevel, "score" => $score);
     if (empty($yaa)) {
         M("YaaMember")->data($data)->add();
     } else {
         M("YaaMember")->data($data)->save();
     }
     if ($newlevel != $level) {
         //生成证书
         $service = \Service\CService::factory("Image");
         $service->updateCer($member_id);
         M("YaaMember")->where(array("member_id" => $member_id))->setField(array("gift_status" => 0));
     }
     $data = array("member_id" => $member_id, "score" => $classcore, "via" => $via, "extension" => $extension);
     M("ScoreHistory")->data($data)->add();
 }
Пример #10
0
 public function importMemberAction()
 {
     setlocale(LC_ALL, 'en_US.UTF-8');
     set_time_limit(0);
     $club_id = get_club_id();
     $this->clean($club_id);
     $brand_id = get_brand_id();
     $upload = new \Think\Upload();
     // 实例化上传类
     // $upload->maxSize   =     3145728 ;// 设置附件上传大小
     $upload->exts = array('csv');
     // 设置附件上传类型
     $upload->rootPath = './Public/uploads/';
     // 设置附件上传根目录
     $upload->savePath = "import/";
     $upload->autoSub = false;
     $upload->replace = false;
     $upload->saveName = $brand_id . "_" . time();
     $info = $upload->uploadOne($_FILES['users']);
     if (!$info) {
         $this->error($upload->getError());
     } else {
         $file = './Public/uploads/' . $info['savepath'] . $info['savename'];
         // $this->checkFile($file);
         $handle = fopen($file, 'r');
         if ($handle) {
             $count = 0;
             $arr = array();
             $users = fgetcsv($handle);
             while ($users = fgetcsv($handle)) {
                 try {
                     $count++;
                     $data = array();
                     $data['name'] = $users[0];
                     $data['phone'] = $users[1];
                     if (empty($data['phone'])) {
                         $data['phone'] = time();
                     }
                     $mc_id = trim($users[14]);
                     if (empty($mc_id)) {
                         $mc_id = 0;
                         $users[14] = 0;
                     } else {
                         if (!is_numeric($mc_id)) {
                             $mcs = M("UserExtension")->where(array("name_cn" => $mc_id))->select();
                             $mc = null;
                             foreach ($mcs as $key => $value) {
                                 $m = M("User")->find($value['id']);
                                 if ($m['club_id'] == get_club_id()) {
                                     $mc = $m;
                                 }
                             }
                             if (empty($mc)) {
                                 $mc_id = M("User")->data(array("username" => "xj" . $users[14], "password" => md5('111111'), "club_id" => get_club_id(), "brand_id" => get_brand_id()))->add();
                                 M("UserExtension")->data(array("work_status" => 0, "id" => $mc_id, "name_cn" => $users[14], "name_en" => $users[14]))->add();
                                 M("AuthGroupAccess")->data(array("uid" => $mc_id, "group_id" => 6))->add();
                                 $users[14] = $mc_id;
                             } else {
                                 $users[14] = $mc['id'];
                             }
                         }
                     }
                     $m = M("MemberBasic")->where(array("club_id" => get_club_id(), "name" => trim($users[0]), "phone" => trim($users[1])))->find();
                     if (!empty($m)) {
                         $uid = $m['id'];
                     } else {
                         $model = D("MemberBasic");
                         $data['sex'] = $users[2];
                         $data['type'] = 1;
                         $data['email'] = $users[3];
                         $data['birthday'] = $users[4];
                         $data['home_phone'] = $users[5];
                         $data['home_addr'] = $users[6];
                         $data['country'] = $users[7];
                         $data['nation'] = $users[8];
                         $data['job'] = $users[9];
                         $data['desc'] = $users[10];
                         $data['brand_id'] = get_brand_id();
                         $data['club_id'] = get_club_id();
                         $data['in_pool'] = 0;
                         $data['is_member'] = 1;
                         $data['join_time'] = trim($users[24]);
                         if (empty($data['join_time'])) {
                             $data['join_time'] = $users[15];
                         }
                         $data['mc_id'] = trim($users[14]);
                         $data['certificate_number'] = trim($users[23]);
                         if (!$model->create($data)) {
                             $this->clean($club_id);
                             $this->error("{$count}行数据有误--" . $model->getError());
                         }
                         $uid = $model->data($data)->add();
                     }
                     $card_type = "湘江世纪城——" . trim($users[11]);
                     $pattern = array('/一/', '/二/', '/三/', '/四/', '/五/', '/六/', '/七/', '/八/', '/九/', '/十/');
                     $replace = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
                     $card_type = preg_replace($pattern, $replace, $card_type);
                     $cardTypeModel = M("CardType");
                     $cardType = $cardTypeModel->where(array("name" => $card_type))->find();
                     //添加卡种
                     if ($users[12] == 0) {
                         $valid_number = 0;
                         if (preg_match('/[1|一]年卡/u', $card_type)) {
                             $valid_time = 12;
                         } else {
                             if (preg_match('/[2|二|两]年卡/u', $card_type)) {
                                 $valid_time = 24;
                             } else {
                                 if (preg_match('/[3|三]年卡/u', $card_type)) {
                                     $valid_time = 36;
                                 } else {
                                     if (preg_match('/半年(.*)卡/u', $card_type)) {
                                         $valid_time = 6;
                                     } else {
                                         if (preg_match('/季(度)?卡/u', $card_type)) {
                                             $valid_time = 3;
                                         } else {
                                             if (preg_match('/(\\d+)(个)?月卡/i', $card_type, $matches)) {
                                                 $valid_time = $matches[1];
                                             } else {
                                                 $valid_time = 12;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         if (preg_match('/\\d+/i', $card_type, $matches)) {
                             $valid_number = $matches[0];
                         } else {
                             $this->clean($club_id);
                             $this->error("{$count}行次不明!");
                         }
                         $valid_time = 12;
                     }
                     if (empty($cardType)) {
                         $data = array("name" => $card_type, "category" => 1, "type" => 1 + $users[12], "valid_time" => $valid_time, "brand_id" => get_brand_id(), "start_time" => "2015-01-01", "end_time" => "2019-01-01", "price" => $users[18], "valid_number" => $valid_number, "sold_num" => 999999, "min_price" => $users[18] - 500);
                         $cardtypeid = M("CardType")->data($data)->add();
                         M("CardSaleclub")->data(array("card_type_id" => $cardtypeid, "club_id" => get_club_id()))->add();
                         M("CardUseclub")->data(array("card_type_id" => $cardtypeid, "club_id" => get_club_id()))->add();
                     } else {
                         $cardtypeid = $cardType['id'];
                     }
                     $card_type_id = $cardtypeid;
                     $mc_id = trim($users[12]);
                     $start_time = trim($users[15]);
                     $end_time = trim($users[16]);
                     $card_number = trim($users[17]);
                     $cardModel = D("Card");
                     $cardTypeModel = M("CardType");
                     $cardType = $cardTypeModel->find($card_type_id);
                     if (empty($cardType)) {
                         $this->clean($club_id);
                         $this->error("{$count}行卡种不存在!");
                     }
                     if (empty($card_number)) {
                         $card_number = date("YmdHis") . rand(0, 10000);
                         $card = array("free_rest" => 0, "sale_club" => get_club_id(), "is_active" => 0, "brand_id" => get_brand_id(), "card_number" => $card_number, "member_id" => $uid);
                         $card['update_time'] = getDbTime();
                         $card_id = $cardModel->data($card)->add();
                         $max_card = M("Card")->where(array("sale_club" => get_club_id(), "is_auto_create" => 1))->order("card_number desc")->find();
                         if (empty($max_card)) {
                             $card_number = get_club_id() . "00001";
                         } else {
                             $card_number = $max_card['card_number'] + 1;
                         }
                         $card_number = preg_replace("/4/", "5", $card_number);
                         while (true) {
                             if ($cardModel->isExist($card_number, get_brand_id())) {
                                 $card_number += 1;
                                 $card_number = preg_replace("/4/", "5", $card_number);
                             } else {
                                 break;
                             }
                         }
                         $cardModel->where("id={$card_id}")->setField(array("card_number" => $card_number, "is_auto_create" => "1"));
                     } else {
                         $card = array("free_rest" => 0, "sale_club" => get_club_id(), "is_active" => 0, "brand_id" => get_brand_id(), "card_number" => $card_number, "member_id" => $uid);
                         $card_id = $cardModel->data($card)->add();
                     }
                     if (!$card_id) {
                         $this->error("{$count}行开卡失败,请稍后再试!");
                         $this->clean($club_id);
                     }
                     $model = D("Contract");
                     $payed = trim($users[19]);
                     $contract_number = date("YmdHis") . rand(0, 10000);
                     $data = array("total_num" => $valid_number, "member_id" => $uid, "start_time" => $start_time, "end_time" => $end_time, "brand_id" => get_brand_id(), "card_type_id" => $card_type_id, "type" => 0, "description" => $users[22], "price" => $payed, "sale_club_id" => get_club_id(), "card_id" => $card_id, "payed" => $payed, "contract_number" => $contract_number, "mc_id" => trim($users[14]), "card_type_extension" => json_encode($cardType), "active_type" => 2);
                     $contract_id = $model->data($data)->add();
                     $service = \Service\CService::factory("Financial");
                     $bill_id = $service->addBillProject(0, 0, $contract_id, $uid, $payed, 0, get_brand_id(), is_user_login(), get_club_id(), trim($users[14]), $users[22]);
                     if (!$bill_id) {
                         $this->clean($club_id);
                         $this->error("{$count}行数据有误--" . $service->getError());
                     }
                     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), $users[22], $payed, 0, 0, 0, get_club_id(), 0, 0, 0);
                     if (!$ret) {
                         $this->clean($club_id);
                         $this->error("{$count}行数据有误--" . $service->getError());
                     }
                 } catch (Exception $e) {
                     $this->clean($club_id);
                     $this->error($e->getMessage());
                 }
             }
         } else {
             $this->clean($club_id);
             $this->error("error!");
         }
     }
     $this->success("Success!");
 }
Пример #11
0
 public function buyAction()
 {
     $member_id = I("member_id");
     $member = M("MemberBasic")->find(I("member_id"));
     if (empty($member)) {
         $this->error("member does not exist");
     }
     $class_id = I("class_id");
     $class = M("PtClass")->find($class_id);
     if (empty($class)) {
         $this->error("class is not exist!");
     }
     $use_recharge = I("use_recharge");
     $model = D("PtContract");
     if (!$model->create()) {
         $this->error($model->getError());
     }
     $rules = array(array('pos', 'number', '请输入正确的pos金额!', 1), array('cash', 'number', '请输入正确的现金金额!', 1), array('check', 'number', '请输入正确的支票金额!', 1), array('network', 'number', '请输入正确的网络支付金额!', 1), array('netbank', 'number', '请输入正确的网银分期金额!', 1));
     // $cashHistoryModel=M("CashHistory");
     // if (!$cashHistoryModel->validate($rules)->create()){
     //     $this->error($cashHistoryModel->getError());
     // }
     $paid = I("cash") + I("pos") + I("check") + I("network") + I("netbank");
     $book_price = 0;
     $price = I("should_pay");
     if ($member['pt_book_price'] != 0) {
         $book_price = $price - $paid > $member['pt_book_price'] ? $member['pt_book_price'] : $price - $paid;
         $paid += $book_price;
     }
     $recharge = 0;
     $should_pay = $price - $paid;
     if ($use_recharge == 1) {
         $recharge = $member['recharge'] > $should_pay ? $should_pay : $member['recharge'];
     }
     $paid += $recharge;
     $model->paid = $paid;
     $contract_number = date("YmdHis") . rand(0, 10000);
     $model->contract_number = $contract_number;
     $model->pt_id = $member['pt_id'];
     $pt_id = I("pt_id");
     if (!empty($pt_id)) {
         $model->pt_id = $pt_id;
     }
     $start_time = I("start_time");
     $end_time = I("end_time");
     if (empty($start_time)) {
         $start_time = date('Y-m-d');
     }
     if (empty($end_time)) {
         $end_time = date('Y-m-d', strtotime("+2 years"));
     }
     $model->start_time = $start_time;
     $model->end_time = $end_time;
     $contract_id = $model->add();
     if (empty($contract_id)) {
         $this->error("Error!请检查参数的正确性");
     }
     if ($use_recharge == 1 && $recharge != 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] - $recharge);
         $data = array("member_id" => $member_id, "value" => "-{$recharge}", "record_id" => is_user_login(), "description" => "购PT消费¥{$recharge},余额¥" . ($member['recharge'] - $recharge));
         $recharge_id = M("RechargeHistory")->data($data)->add();
     }
     $service = \Service\CService::factory("Financial");
     $bill_id = $service->addBillProject(1, 0, $contract_id, $member_id, I("should_pay"), 0, get_brand_id(), is_user_login(), get_club_id(), $member['pt_id'], I("description"));
     if (!$bill_id) {
         $model->delete($contract_id);
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] + $recharge);
         if (isset($recharge_id)) {
             M("RechargeHistory")->delete($recharge_id);
         }
         $this->error($service->getError());
     }
     $ret = $service->pay($bill_id, 0, is_user_login(), get_brand_id(), I('description'), I("cash"), I("pos"), I("check"), I("check_num"), get_club_id(), $recharge, I("network"), I("netbank"));
     if (!$ret) {
         $model->delete($contract_id);
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] + $recharge);
         if (isset($recharge_id)) {
             M("RechargeHistory")->delete($recharge_id);
         }
         M("BillProject")->delete($bill_id);
         $this->error($service->getError());
     }
     if ($book_price != 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setDec("pt_book_price", $book_price);
         $bill_project = M("BillProject")->where(array("member_id" => $member_id, "type" => 8, "object_id" => 0))->select();
         $i = $book_price;
         foreach ($bill_project as $key => $value) {
             $i -= $value['paid'];
             M("BillProject")->where("id=" . $value['id'])->setField(array("object_id" => $contract_id));
             if ($i <= 0) {
                 break;
             }
         }
         M("BillProject")->where("id={$bill_id}")->setInc("paid", $book_price);
     }
     // $cashHistoryModel->data(array("type"=>1,"sub_type"=>0,"recharge"=>$recharge,"cash"=>I("cash"),"check"=>I("check"),"pos"=> I("pos"),"object_id"=>$contract_id,"price"=>I("should_pay"),"record_id"=>is_user_login(),"brand_id"=>get_brand_id()))->add();
     $reason = "新增PT合同";
     if ($class['price'] * I("total_num") > I("should_pay")) {
         $reason .= ";收银过低";
     }
     if (!empty($reason)) {
         $contract = M("PtContract")->find($contract_id);
         $data = array("extension" => json_encode($contract), "reason" => $reason, "record_id" => is_user_login(), "club_id" => get_club_id(), "brand_id" => get_brand_id(), "type" => 1, "status" => 0);
         M("Review")->data($data)->add();
     }
     $cards = D("Card")->getAllCards($member_id, get_brand_id());
     if (empty($cards)) {
         $cardModel = D("Card");
         $card_number = date("YmdHis") . rand(0, 10000);
         $card = array("free_rest" => I("free_rest"), "sale_club" => get_club_id(), "is_active" => 1, "brand_id" => get_brand_id(), "card_number" => $card_number, "member_id" => $member_id);
         $card['update_time'] = getDbTime();
         $card_id = $cardModel->data($card)->add();
         $card_number = get_club_id() . $card_id;
         while (true) {
             if ($cardModel->isExist($card_number, get_brand_id())) {
                 $card_number .= rand(0, 100);
             } else {
                 break;
             }
         }
         $cardModel->where("id={$card_id}")->setField("card_number", $card_number);
         $this->success("购买成功!相关卡号为:{$card_number} 请前台烧卡!", U("Cashier/Ptcontract/index"));
     }
     $this->success("购买成功!您的任意会员卡均可进行私教消费!", U("Cashier/Ptcontract/index"));
 }
Пример #12
0
 public function autoCheckOutAction()
 {
     $time = date('Y-m-d', strtotime("1 day ago"));
     $sql = "select contract_id,club_id from yoga_check_history  a where create_time > '{$time}' and status=1 and not exists(select * from yoga_check_history b where  a.contract_id=b.contract_id and b.create_time > a.create_time and b.status=0);";
     $Model = new \Think\Model();
     $ret = $Model->query($sql);
     $service = \Service\CService::factory("Api");
     $time = date('Y-m-d H:i:s');
     foreach ($ret as $key => $value) {
         $contract_id = $value['contract_id'];
         $club_id = $value['club_id'];
         echo "{$time} : {$contract_id}  auto checkout!\r\n";
         $service->myout($contract_id, $club_id);
     }
 }
Пример #13
0
 public function cerAction($id)
 {
     $cer = M("CerHistory")->where(array("member_id" => $id))->order("level desc")->find();
     if (empty($cer)) {
         $service = \Service\CService::factory("Image");
         $service->updateCer($id);
         $cer = M("CerHistory")->where(array("member_id" => $id))->order("level desc")->find();
     }
     $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
     $root = C("pic_path");
     $file = "/Public/" . str_replace("{$root}", "", $cer['file']);
     $cer['url'] = $sys_protocal . $_SERVER['HTTP_HOST'] . $file;
     $this->ajaxReturn(array("status" => 1, "data" => $cer));
 }
Пример #14
0
 public function checkoutAction($id)
 {
     $bill = M("BillProject")->find($id);
     $contract = M("Contract")->find($bill['object_id']);
     $card = M("Card")->find($contract['card_id']);
     $service = \Service\CService::factory("Api");
     list($status, $member) = $service->out($card['card_number'], get_club_id());
     if ($status != 0) {
         $this->error($service->getError());
     }
     $this->success("ok");
 }
Пример #15
0
 public function doPayAction()
 {
     $goodsModel = M("Goods");
     $goodsModel->startTrans();
     $service = \Service\CService::factory("Financial");
     $bill_project = M("BillProject")->find(I("id"));
     if (empty($bill_project)) {
         $goodsModel->rollback();
         $this->error("Bill is not exist!");
     }
     $recharge = 0;
     $member_id = I("member_id");
     $member = M("MemberBasic")->find(I("member_id"));
     $price = $bill_project['price'] - $bill_project['paid'];
     if (I('use_recharge') == 1) {
         $recharge = $member['recharge'];
         $recharge = $recharge > $price ? $price : $recharge;
     }
     $ret = $service->pay(I("id"), 1, is_user_login(), get_brand_id(), I("description"), I("cash"), I("pos"), I("check"), I('check_num'), get_club_id(), $recharge, I("network"), I("netbank"));
     if (!$ret) {
         $goodsModel->rollback();
         $this->error($service->getError());
     }
     if (I('use_recharge') == 1 && $recharge > 0) {
         M("MemberBasic")->where(array("id" => $member_id))->setField("recharge", $member['recharge'] - $recharge);
         $data = array("member_id" => $member_id, "value" => "-{$recharge}", "record_id" => is_user_login(), "description" => "支付购物欠款,余额" . ($member['recharge'] - $recharge));
         M("RechargeHistory")->data($data)->add();
     }
     $goodsModel->commit();
     $this->success("支付成功", U("printreceipts", array("id" => $ret)));
 }
Пример #16
0
 public function disagreeAction()
 {
     $service = \Service\CService::factory("Financial");
     $ret = $service->disagree(I("id"));
     $this->success("success");
 }
Пример #17
0
 public function getMembersAction()
 {
     $service = \Service\CService::factory("Member");
     $response = $service->getMembers();
     $this->ajaxReturn($response);
 }
Пример #18
0
 public function printreceiptsAction($id)
 {
     $service = \Service\CService::factory("Financial");
     $history = $service->getPayRecord($id);
     $this->assign("history", $history);
     $project = M("BillProject")->find($history["bill_project_id"]);
     $this->assign("bill", $project);
     $num = 1;
     $items = array();
     switch ($project['type']) {
         case '8':
             $title = "PT定金收费";
             break;
         case '9':
             $title = "会籍定金收费";
             break;
         case '10':
             $title = "退卡费用";
             break;
         case '0':
             $title = "合同收款";
             $items[] = array("key" => "合同类型", "value" => "新办合同");
             break;
         case '1':
             $title = "PT合同收款";
             break;
         case '2':
             $order_id = $project['object_id'];
             $order = M("GoodsSaleList")->where(array("order_id" => $order_id))->select();
             $title = "商品收款";
             break;
         case '3':
             $title = "转让收款";
             $items[] = array("key" => "合同类型", "value" => "转让合同");
             break;
         case '4':
             $title = "续会收款";
             $items[] = array("key" => "合同类型", "value" => "续会合同");
             break;
         case '5':
             $title = "升级收款";
             $items[] = array("key" => "合同类型", "value" => "升级合同");
             break;
         case '7':
             $title = "充值收款";
             break;
         default:
             # code...
             break;
     }
     $head = "收款票据";
     if ($history['is_printed'] > 0) {
         $head = $head . "(补)";
     }
     $this->assign("title", $title);
     $this->assign("head", $head);
     if (empty($order)) {
         $order = array(array("goods_name" => $title, "number" => 1, "price" => $project['price']));
     }
     $this->assign("order", $order);
     if ($project['type'] == 0 || $project['type'] == 3 || $project['type'] == 4 || $project['type'] == 5) {
         $contract = M("Contract")->find($project['object_id']);
         $card_type = M("CardType")->find($contract['card_type_id']);
         $items[] = array("key" => "购买卡种", "value" => $card_type['name']);
         if (!empty($contract['mc_id'])) {
             $mc = M("UserExtension")->find($contract['mc_id']);
             $items[] = array("key" => "会籍顾问", "value" => $mc['name_cn']);
         } else {
             $items[] = array("key" => "会籍顾问", "value" => "");
         }
     } else {
         if ($project['type'] == 1) {
             $contract = M("PtContract")->find($project['object_id']);
             switch ($contract['sale_type']) {
                 case '1':
                     $type = "新会员购买";
                     break;
                 case '2':
                     $type = "续课";
                     break;
                 case '3':
                     $type = "POS销售";
                     break;
                 case '4':
                     $type = "场地开发";
                     break;
                 default:
                     break;
             }
             $items[] = array("key" => "合同类型", "value" => $type);
             if (!empty($contract['pt_id'])) {
                 $mc = M("UserExtension")->find($contract['pt_id']);
                 $items[] = array("key" => "私教名", "value" => $mc['name_cn']);
             }
             $class_id = $contract['class_id'];
             $class = M("PtClass")->find($class_id);
             $items[] = array("key" => "课程名称", "value" => $class['name']);
             $num = $contract['total_num'];
         }
     }
     $this->assign("num", $num);
     $this->assign("items", $items);
     $club = M("Club")->find(get_club_id());
     $cashier = M("UserExtension")->find($history['record_id']);
     if (empty($cashier)) {
         $brand = M("Brand")->find($history['brand_id']);
         $this->assign("cashier", $brand['brand_name']);
     } else {
         $this->assign("cashier", $cashier['name_cn']);
     }
     $member = M("MemberBasic")->find($project['member_id']);
     $this->assign("member", $member);
     $this->assign("club", $club);
     $this->assign("print_time", date('Y-m-d H:i:s'));
     M("PayHistory")->where(array("id" => $id))->setInc("is_printed");
     $new_printer_club = C("new_printer_club");
     $club_id = get_club_id();
     if (in_array($club_id, $new_printer_club)) {
         $this->display('Common@Base:printreceiptsnew');
     } else {
         $this->display('Common@Base:printreceipts');
     }
 }