<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id$
 */

if(!defined('__CORE_DIR')){
    exit("Access Denied");
}

class Mdl_Order_Order extends Mdl_Table
{   
  
    protected $_table = 'order';
    protected $_pk = 'order_id';
    protected $_cols = 'order_id,uid,all_price,pay_status,pay_time,order_status,clientip,dateline,service_time,service_mobile,service_addr,service_demand,aunt_id,js_price';
    
    public function allstatus(){
        return array(
            0 => '未确认',
            1 => '已审核',
            2 => '已接单',
            3 => '已完成',
            7 => '已确认',
            8 => '已取消',
            9 => '已拒绝',
        );
    }
    
     public function create($data)
    {

        if(!$uid = $data['uid']){
            return false;
        }else if(!$product_id = $data['product_id']){
            return false;
        }else if(!$all_price = $data['all_price']){
            return false;
        }else if(!$service_time = $data['service_time']){
            return false;
        }else if(!$service_mobile = $data['service_mobile']){
            return false;
        }else if(!$service_addr = $data['service_addr']){
            return false;
        }else if(!$service_demand = $data['service_demand']){
            return false;
        }
        
        
        if($data['order_status']){
            $order_status = $data['order_status'];
        }else{
            $order_status = 0;
        }
        
        if($data['lat']){
            $lat = $data['lat'];
        }else{
            $lat = '';
        }
        
        if($data['lng']){
            $lng = $data['lng'];
        }else{
            $lng = '';
        }


        $a = array('uid'=>$uid, 'product_id'=>$product_id,'all_price'=>$all_price,'service_time'=>$service_time,'service_mobile'=>$service_mobile,'service_addr'=>$service_addr,'service_demand'=>$service_demand,'order_status'=>$order_status,'lat'=>$lat,'lng'=>$lng);    

    	if(!$o = $this->insert($a, true)){
    		return false;
    	}

        return $o;
    }
    
    
    
     public function insert($data)
    {

        $data['clientip'] = $data['clientip'] ? $data['clientip'] : __IP;
        $data['dateline'] = $data['dateline'] ? $data['dateline'] :  __CFG::TIME;
        if($uid = $this->db->insert($this->_table, $data, true)){
            $this->db->Execute("INSERT INTO ".$this->table('member_fields')."(uid) VALUES('$uid')");
        }
        return $uid;
    }
    
      
    

    
    
}