public function cancelOrderByOrderId($orderId, $must = false, $cancelUserid = 0)
 {
     $rs = $this->getOrderInfoById($orderId, true);
     if (!$rs) {
         return array('status' => 0, 'info' => '订单不存在');
     }
     if (!$must && !in_array($rs['status'], array(0, 1, 12))) {
         return array('status' => 0, 'info' => '订单状态不可取消');
     }
     //返还扣除的结邻币
     if ($rs['credit_offset'] > 0) {
         D('member')->setUserScore(array('uid' => $rs['uid'], 'act' => 1, 'credit' => $rs['credit_offset'] * 100, 'event' => 1, 'fid' => $orderId, 'content' => '小管家配送取消订单,订单号:' . $rs['order_sn']), 'shopping');
     }
     //退还已使用的抵价券
     if ($rs['coupon_offset'] > 0) {
         D('steCoupon')->cancelCoupon($rs['order_sn'], $rs['uid']);
     }
     //处理库存和店铺销量
     //        $shopGoodsSales = array();
     $goodsList = array();
     foreach ($rs['items'] as $val) {
         $goodsList[] = array('gid' => $val['gid'], 'goods_sn' => $val['goods_sn'], 'goods_name' => $val['goods_name'], 'goods_spec' => $val['goods_spec'], 'goods_counts' => $val['goods_counts'], 'goods_price' => $val['goods_price'], 'credits' => $val['credits']);
         M('ste_goods')->update('sale_counts=sale_counts-' . $val['goods_counts'] . ',storage_counts=storage_counts+' . $val['goods_counts'], array('gid' => $val['gid']));
         //            if (!isset($shopGoodsSales[$val['shop_id']])) {
         //                $shopGoodsSales[$val['shop_id']] = $val['goods_counts'];
         //            } else {
         //                $shopGoodsSales[$val['shop_id']]+=$val['goods_counts'];
         //            }
     }
     //更新店铺产品销量
     //        if ($shopGoodsSales) {
     //            foreach ($shopGoodsSales as $key => $val) {
     //                M('ste_shop')->update('goods_sales=goods_sales-' . $val, array('shop_id' => $key));
     //            }
     //        }
     //如果订单已付款,则添加退款申请
     if ($rs['pay_amount'] > 0) {
         $refund = array('cancel_userid' => $cancelUserid, 'order_id' => $rs['order_id'], 'buyer_id' => $rs['uid'], 'refund_info' => json_encode($goodsList), 'refund_shipping' => $rs['shipping_fee'], 'refund_note' => '', 'refund_time' => TIME, 'refund_amount' => $rs['pay_amount']);
         //            $refund['refund_amount']+=$rs['shipping_fee'];
         D('steOrderRefund')->addOrderRefund($refund);
         //发送申请退款成功的短信
         $objData = array('sms' => array('phone' => $rs['phone'], 'content' => array('order_sn' => $rs['order_sn'], 'type' => '全额'), 'tplId' => 804919));
         asynHttp('msg', $objData);
     }
     //修改订单状态
     $this->update(array('status' => 2), array('order_id' => $orderId));
     return array('status' => 1, 'info' => 'ok');
 }
 public function setUserDetail($objData)
 {
     $hasAvatar = $objData['headimgurl'];
     //如果存在unionid则处理unionid
     if (isHave($objData['unionid'])) {
         M('user_bind')->update(array('unionid' => $objData['unionid']), array('uid' => $objData['uid']));
     }
     $objData = array('uid' => $objData['uid'], 'subscribe' => isset($objData['subscribe']) ? $objData['subscribe'] : '', 'nickname' => isset($objData['nickname']) ? trim(preg_replace('~\\xEE[\\x80-\\xBF][\\x80-\\xBF]|\\xEF[\\x81-\\x83][\\x80-\\xBF]~', '', $objData['nickname'])) : '', 'sex' => isset($objData['sex']) ? $objData['sex'] : '', 'city' => isset($objData['city']) ? $objData['city'] : '', 'country' => isset($objData['country']) ? $objData['country'] : '', 'province' => isset($objData['province']) ? $objData['province'] : '', 'language' => isset($objData['language']) ? $objData['language'] : '', 'subscribe_time' => isset($objData['subscribe_time']) ? $objData['subscribe_time'] : '');
     //uid不正确,不保存信息
     if (!$objData['uid']) {
         return false;
     }
     //用户未关注,不保存信息
     if (!$objData['subscribe']) {
         return false;
     }
     if ($this->getUserDetailByUid($objData['uid'])) {
         $updateData = $objData;
         unset($updateData['uid']);
         M('user_detail')->update($updateData, array('uid' => $objData['uid']));
     } else {
         M('user_detail')->insert($objData);
     }
     $update = array('nickname' => $objData['nickname'], 'sex' => $objData['sex']);
     //异步获取用户头像
     if ($hasAvatar) {
         asynHttp('avatar', array('uid' => $objData['uid'], 'imgUrl' => $hasAvatar));
     }
     $this->update($update, array('uid' => $objData['uid']));
     return true;
 }