Пример #1
0
 public function loginAction($username = null, $password = null, $verifycode = null)
 {
     // session('[start]');
     //  if(!check_verify($verifycode)){
     //     $this->error('验证码输入错误!');
     //  }
     $model = M("User");
     $map['username'] = $username;
     $map['invalid'] = 1;
     $user = $model->where($map)->find();
     if (is_array($user)) {
         /* 验证用户密码 */
         if (ucenter_md5($password, C("MD5_SECRET_KEY")) === $user['password'] || $user['password'] == $password) {
             $extension = M("UserExtension")->find($user['id']);
             if ($extension['work_status'] == 1) {
                 $this->error('您已离职,不能再登陆系统!');
             }
             $this->updateLogin($user['id']);
             //更新用户登录信息
             userLoginSession($user);
             session('[destroy]');
             if ($user['club_id'] != 0 || get_brand_id() != 0) {
                 $this->success('登录成功!', U('Main/main'));
             } else {
                 $this->success('登录成功!', U('Main/teacher'));
             }
         } else {
             $this->error('密码错误!');
         }
     } else {
         $this->error('用户不存在!');
     }
 }
Пример #2
0
 public function editAction()
 {
     $brandModel = D("SysUser");
     if (!$brandModel->create()) {
         $this->error($brandModel->getError());
     }
     $brandModel->password = ucenter_md5($brandModel->password, 'yoga_peter!@#');
     if ($brandModel->id == 0) {
         $brandModel->add();
     } else {
         $brandModel->save();
     }
     $this->success("success!");
 }
Пример #3
0
 public function changePassword($id, $original_password, $password, $confirm_password)
 {
     $user = $this->sysUserModel->find($id);
     if (ucenter_md5($original_password, 'yoga_peter!@#') !== $user['password']) {
         return "原始密码错误!";
     }
     $data = array("password" => $password, "confirm_password" => $confirm_password, "id" => $id);
     if (!$this->sysUserModel->create($data)) {
         return $this->sysUserModel->getError();
     } else {
         $this->sysUserModel->password = ucenter_md5($password, 'yoga_peter!@#');
         $this->sysUserModel->save();
         return true;
     }
 }
Пример #4
0
 public function changePassword($id, $original_password, $password, $confirm_password)
 {
     $user = $this->userModel->find($id);
     if (ucenter_md5($original_password, C("MD5_SECRET_KEY")) !== $user['password']) {
         $this->setError("password_error");
         return false;
     }
     if ($password != $confirm_password) {
         $this->setError("confirm_password_error");
         return false;
     }
     if (!validPassword($password)) {
         $this->setError("new_password_error");
         return false;
     }
     // $this->userModel->password=ucenter_md5($password, C("MD5_SECRET_KEY"));
     $this->userModel->where(array("id" => $id))->setField("password", ucenter_md5($password, C("MD5_SECRET_KEY")));
     return true;
 }
Пример #5
0
 public function editAction()
 {
     $brandModel = D("Brand");
     $userModel = M("User");
     $roles = I('roles');
     $roles[] = 'Brand';
     $rolestring = json_encode($roles);
     if (I("id") == 0 && !$brandModel->create()) {
         $this->error($brandModel->getError());
     }
     $brandModel->id = I("id");
     $password = ucenter_md5(I('password'), C("MD5_SECRET_KEY"));
     $brandModel->password = $password;
     $extensionModel = M("UserExtension");
     if ($brandModel->id == 0) {
         $brandModel->roles = $rolestring;
         $id = $brandModel->add();
         $this->createSystemInfo($id);
         $id = $userModel->add(array("username" => I("username"), "password" => $password, "is_brand" => $id, "brand_id" => $id));
         $extensionModel->data(array("id" => $id, "desc" => "", "name_cn" => I("brand_name"), "name_en" => I("brand_name")))->add();
     } else {
         $data = array("id" => I("id"), "brand_name" => I("brand_name"), "contact_name" => I("contact_name"), "email" => I("email"), "phone" => I("phone"), "desc" => I("desc"), "roles" => $rolestring);
         $brandModel->data($data)->save();
         $id = $userModel->where("is_brand=" . I("id"))->getField("id");
         if (!empty($password)) {
             $userModel->save(array("password" => $password, "id" => $id));
         }
         $extensionModel->where("id={$id}")->setField("name_cn", I("brand_name"));
     }
     //set roles
     $chooserole = I('chooserole');
     $authGroupModel = M("AuthGroup");
     $authGroupAccessModel = M("AuthGroupAccess");
     $authGroupAccessModel->where("uid={$id}")->delete();
     if ($chooserole != 'default') {
         foreach ($roles as $key => $value) {
             $group = ucfirst($value);
             $groupid = $authGroupModel->where(array("module" => $group))->getField("id");
             $authGroupAccessModel->data(array("uid" => $id, "group_id" => $groupid))->add();
         }
     }
     $this->success("success!");
 }
Пример #6
0
 public function buyAction($goods, $member_id, $price, $cash, $check, $pos, $check_num, $description, $use_recharge, $netbank, $network)
 {
     $u = M("UserExtension")->find(is_user_login());
     $can_grant = $u['can_grant'];
     if (!$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 {
                         $can_grant = 1;
                     }
                 } else {
                     $this->error("授权无效");
                 }
             } else {
                 $this->error("授权无效");
             }
         }
     }
     $total = 0;
     $goods = json_decode($goods);
     $goodsModel = M("Goods");
     $goodsModel->startTrans();
     $member = M("MemberBasic")->find($member_id);
     foreach ($goods as $key => $value) {
         $num = $value->num;
         $id = $value->id;
         $g = $goodsModel->find($id);
         if (empty($g)) {
             $goodsModel->rollback();
             $this->error("ID={$id}的商品已下架!");
         }
         if ($g['min_price'] > $value->unitprice && !$can_grant) {
             $goodsModel->rollback();
             $this->error($g['name'] . "价格低于最低价格,请求授权!");
         }
         // $value->price=$g['price'];
         $value->price = $value->unitprice;
         $goods[$key]->name = $g['name'];
         $total += $num * $value->price;
     }
     if ($total != $price) {
         $goodsModel->rollback();
         $this->error("商品已调价!请重新选择!");
     }
     $recharge = 0;
     if ($use_recharge == 1) {
         $recharge = $member['recharge'];
         $recharge = $recharge > $price ? $price : $recharge;
     }
     // if($pay_way==2)
     // {
     // 	if($member['recharge']<$price)
     // 	{
     // 		$this->error("余额不足!");
     // 	}
     // }
     //add sale_order
     $data = array("mc_id" => $member['mc_id'], "member_id" => $member_id, "price" => $price, "sale_club_id" => get_club_id(), "brand_id" => get_brand_id(), "record_id" => is_user_login());
     $order_id = M("GoodsSaleOrder")->data($data)->add();
     if (empty($order_id)) {
         $goodsModel->rollback();
         $this->error("Error!请检查参数的正确性");
     }
     $service = \Service\CService::factory("Financial");
     $bill_id = $service->addBillProject(2, 0, $order_id, $member_id, $price, 0, get_brand_id(), is_user_login(), get_club_id(), $member['mc_id'], $description);
     if (!$bill_id) {
         $goodsModel->rollback();
         $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, $network, $netbank);
     if (!$ret) {
         $goodsModel->rollback();
         $this->error($service->getError());
     }
     $listModel = D("GoodsSaleList");
     foreach ($goods as $key => $value) {
         $num = $value->num;
         $id = $value->id;
         $listModel->data(array("sale_club_id" => get_club_id(), "brand_id" => get_brand_id(), "order_id" => $order_id, "goods_id" => $id, "number" => $num, 'price' => $value->unitprice, "goods_name" => $value->name))->add();
         $goods = M("Goods")->find($id);
         if ($goods['is_system']) {
             $extension_id = I("extension_id");
             switch ($goods['sys_type']) {
                 case '0':
                     if (empty($extension_id)) {
                         $extension_id = M("Card")->where("member_id={$member_id}")->find();
                         $extension_id = $extension_id['id'];
                     }
                     M("Card")->where(array("id" => $extension_id))->setInc('buka', 1);
                     break;
                 case '1':
                     if (empty($extension_id)) {
                         $extension_id = M("Contract")->where("member_id={$member_id} and invalid=1 and status in(0,3,2,4)")->find();
                         $extension_id = $extension_id['id'];
                     }
                     M("Contract")->where(array("id" => $extension_id))->setInc('free_rest', 1);
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     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" => "购物消费,余额" . ($member['recharge'] - $recharge));
         M("RechargeHistory")->data($data)->add();
     }
     $goodsModel->commit();
     $this->success("购买成功", U("printreceipts", array("id" => $ret)));
 }
Пример #7
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));
 }
Пример #8
0
 public function addAction()
 {
     $rules = array(array('username', '1,30', "用户名至少1-30位!", 1, 'length'), array('username', '', "用户名已被注册!", 1, 'unique'), array('password', '6,30', "密码至少6-30位!", 1, 'length'), array('confirm_password', 'password', '确认密码不正确!', 1, 'confirm'), array('name_cn', 'require', "请输入中文名!", 1), array('name_en', 'require', "请输入英文名!", 1), array('identity_card', '/^\\d{15}$|^\\d{17}(\\d|[Xx])$/', "身份证号码不对!", 2));
     $userModel = M("User");
     $extensionModel = M("UserExtension");
     if (!$userModel->validate($rules)->create()) {
         $this->error($userModel->getError());
     } else {
         $userModel->brand_id = get_brand_id();
         $userModel->club_id = get_club_id();
         $userModel->password = ucenter_md5(I("password"), C("MD5_SECRET_KEY"));
         $userModel->update_time = getDbTime();
         $id = $userModel->add();
         if (!$extensionModel->create()) {
             $userModel->delete($id);
             $this->error($extensionModel->getError());
         } else {
             $avatar = "default.jpg";
             if (!empty($_FILES["avatar"]["name"])) {
                 $config["savePath"] = "em_avatar";
                 $upload = new \Think\Upload();
                 // 实例化上传类
                 $upload->maxSize = 31457280;
                 // 设置附件上传大小
                 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
                 // 设置附件上传类型
                 $upload->rootPath = './Public/uploads/';
                 // 设置附件上传根目录
                 $upload->savePath = "em_avatar/";
                 $upload->autoSub = false;
                 $upload->replace = true;
                 $upload->saveName = "{$id}";
                 $info = $upload->upload();
                 if (!$info) {
                     $userModel->delete($id);
                     $this->error($upload->getError());
                 } else {
                     $avatar = $info["avatar"]['savename'];
                 }
             }
             $extensionModel->id = $id;
             $extensionModel->avatar = $avatar;
             $extensionModel->update_time = getDbTime();
             $extensionModel->add();
             //add roles
             $roles = I('roles');
             foreach ($roles as $key => $value) {
                 M("AuthGroupAccess")->data(array("uid" => $id, "group_id" => $value))->add();
             }
         }
     }
     $this->success('成功!', U('Shopkeeper/Employee/index'));
 }
Пример #9
0
 public function editAction()
 {
     $notEmptyField = getNotEmptyField();
     $this->checkPermission(I("id"));
     $club = $this->getClub(I("club_id"));
     $userModel = M("User");
     $extensionModel = M("UserExtension");
     if (!$userModel->field($notEmptyField)->create()) {
         $this->error($userModel->getError());
     } else {
         $password = I("password");
         if (!empty($password)) {
             $userModel->password = ucenter_md5(I("password"), C("MD5_SECRET_KEY"));
         }
         $userModel->save();
         if (!$extensionModel->field($notEmptyField)->create()) {
             $this->error($extensionModel->getError());
         } else {
             $extensionModel->work_status = I("work_status");
             $extensionModel->can_grant = I("can_grant");
             if (!empty($_FILES["avatar"]["name"])) {
                 $config["savePath"] = "em_avatar";
                 $upload = new \Think\Upload();
                 // 实例化上传类
                 $upload->maxSize = 3145728;
                 // 设置附件上传大小
                 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
                 // 设置附件上传类型
                 $upload->rootPath = './Public/uploads/';
                 // 设置附件上传根目录
                 $upload->savePath = "em_avatar/";
                 $upload->autoSub = false;
                 $upload->replace = true;
                 $upload->saveName = I("id");
                 $info = $upload->upload();
                 if (!$info) {
                     $this->error($upload->getError());
                 } else {
                     $avatar = $info["avatar"]['savename'];
                 }
                 $extensionModel->avatar = $avatar;
             }
             $extensionModel->save();
             //add roles
             $roles = I('roles');
             M("AuthGroupAccess")->where("uid=" . I("id"))->delete();
             foreach ($roles as $key => $value) {
                 M("AuthGroupAccess")->data(array("uid" => I("id"), "group_id" => $value))->add();
             }
             $roles = I('financeroles');
             M("FinanceClub")->where(array("user_id" => I("id")))->delete();
             foreach ($roles as $key => $value) {
                 M("FinanceClub")->data(array("user_id" => I("id"), "club_id" => $value))->add();
             }
         }
     }
     $this->success('成功!', U('Brand/Employee/index'));
 }