cancel.php 3.27 KB
<?php
set_time_limit(0);
require_once '../QINSBootstrap/Bootstrap.php';

        $time = time() - 8 * 84600;
        $time1 = date("Ymd", $time);
      //  $time1 = "20140911";
        $list = YHMOrders_Models_Status_Client::getOrderStatusByTime($time1, 100);
        foreach ($list as $k => $order_info) {
            $orderGoodsList = YHMOrders_Models_Orders_Client::getGoodsInfoByOrderCode($order_info['order_code']);
            //目前一个订单只有一个商品,所以取出一条数据
            $order_goods = current($orderGoodsList);
            if (isset($order_goods['goods_name'])&&($order_goods['goods_name']!=""))
            {
            //images
            $txt = "http://yhfair-product.qiniudn.com/";
            $txt = str_replace($txt, "", $order_goods['goods_images']);
            $arr = explode("?", $txt);
            $goods_image = $arr[0];

            $message = new YHMIm_MessagesParam_YHMOrderStatus;
            $message->text = '由于您没有及时付款,交易已经关闭。';
            $message->seller_uid = $order_info['buyer_uid'];
            $message->product_skc = $order_goods['product_skc'];
            $message->product_name = $order_goods['goods_name'];
            $message->image_url = YHMUpload_Images::template($goods_image, 'yhfair-product');
            $message->sale_price = (int) $order_goods['last_price'];
            $message->stock_number = $order_goods['buy_number'];
            $message->size_name = !empty($order_goods['size_name']) ? $order_goods['size_name'] : '-';
            $message->order_code = $order_info['order_code'];
            $send = YHMIm_Client::yhmOrderStatus(0, $order_info['buyer_uid'], $message);
           cancel($order_info['order_code'],"SELLER_CANCEL_ORDER");
            YHMOrders_Models_Status_Client::setOrderstatus($order_info['order_code'], 910, $order_info['buyer_uid']);
            print_r($message);
            }
            //exit();
        }
   
    
    function cancel($order_code,$order_status)
    {
        $cancel = YHMOrders_Models_Orders_Client::updateOrderStatus($order_code, YHMConfig_Orderstatus::$order_status[$order_status]);
         
        if (empty($cancel)) {
            return self::result(400, '取消订单失败');
        }
        //还回库存
        $goodsList = YHMOrders_Models_Orders_Client::getGoodsByOrderCode($order_code);
        if (!empty($goodsList)) {
            foreach ($goodsList as $g) {
                $stockInfo = YHMProduct_Models_Stock_Client::getStockBySku($g['product_sku']);
                $curStockNum = $stockInfo['stock_number'] + $g['buy_number'];
                $ret = YHMProduct_Models_Stock_Client::updateNumberBySku($g['product_sku'], $curStockNum, $stockInfo['product_skc']);
                if (empty($ret)) {
                    return self::result(501, '还原库存失败');
                }
                // 同步索引
                try {
                    $syncParams = array(
                        'product_skc' => $stockInfo['product_skc'],
                        'stock_number' => $curStockNum
                    );
                    $syncProduct = new YHMSearch_Syncgoods ();
                    $syncProduct->sync($syncParams);
                } catch (Exception $e) {
                    
                }
            }
        }
    }