/**
  * 发布需求之前 验证是否符合发布需求
  * @param int $member_id
  */
 protected function auth_add_demand($member_id)
 {
     //检测需求未完成不能 在发布需求
     // 		$findDemand = $this->dao->where(array('member_id'=>$member_id,'status'=>0,'expire_time'=>array('gt',time())))->getField('id');
     // 		if($findDemand){
     // 			$this->jsonUtils->echo_json_msg(4, '您有一发布需求未完成,不能发布需求');exit();
     // 		}
     //72小时内只能取消3次需求
     $limit_time = time() - 72 * 60 * 60;
     $cancel_demand = $this->dao->where("member_id={$member_id} and status=2 and cancel_time>{$limit_time} and is_bidding > 0")->field('cancel_time,id')->order('cancel_time asc')->select();
     if ($cancel_demand === false) {
         $this->jsonUtils->echo_json_msg(4, '72小时限制查询出错');
         exit;
     } else {
         $num = count($cancel_demand);
         if ($num >= 3) {
             $last_cancel = $cancel_demand[0]['cancel_time'];
             $left_time = $last_cancel - $limit_time;
             if ($left_time > 0) {
                 $hour = floor($left_time / 3600);
                 $minute = floor(($left_time - 3600 * $hour) / 60);
                 //	$second = floor((($left_time-3600 * $hour) - 60 * $minute) % 60);
                 $result = $hour . '小时' . $minute . '分钟';
             }
             $str = "由于您72小时内已取消3次需求,于" . $result . "后可以再次发布需求";
             $this->jsonUtils->echo_json_msg(4, $str);
             exit;
         }
     }
     //订单最多能有5个为完成订单
     $order = MemberOrderController::getOrderWithoutDone($member_id);
     if (!$order) {
         $this->jsonUtils->echo_json_msg(4, '您已有5个未完成的订单,请完成后在继续下单');
         exit;
     }
     return true;
 }
 public function submit_order()
 {
     $member_session_id = $_POST['member_session_id'];
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     $merchant_id = isset($_POST['merchant_id']) ? htmlspecialchars($_POST['merchant_id']) : '';
     $order_time = isset($_POST['reach_time']) ? htmlspecialchars($_POST['reach_time']) : '';
     $cart_id = isset($_POST['cart_id']) ? htmlspecialchars($_POST['cart_id']) : '';
     $service_ids = isset($_POST['service_ids']) ? htmlspecialchars($_POST['service_ids']) : '';
     $member_remark = isset($_POST['remark']) ? htmlspecialchars($_POST['remark']) : '';
     if (empty($merchant_id)) {
         $this->jsonUtils->echo_json_msg(4, '商家ID为空...');
         exit;
     }
     if (empty($order_time)) {
         $this->jsonUtils->echo_json_msg(4, '到店时间为空...');
         exit;
     }
     if (empty($cart_id)) {
         $this->jsonUtils->echo_json_msg(4, '车id为空...');
         exit;
     }
     if (empty($service_ids)) {
         $this->jsonUtils->echo_json_msg(4, '请选择所需服务项目...');
         exit;
     }
     $unix_time = strtotime($order_time);
     if ($unix_time < time()) {
         $this->jsonUtils->echo_json_msg(4, '预约时间必须大于当前时间');
         exit;
     }
     $order = MemberOrderController::getOrderWithoutDone($member_id);
     if (!$order) {
         $this->jsonUtils->echo_json_msg(4, '您已有5个未完成的订单,请完成后在继续下单');
         exit;
     }
     $service = M("service");
     $order_no = time() . rand(1000, 9999);
     // 订单号
     $total_price = 0;
     $total_time = 0;
     $service_ids_arr = explode(',', $service_ids);
     if ($_FILES) {
         $f_arr = mul_upload('/UserService/', 1);
         if ($f_arr) {
             $d_data['pics'] = $f_arr;
         }
     } else {
         $d_data['pics'] = array();
     }
     foreach ($service_ids_arr as $key => $value) {
         $s_arr = $service->field("cat_id as id,price,name,timeout as time")->where("id={$value} and merchant_id = {$merchant_id}")->find();
         if ($s_arr) {
             $total_price = $total_price + $s_arr['price'];
             $total_time = $total_time + $s_arr['time'];
             $d_data['list'][$key] = $s_arr;
             $d_data['list'][$key]['is_server'] = 1;
             $service_name[] = $s_arr['name'];
         } else {
             $this->jsonUtils->echo_json_msg(4, '提交的服务项目有误');
             exit;
         }
     }
     $data['order_no'] = $order_no;
     $data['service_name'] = implode('、', $service_name);
     $data['status'] = 0;
     $data['merchant_id'] = $merchant_id;
     $data['member_id'] = $member_id;
     $data['type'] = 0;
     // 服务订单
     $data['goods_count'] = 1;
     $data['unit_price'] = $total_price;
     $data['total_price'] = $total_price;
     $data['total_time'] = $total_time;
     $data['sub_data'] = json_encode($d_data);
     $data['reach_time'] = $unix_time;
     $data['cart_id'] = $cart_id;
     $data['cart_data'] = MemberDemandController::getcart($cart_id);
     $data['addtime'] = time();
     $data['action_time'] = time();
     $data['member_remark'] = $member_remark;
     $data['merchant_remark'] = '';
     $result = $this->dao->add($data);
     if ($result) {
         $this->jsonUtils->echo_json_msg(0, '提交订单成功...');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '提交订单失败...');
         exit;
     }
 }