/**
  * 下订单
  * 判断是否是POST提交
  * 如果是POST提交则进行下单操作
  * 否则 提示错误
  *
  *
  * @author 李东
  *         @date						2015-07-09
  */
 public function add_order()
 {
     if (IS_POST) {
         $posts = I('post.');
         // print_r($posts);exit;
         /* 获取当前登录的用户的ID */
         $member_id = session('home_member_id');
         $rules = array(array('qty', '/^[1-9]\\d*(\\.\\d+)?$/', '数量必须大于1', 'regex'));
         // 默认情况下用正则进行验证
         if (!$posts['agree']) {
             $tips_msg = array('status' => '0', 'msg' => '请同意保密协议');
             goto export;
             /* 直接跳转到输出位置 */
         }
         /* 如果需要发票,判断发票信息是否填写 */
         if ($posts['need_invoice']) {
             if (empty(trim($posts['invoice']))) {
                 $tips_msg = array('status' => '0', 'msg' => '请填写发票抬头');
                 goto export;
             }
             if (intval($posts['address_id']) < 1) {
                 $tips_msg = array('status' => '0', 'msg' => '请选择发票寄送地址');
                 goto export;
             }
         }
         $product_info = get_info($this->product_table, array('id' => $posts['product_id']));
         $shop_id = $product_info['shop_id'];
         /* 获取店铺ID */
         $product_type = $product_info['type'];
         /* 获取产品类型 */
         $address_path = '';
         $area_detail = '';
         $product_title = $product_info['title'];
         /*获取产品title*/
         $product_description = array();
         if (empty($posts['expected_start_time']) || empty($posts['expected_end_time'])) {
             $tips_msg = array('status' => '0', 'msg' => '请填写完整预约服务时间');
             goto export;
         }
         if ($posts['expected_start_time'] >= $posts['expected_end_time']) {
             $tips_msg = array('status' => '0', 'msg' => '结束时间必须大于开始时间');
             goto export;
         }
         if ($product_type == 37) {
             /* 判断是否填写了详细信息 */
             if (empty(trim($posts['area_detail']))) {
                 $tips_msg = array('status' => '0', 'msg' => '请填写详细地址');
                 goto export;
             } elseif (empty($posts['addpath'])) {
                 $tips_msg = array('status' => '0', 'msg' => '请选择服务地址');
                 goto export;
             } else {
                 /* 选择服务地址的path */
                 $address_path = $posts['addpath'] . $posts['area'];
                 $area_detail = $posts['area_detail'];
             }
         } else {
             if (!$posts['language_sbt']) {
                 $tips_msg = array('status' => '0', 'msg' => '请选择翻译模式');
                 goto export;
             }
             /* 判断文件用途 */
             if ($posts['ability_id'] == 'other') {
                 $description = $posts['ability_other'];
                 $product_description['ability_other'] = $description;
             } elseif (is_numeric($posts['ability_id'])) {
                 $product_description['ability_id'] = $posts['ability_id'];
             } else {
                 $tips_msg = array('status' => '0', 'msg' => '请选择服务领域或文件领域');
                 goto export;
             }
         }
         /* 判断专业领域 */
         if ($posts['industry_id'] == 'other') {
             $description = $posts['industry_other'];
             $product_description['industry_other'] = $description;
         } elseif (is_numeric($posts['industry_id'])) {
             $product_description['industry_id'] = $posts['industry_id'];
         } else {
             $tips_msg = array('status' => '0', 'msg' => '请选择服务领域或文件领域');
             goto export;
         }
         $expired_time = date('Y-m-d H-i-s', time() + intval(C('TIME_LEFT')) * 24 * 3600);
         /* 计算失效时间 */
         /* 判断音频翻译是否填网址或者上传文件 */
         if ($product_type != 37) {
             if (empty($posts['save_path']) && !$posts['files_url']) {
                 $tips_msg = array('status' => '0', 'msg' => '请上传要翻译的文件');
                 goto export;
             }
         }
         /* 计算数量(千字/小时) */
         $qty = floatval($posts['qty']);
         $total_price = $qty * $product_info['price'];
         /* 计算总价 */
         $order_num = get_order_num(intval($shop_id), intval($member_id));
         // dump($address_path);die;
         $_POST = array('title' => $product_title, 'order_num' => $order_num, 'member_id' => $member_id, 'shop_id' => $posts['shop_id'], 'product_id' => $posts['product_id'], 'qty' => $qty, 'product_type' => $product_type, 'total_price' => $total_price, 'status' => '1', 'expired_time' => $expired_time, 'description' => $posts['description'], 'product_description' => json_encode($product_description), 'address_id' => $posts['address_id'], 'requirements' => $posts['language_sbt'], 'is_need_invoice' => $posts['need_invoice'], 'step' => 1, 'address_path' => $address_path, 'area_detail' => $area_detail, 'expected_start_time' => $posts['expected_start_time'], 'expected_end_time' => $posts['expected_end_time'], 'invoice' => $posts['invoice'], 'address_id' => $posts['address_id'], 'files_url' => $posts['files_url'], 'is_confirm_price' => '1');
         /* 开启事务 */
         $Model = M();
         $Model->startTrans();
         $result1 = update_data($this->table, $rules);
         if (is_numeric($result1)) {
             $_POST = array('order_id' => $result1, 'order_status' => 1, 'description' => '下单成功');
             $result2 = update_data($this->history_table);
             if (!empty($posts['save_path'])) {
                 /* 判断是否提交了文件 */
                 //multi_file_upload($posts['save_path'],'Uploads/UserFiles/'.$member_id,'files','order_id',$result1,'save_path');
                 $data_array = array();
                 foreach ($posts['save_path'] as $val) {
                     if (!empty(intval($val))) {
                         $data_array[$val] = array("title" => $posts["filename_" . $val], "order_id" => $result1, "member_id" => $member_id, "shop_id" => $posts['shop_id'], "description" => $posts['description']);
                     }
                 }
                 multi_file_uploads($posts['save_path'], 'Uploads/UserFiles/' . $member_id, 'files', $data_array, 'save_path');
             }
             /*发送订单消息*/
             $result3 = order_msg_send($member_id, $result1, $order_num, $shop_id);
             if (is_numeric($result1) && is_numeric($result2) && is_numeric($result3)) {
                 /*提交事务*/
                 $Model->commit();
                 /*@刘巧 给订单用户发送短信 */
                 $shop_info = get_info('shop', array('shop_id' => $posts['shop_id']), array('title'));
                 $content = C('ORDSUCCESS');
                 $content2 = C('MESSAGE_SHOP');
                 $content = str_replace("(0)", $total_price, $content);
                 //替换金额;
                 $content = str_replace("(1)", $shop_info['title'], $content);
                 //替换商家电铺字符串
                 $content2 = str_replace("(0)", $total_price, $content2);
                 //替换订单用户字符串
                 $content2 = str_replace("(2)", session('username'), $content2);
                 //替换订单用户字符串
                 $account = session('home_member_tel');
                 $stauts1 = send_code($content, $account);
                 /*@liuqiao 给商家用户发送短信*/
                 $stauts2 = send_code($content1, $account1);
                 $tips_msg = array('status' => '1', 'msg' => '下单成功', 'order_id' => $result1);
             } else {
                 /*事务回滚*/
                 $Model->rollback();
                 $tips_msg = array('status' => '0', 'msg' => '下单失败');
             }
         } else {
             $tips_msg = array('status' => '0', 'msg' => $result1);
         }
     } else {
         $tips_msg = array('status' => '0', 'msg' => '错误请求');
     }
     export:
     /*判断需要展示的web提示信息*/
     if ($tips_msg['status']) {
         $this->success($tips_msg['msg'], U('/Home/Buy/confirm_quote', array('order_id' => $tips_msg['order_id'])));
     } else {
         $this->error($tips_msg['msg']);
     }
 }
 public function index()
 {
     if (session('home_member_id')) {
         //判断用户是否已经登录,如果登录就不能再注册
         header("location:" . U("Home/Index/index"));
     } else {
         if (IS_POST) {
             //接收用户的传值
             $apptype = (!empty(I('post.apptype')) and I('post.apptype') == C('APP_KEY')) ? true : false;
             //手机app接口密钥
             //手机返回json数据
             if ($apptype) {
                 $ajax = true;
             } else {
                 $ajax = false;
             }
             $type = I('get.type');
             $telephone = I('telephone');
             $password = md5(md5(I('password')));
             //密码
             //$email = I('email');
             $confirmPassword = md5(md5(I('confirmPassword')));
             //	确认密码
             $code = I('code');
             //验证码
             $province = I('province');
             //省id
             $city = I('city');
             //市id
             if ($apptype) {
                 $member_id = intval(I('registerId'));
             } else {
                 $member_id = session('registerId');
             }
             //验证信息的合法性
             $rules = array(array('telephone', 'require', '请输入手机号'), array('password', 'require', '请输入密码!'));
             $is_telephone = 0;
             $is_email = 0;
             //验证手机号码合法性
             if (preg_match('/^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$/', $telephone)) {
                 $_POST['telephone'] = $telephone;
                 $is_telephone = 1;
                 $info = get_info('member', array('telephone' => $telephone, 'status' => 1, 'type' => array('GT', -2)));
                 if ($info) {
                     //如果手机号码被使用就删除这条记录
                     delete_data($this->table, array('id' => $member_id));
                     $this->error('手机号已被使用', '', $ajax);
                 }
             }
             /* if(preg_match("/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)){
             				$_POST['telephone']=$telephone;
             				$is_email=1;
             				
             				$info=get_info('member',array('telephone'=>$telephone,'status'=>1,'type'=>array('GT',-2)));
             				if($info){
             					$this->error('邮箱已被使用');
             				}
             			} */
             if ($is_telephone == 0) {
                 $this->error('请输入正确的手机号', '', $ajax);
             }
             /* if($is_email==0){
             				$this->error('请输入邮箱!');
             			} */
             //验证验证码的正确性
             //查询验证码
             $member_info = get_info($this->table, array('id' => $member_id, 'telephone' => $telephone));
             $member_code = $member_info['code'];
             if ($code != $member_code) {
                 $this->error('验证码不正确,请重新输入!', '', $ajax);
             }
             //组织填写member表中需要系统自动定义的字段????????????????????????????????
             //生成用户登录的code数字的形式存入到数据库中
             //$username = uniqid();//以微秒计数生成唯一的id
             if ($type == 1) {
                 $_POST['type'] = 1;
                 //表示普通用户
                 $_POST['role_id'] = 7;
             } else {
                 if ($type == 2) {
                     $_POST['type'] = 2;
                     //表示个人译者
                     $_POST['role_id'] = 8;
                 } else {
                     if ($type == 3) {
                         $_POST['type'] = 3;
                         //表示公司
                         $_POST['role_id'] = 9;
                     }
                 }
             }
             //将用户的信息存入到member表中
             $_POST['id'] = $member_id;
             //$_POST['type'] = 0;
             $_POST['password'] = $password;
             $_POST['confirmPassword'] = $confirmPassword;
             $_POST['username'] = $telephone;
             $_POST['integration'] = 100;
             $result = update_data($this->table, $rules);
             /*@刘巧将用户手机号作为昵称并隐藏4位*/
             $username = substr($telephone, 0, 5) . '****' . substr($telephone, 9);
             //将需要的信息存入到session中直接表示用户登录了
             if (is_numeric($result)) {
                 session('home_member_id', $result);
                 //将用户的id存入session值
                 session('nickname', $username);
                 //用户的昵称存入session值
                 session('points', 100);
                 //注册用户积分
                 session('home_member_tel', $telephone);
                 if ($apptype) {
                     $userinfo["home_member_id"] = $result;
                     //用户的id
                     $userinfo["nickname"] = $username;
                     //用户的昵称
                     $userinfo['balance'] = "0.00";
                     //账户余额
                     $userinfo['withdrawals'] = "0.00";
                     //可提现金额
                 }
                 //生成店铺信息
                 if ($type == 2) {
                     unset($_POST);
                     $_POST['type'] = 2;
                     //个人译者
                     $_POST['member_id'] = $result;
                     $_POST['status'] = 3;
                     $result = update_data($this->shop);
                     session('home_shop_id', $result);
                     session('nickname', $username);
                     //用户的昵称存入session值
                     session('home_member_tel', $telephone);
                     session('type', $type);
                     if ($apptype) {
                         $userinfo["home_shop_id"] = $result;
                         $userinfo["type"] = $type;
                     }
                 } else {
                     if ($type == 3) {
                         unset($_POST);
                         $_POST['type'] = 3;
                         //公司注册
                         $_POST['member_id'] = $result;
                         $_POST['status'] = 3;
                         //表示没有审核通过
                         $_POST['area_id'] = $city;
                         $result = update_data($this->shop);
                         session('nickname', $username);
                         //用户的昵称存入session值
                         session('home_member_tel', $telephone);
                         session('home_shop_id', $result);
                         session('type', $type);
                         if ($apptype) {
                             $userinfo["home_shop_id"] = $result;
                             $userinfo["type"] = $type;
                         }
                     }
                 }
                 //生成店铺日程信息,这个日程信息是初始化的日程信息
                 $sql = '';
                 for ($i = 1; $i <= 3; $i++) {
                     for ($s = 1; $s <= 7; $s++) {
                         $sql .= "insert into `sr_shop_time`(`shop_id`,`time`,`week`,`type`) values({$result},{$i},{$s},3);";
                     }
                 }
                 $Model = M();
                 $result2 = $Model->execute($sql);
                 if (is_numeric($result2)) {
                     if ($apptype) {
                         $data["status"] = "1";
                         $data["info"] = "注册成功!";
                         $data["userinfo"] = $userinfo;
                         $this->ajaxReturn($data);
                     } else {
                         if ($type == 1) {
                             $content = C('REGSUCCEESS');
                             $account = $I('telephone');
                             send_code($content, $account);
                             $this->success('注册成功!', U('Home/Index/index'));
                         } else {
                             $this->success('注册成功!', U('/User/StoreSetting/index'));
                         }
                     }
                 } else {
                     if ($apptype) {
                         $this->error($result2, '', $ajax);
                     } else {
                         $this->error($result2, U('Home/Index/index'));
                     }
                 }
             } else {
                 if ($apptype) {
                     $this->error($result, '', $ajax);
                 } else {
                     $this->error($result, U('Home/Index/index'));
                 }
             }
         } else {
             //查询地理信息
             $area_data = get_area_cache();
             //接收判断是哪一种注册
             $type = intval(I('type'));
             $data['area_data'] = $area_data;
             $data['type'] = $type;
             $this->assign($data);
             if (!empty($type)) {
                 $this->display('index_1_1');
             } else {
                 $this->display('index_1');
             }
         }
     }
 }
 /**
  *店铺管理
  *	个人译者和翻译公司的店铺管理有所不同,需要做一定的判断处理
  *流程分析
  *	1、店铺的申请
  *		按照用户登录的类型店铺的申请分为个人译者店铺的申请和翻译公司店铺的申请
  *			个人译者的店铺申请所上传的资料是身份证、学历证书、资质证书
  *			公司翻译的店铺申请所上传的资料是营业执照、税务登记、资质证书
  *	2、店铺的审核
  *		店铺上传资料之后就会由后台审核,审核的过程中商铺可以修改上传的资质
  *	3、店铺申请成功
  *		店铺申请成功之后店铺的资料只能修改店铺介绍
  *@author 刘浩 <qq:372980503>
  *@time   2015-07-20
  **/
 public function index()
 {
     if (IS_POST) {
         //不考虑app端的
         $posts = I("post.");
         //$type = session('type');
         //$shop_id = session('home_shop_id');
         //重新获取店铺信息
         $member_id = session("home_member_id");
         $info = get_info(D('ShopMemberView'), array("member.id" => $member_id));
         $type = $info["type"];
         $shop_id = $info["shop_id"];
         if ($type == 3 or $type == 2) {
             $_POST['id'] = $shop_id;
             if ($type == 3) {
                 $_POST['type'] = 2;
                 //翻译公司
                 $title_msg = "公司名称不能为空";
                 $content_msg = "公司介绍不能为空!";
                 $license_msg = "营业执照正面不能为空!";
                 $license_msg_1 = "营业执照反面不能为空!";
                 $tax_msg = "税务登记证不能为空!";
             } else {
                 if ($type == 2) {
                     $_POST['type'] = 1;
                     //个人译者
                     $title_msg = "店铺名称不能为空";
                     $content_msg = "店铺介绍不能为空!";
                     $license_msg = "身份证正面不能为空!";
                     $license_msg_1 = "身份证反面不能为空!";
                     $tax_msg = "学历证书不能为空!";
                 }
             }
             if (empty($shop_id)) {
                 $_POST["member_id"] = session("home_member_id");
             }
             $_POST['status'] = 0;
             //表示正在审核
             $_POST['operate_type1'] = $_POST['operate_type'];
             $_POST['operate_type'] = json_encode($_POST['operate_type']);
             $_POST['translate_type'] = json_encode($_POST['servece_type']);
             $_POST['description_now'] = htmlspecialchars($_POST['content']);
             //判断店铺名称是否重名
             if (!empty($_POST['title'])) {
                 if ($shop_id) {
                     $map = array("title" => array("eq", $_POST['title']), "id" => array("neq", $shop_id));
                 } else {
                     $map = array("title" => array("eq", $_POST['title']));
                 }
                 $match_result = get_info($this->table, $map);
                 if ($match_result) {
                     $this->error('店铺名称已经被占用,请重新取名!!');
                 }
             }
             //判断店铺是否已审核通过
             //$info = get_info($this->table,array("id"=>$shop_id));
             if ($info['shop_status'] == 1) {
                 $this->error('您的店铺已经审核通过,不可再次修改!');
             } else {
                 if ($info['shop_status'] == 2) {
                     $this->error('您的店铺已被冻结,无法进行修改!');
                 }
             }
             //验证资质证书
             if (empty($_POST["image1"]) and empty($_POST["image"])) {
                 $_POST["images"] = "";
             } else {
                 $_POST["images"] = 1;
             }
             //验证信息的正确性
             $rules = array(array('title', 'require', $title_msg, 1), array('operate_type1', 'checkArray', '业务范围不能为空', 1, 'function'), array('servece_type', 'checkArray', '服务类别不能为空', 1, 'function'), array('translate_num', 'require', '日翻译量不能为空', 1), array('translate_year', 'require', '翻译年限不能为空!', 1), array('translate_year', 'number', '翻译年限必须为数字!'), array('shop_license', 'require', $license_msg, 1), array('shop_license_1', 'require', $license_msg_1, 1), array('shop_tax', 'require', $tax_msg, 1), array('images', 'require', '翻译资质证书不能为空', 1), array('content', 'require', $content_msg));
             /*@刘巧 判断用户店铺名是否符合规范*/
             $_POST['title'] = get_word_search($_POST['title']);
             //组织上传信息
             /* unset($_POST);
             			$_POST = array(
             				'id'=>$shop_id,
             				'title'=>$parameters['title'],
             				'type'=>$type,
             				'short_description'=>$parameters['content'],
             				'status'=>3,
             				'operate_type'=>json_encode($parameters['operate_type']),
             				'translate_type'=>json_encode($parameters['servece_type']),
             				'translate_year'=>$parameters['translate_year'],
             				'traslate_num'=>$parameters['translate_num'],
             			); */
             $result = update_data($this->table, $rules);
             if (is_numeric($result)) {
                 //将店铺的营业执照存入对应的文件夹,对应的字段
                 if (is_numeric($posts['shop_license'])) {
                     multi_file_upload($posts['shop_license'], 'Uploads/Shop/license', $this->table, 'id', $result, 'shop_license');
                 }
                 if (is_numeric($posts['shop_license_1'])) {
                     multi_file_upload($posts['shop_license_1'], 'Uploads/Shop/license', $this->table, 'id', $result, 'shop_license_1');
                 }
                 //将店铺的税务登记证或者是个人译者的学历证书图片存入之地呢的文件夹和对应的字段
                 if (is_numeric($posts['shop_tax'])) {
                     multi_file_upload($posts['shop_tax'], 'Uploads/Shop/license', $this->table, 'id', $result, 'shop_tax');
                 }
                 //将店铺的翻译资质存入到shop_image
                 if ($posts['image']) {
                     multi_file_upload(array_unique($posts['image']), 'Uploads/Shop/license', $this->shop_image, 'shop_id', $result, 'image');
                 }
                 $content = C('SHOPZILIAO');
                 $account = session('home_member_tel');
                 $status = send_code($content, $account);
                 $this->success('提交成功');
             } else {
                 $this->error($result);
             }
         } else {
             $this->error("您还未开店或者不是公司账号");
         }
     } else {
         $member_id = session('home_member_id');
         //获取业务范围缓存
         $operate_type = get_operate_cache();
         //指的是翻译、审稿、校对、母语审稿、同声传译、陪同翻译
         //定义服务类别
         $servece_type = array('中译外', '外译外', '外译中');
         //这个是固定的,后台不能做出修改的
         //判断用户是否开店
         //使用member_id查找店铺列表中是否存在status是1或3的店铺,如果没有就显示让其上传资料,上传资料的时候分为两种一种是翻译公司一种是个人译者
         //如果是开店的就显示其上传的认证信息
         //如果是没有开店的就显示店铺申请的信息
         $info = get_info(D('MemberShopView'), array('shop.member_id' => $member_id));
         $data['operate_type'] = $operate_type;
         $data['servece_type'] = $servece_type;
         if ($info) {
             //开了店的或者是正在审核中的店铺
             $info['operate_type'] = json_decode($info['operate_type']);
             $info['translate_type'] = json_decode($info['translate_type']);
             $data['info'] = $info;
             //获取资质证书
             $shop_image = get_result("shop_image", array("shop_id" => $info["shop_id"]));
             $data['shop_image'] = $shop_image;
             $this->assign($data);
             if ($info['shop_status'] == 1 or $info['shop_status'] == 2) {
                 //表示店铺审核通过或冻结
                 $this->display('index2');
             } else {
                 //表示店铺正在审核的
                 $this->display('index');
             }
         } else {
             if (session("type") < 2) {
                 $this->redirect('User/Index/index');
             } else {
                 $this->assign($data);
                 $this->display('index');
             }
         }
         /* $ParameterArray['data']['operate_type'] = $operate_type;
         			$ParameterArray['data']['servece_type'] = $servece_type;
         			$this->ReturnParameter($ParameterArray); */
     }
 }