public function index()
 {
     $map = array();
     $param = array();
     $page = array('curpage' => I('get.p', 0), 'size' => 10);
     $order = " client_id desc ";
     $fields = " create_time ,update_time,user_id,client_id,client_secret,client_name,redirect_uri,grant_types,scope ";
     $result = apiCall(ClientsApi::QUERY, array($map, $page, $order, $fields, $param));
     ifFailedLogRecord($result, __FILE__ . __LINE__);
     if (!$result['status']) {
         $this->error($result['info']);
     }
     $this->assign("list", $result['info']['list']);
     $this->assign("show", $result['info']['show']);
     $this->display();
 }
 /**
  * TODO: 取消订单
  */
 public function cancelOrder()
 {
     //检测订单状态
     //订单状态只能为,
     $map = array('id' => I('get.id', 0));
     //假删除订单
     $result = apiCall(OrdersApi::PRETEND_DELETE, array($map));
     ifFailedLogRecord($result, __FILE__ . __LINE__);
     if (!$result['status']) {
         $this->error($result['info']);
     }
     $this->success("取消成功!");
 }
 /**
  * 获取订单
  * @param post.type 0=全部,1=待付款,2=待发货,3=待收货,4=待评论
  */
 public function orderlist()
 {
     $type = I('post.type', 0, 'intval');
     //是否获取物流信息
     $shouldGetExpressInfo = false;
     $map = array();
     if ($type == 1) {
         //待付款
         $map['pay_status'] = OrdersModel::ORDER_TOBE_PAID;
     } elseif ($type != 0) {
         //货到付款,在线已支付
         $map['pay_status'] = array('in', array(OrdersModel::ORDER_PAID, OrdersModel::ORDER_CASH_ON_DELIVERY));
     }
     if ($type == 2) {
         //1. 已支付、货到付款
         //2. 待发货
         //
         $map['order_status'] = OrdersModel::ORDER_TOBE_SHIPPED;
     } elseif ($type == 3) {
         //1. 已支付、货到付款
         //2. 已发货
         $map['order_status'] = OrdersModel::ORDER_SHIPPED;
         $shouldGetExpressInfo = true;
     } elseif ($type == 4) {
         //1. 已支付、货到付款
         //2. 已收货
         //3. 待评论
         $map['order_status'] = OrdersModel::ORDER_RECEIPT_OF_GOODS;
         $map['comment_status'] = OrdersModel::ORDER_TOBE_EVALUATE;
         $shouldGetExpressInfo = true;
     }
     $map['wxuser_id'] = $this->userinfo['id'];
     //TODO: 订单假删除时不查询
     $map['status'] = 1;
     $orders = " createtime desc ";
     $page = array('curpage' => I('post.p', 0), 'size' => 3);
     $result = apiCall(OrdersApi::QUERY, array($map, $page, $orders));
     ifFailedLogRecord($result, __FILE__ . __LINE__);
     //1. 订单信息
     $order_list = $result['info']['list'];
     $store_ids = array();
     $order_ids = array();
     $result_list = array();
     $store_key = array();
     foreach ($order_list as $vo) {
         $entity = array('orderid' => $vo['id'], 'price' => number_format($vo['price'] / 100.0, 2), 'storeid' => $vo['storeid'], 'order_status' => $vo['order_status'], 'comment_status' => $vo['comment_status'], 'order_status_desc' => getTaobaoOrderStatus($vo['order_status']), 'pay_status' => $vo['pay_status'], '_items' => array(), '_store' => array());
         $result_list[$vo['id']] = $entity;
         if (!array_key_exists($vo['storeid'], $store_key)) {
             array_push($store_ids, $vo['storeid']);
             $store_key[$vo['storeid']] = $vo['storeid'];
         }
         array_push($order_ids, $vo['id']);
     }
     if (count($store_ids) > 0) {
         $mapStore = array();
         $mapStore['id'] = array('in', $store_ids);
         //2. 获取店铺信息
         $result = apiCall(StoreApi::QUERY_NO_PAGING, array($mapStore));
         ifFailedLogRecord($result, __FILE__ . __LINE__);
         foreach ($result_list as &$vo_obj) {
             foreach ($result['info'] as $vo) {
                 if ($vo['id'] == $vo_obj['storeid']) {
                     $vo_obj['_store'] = $vo;
                     break;
                 }
             }
         }
     }
     //3. 获取订单商品信息
     if (count($store_ids) > 0) {
         $mapOrder = array();
         $mapOrder['orders_id'] = array('in', $order_ids);
         $result = apiCall(OrdersItemApi::QUERY_NO_PAGING, array($mapOrder));
         ifFailedLogRecord($result, __FILE__ . __LINE__);
         foreach ($result['info'] as $vo) {
             $entity = array('name' => $vo['name'], 'p_id' => $vo['p_id'], 'img' => $vo['img'], 'price' => number_format($vo['price'] / 100.0, 2), 'ori_price' => number_format($vo['ori_price'] / 100.0, 2), 'sku_id' => $vo['sku_id'], 'sku_desc' => $vo['sku_desc'], 'count' => $vo['count'], 'orders_id' => $vo['orders_id'], 'createtime' => date("Y-m-d H:i:s", $vo['createtime']));
             if (isset($result_list[$vo['orders_id']])) {
                 array_push($result_list[$vo['orders_id']]['_items'], $entity);
             }
         }
     }
     if (IS_POST) {
         //dump($result_list);
         $this->success($result_list);
     } else {
         $this->error("禁止访问!");
     }
 }
 /**
  * 单个发货操作
  */
 public function deliver()
 {
     $expresslist = C("CFG_EXPRESS");
     if (IS_GET) {
         $id = I('get.id', 0);
         $map = array('id' => $id);
         $result = apiCall(OrdersInfoViewApi::GET_INFO, array($map));
         if ($result['status']) {
             $this->assign("order", $result['info']);
         } else {
             $this->error("订单信息获取失败!");
         }
         $map = array('orderid' => $result['info']['orderid']);
         $result = apiCall(OrdersExpressApi::GET_INFO, array($map));
         if ($result['status'] && is_array($result['info'])) {
             $this->assign("express", $result['info']);
         }
         $this->assign("expresslist", $expresslist);
         $this->display();
     } elseif (IS_POST) {
         $expresscode = I('post.expresscode', '');
         $expressno = I('post.expressno', '');
         $wxuserid = I('post.wxuserid', 0);
         $orderid = I('post.orderid', '');
         $orderOfid = I('post.orderOfid', '');
         if (empty($expresscode) || !isset($expresslist[$expresscode])) {
             $this->error("快递信息错误!");
         }
         if (empty($expressno)) {
             $this->error("快递单号不能为空");
         }
         $id = I('post.id', 0);
         $entity = array('expresscode' => $expresscode, 'expressname' => $expresslist[$expresscode], 'expressno' => $expressno, 'note' => I('post.note', ''), 'orderid' => $orderid, 'wxuserid' => $wxuserid);
         if (empty($entity['orderid'])) {
             $this->error("订单编号不能为空");
         }
         if (empty($id) || $id <= 0) {
             $result = apiCall(OrdersExpressApi::ADD, array($entity));
         } else {
             $result = apiCall(OrdersExpressApi::SAVE_BY_ID, array($id, $entity));
         }
         if ($result['status']) {
             // 1. 修改订单状态为已发货
             //                $result = ServiceCall("Common/Order/shipped", array($orderOfid,false,UID));
             $result = apiCall(OrderStatusApi::SHIPPED, array($orderOfid, false, UID));
             if (!$result['status']) {
                 ifFailedLogRecord($result['info'], __FILE__ . __LINE__);
             }
             //TODO: 移动到消息模块处理
             //========================================
             $text = "亲,您订单({$orderid})已经发货,快递单号:{$expressno},快递公司:" . $expresslist[$expresscode] . ",请注意查收";
             // 2.发送提醒信息给指定用户
             $this->sendTextTo($wxuserid, $text);
             //========================================
             $this->success(L('RESULT_SUCCESS'), U('Admin/Orders/deliverGoods'));
         } else {
             $this->error($result['info']);
         }
     }
 }
 private function type2dtree($list)
 {
     $dtree_ids = array(-1);
     foreach ($list as $vo) {
         array_push($dtree_ids, $vo['dtree_account_type']);
     }
     $where = array('id' => array("in", $dtree_ids));
     $result = apiCall(DatatreeApi::QUERY_NO_PAGING, array($where));
     ifFailedLogRecord($result, __LINE__ . __LINE__);
     $dtree_type = $result['info'];
     foreach ($list as &$vo) {
         foreach ($dtree_type as $type) {
             if ($vo['dtree_account_type'] == $type['id']) {
                 $vo['_account_type'] = $type['name'];
             }
         }
     }
     return $list;
 }