Example #1
0
 /**
  * 提交订单
  */
 public function goAction()
 {
     if (ComTool::isAjax()) {
         if (!$this->isLogin()) {
             ComTool::ajax(Cola::getConfig('_error.mustlogin'), '请先登录,即将跳转至登录页面');
         }
         $mobile = trim($this->post('mobile'));
         ComTool::checkEmpty($mobile, '请填写常用手机号');
         if (!ComTool::isMobile($mobile)) {
             ComTool::ajax(100001, '请填写正确的手机号');
         }
         $receiver = $this->post('receiver', '');
         ComTool::checkMaxLen($receiver, 16, "收货人姓名最多16位");
         $addrDesc = $this->post('addr_desc', '');
         ComTool::checkMaxLen($addrDesc, 32, "详细位置最多32位");
         $message = trim($this->post('message', ''));
         ComTool::checkMaxLen($message, 100, "留言最多100字");
         $curCategory = $this->post('cate', 0);
         $curCategory = intval(base64_decode($curCategory));
         if (!isset($_SESSION['cart'][$curCategory])) {
             ComTool::ajax(100001, '购物车为空');
         }
         $cart = $this->getCart($curCategory);
         if (!$cart) {
             ComTool::ajax(100001, '购物车为空');
         }
         $groupName = $this->post('group', '');
         if (!$groupName) {
             $category = CategoryData::getById($curCategory);
             $group = GroupData::getById($category['group_id']);
             $groupName = $group['name'];
         } else {
             $groupName = base64_decode($groupName);
         }
         $currUser = $this->getCurrentUser();
         $data = array();
         $orderId = ComTool::getOrderId();
         $data['id'] = $orderId;
         $data['user_id'] = $currUser['id'];
         $data['category_id'] = $curCategory;
         $data['user_name'] = $receiver;
         $data['user_tel'] = $mobile;
         $data['user_addr'] = "{$groupName} {$addrDesc}";
         $data['message'] = $message;
         $data['create_time'] = $data['update_time'] = time();
         $data['create_date'] = date("Y-m-d");
         $data['total_cost'] = $cart['totalPrice'];
         $data['status'] = '1';
         $res = OrderData::add($data);
         if ($res === false) {
             ComTool::ajax(100001, '服务器忙,请重试');
         }
         $sql = "insert into order_detail(order_id,good_id,good_name,amount,`price`,price_desc,`status`) values";
         foreach ($cart['products'] as $product) {
             $sql .= "('{$orderId}','{$product['id']}','{$product['name']}','{$product['quantity']}','{$product['price']}','{$product['price']}({$product['price_num']}{$product['price_unit']})','1'),";
         }
         $sql = trim($sql, ',');
         $res = OrderData::sql($sql);
         if ($res === false) {
             ComTool::ajax(100001, '服务器忙,请重试');
         }
         //TODO 清除此分类购物车的session
         ComTool::ajax(100000, 'ok');
     }
 }