Beispiel #1
0
function exportOrder($data)
{
    global $dbConn;
    $num = 0;
    foreach ($data as $id) {
        $sql = "SELECT a.addtime, a.recordnumber, a.partner_id, a.purchaseuser_id, b.sku, b.price, b.count,b.stockqty  FROM ph_order as a ";
        $sql .= " JOIN ph_order_detail as b ON a.id = b.po_id WHERE a.id = '{$id}' AND a.is_delete = 0 AND b.is_delete = 0 ";
        $query = $dbConn->query($sql);
        $datalist = array();
        if ($query) {
            $rtnData = $dbConn->fetch_array_all($query);
            if (!empty($rtnData)) {
                $ii = 0;
                foreach ($rtnData as $k => $v) {
                    $addtime = $v['addtime'];
                    $recordnumber = $v['recordnumber'];
                    $parid = $v['partner_id'];
                    $purid = $v['purchaseuser_id'];
                    $price = $v['price'];
                    $count = $v['count'];
                    $sku = $v['sku'];
                    $stockqty = $v['stockqty'];
                    $skuinfo = getSkuById($sku);
                    $name = $skuinfo[0]['goodsName'];
                    //$parname      = getParNameById($parid);
                    $parname = getPartnerBySku($sku);
                    $purname = getNameById($purid);
                    $datalist[$ii]['addtime'] = $addtime;
                    $datalist[$ii]['recordnumber'] = $recordnumber;
                    $datalist[$ii]['parname'] = $parname;
                    $datalist[$ii]['purname'] = $purname;
                    $datalist[$ii]['sku'] = $sku;
                    $datalist[$ii]['name'] = $name;
                    $datalist[$ii]['price'] = $price;
                    $datalist[$ii]['count'] = $count;
                    $datalist[$ii]['stockqty'] = $stockqty;
                    $datalist[$ii]['totalmoney'] = $price * $count;
                    $ii++;
                }
                $dataArr[$num] = $datalist;
                $num++;
            }
        }
    }
    return $dataArr;
}
Beispiel #2
0
<?php

include "config.php";
include "/data/web/purchase.valsun.cn/lib/functions.php";
$sql = "select sku,purchaseId from pc_goods  order by rand() limit 500 ";
$sql = $dbconn->execute($sql);
$skuInfo = $dbconn->getResultArray($sql);
foreach ($skuInfo as $item) {
    $sku = $item["sku"];
    $amount = rand(1, 200);
    $purchaseId = $item["purchaseId"];
    $partnerName = getPartnerBySku($sku);
    $tallymanId = rand(200, 300);
    $now = time();
    $note = "异常到货数量{$amount}个";
    $sql = "INSERT INTO `ph_sku_reach_record`(`sku`, `purchaseId`, `amount`,tallymanId,note,addtime,partnerName) VALUES ('{$sku}',{$purchaseId},{$amount},{$tallymanId},'{$note}',{$now},'{$partnerName}')";
    if ($dbconn->execute($sql)) {
        echo "添加数据成功。。。。\n";
    }
}
Beispiel #3
0
 public function addStock()
 {
     error_reporting(0);
     global $dbconn, $rmqObj;
     $sku = $_REQUEST["sku"];
     $amount = $_REQUEST["amount"];
     $totalAmount = $amount;
     $intime = $_REQUEST["intime"];
     $key = trim($_REQUEST["key"]);
     if (empty($key)) {
         $data["errorCode"] = 501;
         $data["msg"] = "传过来的参数缺少key";
         return json_encode($data);
     } else {
         $number = $this->check_instock($key);
         if ($number > 0) {
             $data["errorCode"] = 0;
             $data["msg"] = "这个key的上架已经匹配过采购订单";
             //return json_encode($data);
         }
     }
     //$this->trigger_list($sku,$amount);
     $sql = "select a.count ,a.stockqty,a.price,a.id as detail_id,a.sku, b.recordnumber,b.id from ph_order_detail as a left join ph_order as b on a.po_id=b.id where a.is_delete=0\n\t\t\t\tand b.is_delete=0\n\t\t\t\tand b.status=3 \n\t\t\t\tand a.sku='{$sku}'\n\t\t\t\torder by b.id ASC\n\t\t\t";
     //查找在途订单sku 未到货的数量
     $sql = $dbconn->execute($sql);
     $skuInfoArr = $dbconn->getResultArray($sql);
     $now = time();
     $flag = array();
     foreach ($skuInfoArr as $item) {
         if ($amount <= 0 || $item["count"] <= 0) {
             //匹配完成 跳出
             break;
         }
         $unArriveNum = $item["count"] - $item["stockqty"];
         if ($unArriveNum <= $amount) {
             //订单的数量小于等于入库数量
             $nowNeedAmount = $unArriveNum;
         } else {
             $nowNeedAmount = $amount;
         }
         $amount = $amount - $nowNeedAmount;
         //入库后剩余数量
         $sql = "update ph_order_detail set stockqty=stockqty+{$nowNeedAmount} ,reach_time={$now} where id={$item['detail_id']}";
         if ($dbconn->execute($sql)) {
             //写入批次到货记录表
             // 发送消息队列 重新计算 成本核算价
             $publish_data = array();
             $publish_data['type'] = "updatePrice";
             $publish_data['totalNum'] = $totalAmount;
             $publish_data['number'] = $nowNeedAmount;
             $publish_data['price'] = $item['price'];
             $publish_data['sku'] = $sku;
             $publish_data['intime'] = $intime;
             $this->publish_msg($publish_data);
             if ($nowNeedAmount > 0) {
                 $sql = "INSERT INTO `ph_order_arrive_log`(`ordersn`, `sku`, `amount`, `arrive_time`,keyWord) VALUES ('{$item['recordnumber']}','{$item['sku']}',{$nowNeedAmount},{$now},'{$key}')";
                 $dbconn->execute($sql);
             }
             $this->checkOrderFinish($item["id"]);
         } else {
             //如果入库不成功
             $flag[] = 0;
         }
     }
     if (in_array(0, $flag)) {
         //插入数据不成功
         $data["errorCode"] = 500;
         //$data["msg"] = "部分数据插入失败";
         $data["msg"] = $amount;
     } else {
         $data["errorCode"] = 0;
         //$data["msg"] = "success";
         $data["msg"] = $amount;
     }
     $log = "sku : {$sku}; 上架的总数:{$totalAmount};匹配采购订单后剩余的数量:{$amount},key:{$key}";
     $note = "sku : {$sku}; 上架的总数:{$totalAmount};匹配采购订单后剩余的数量:{$amount}";
     $remain = $amount;
     $partnerName = getPartnerBySku($sku);
     $user = getUserIdBySku($sku);
     $purchaseId = $user["purchaseId"];
     $now = time();
     if ($amount == $totalAmount) {
         $sql = "INSERT INTO `ph_order_arrive_log`(sku,`arrive_time`,keyWord) VALUES ('{$item['sku']}',{$now},'{$key}')";
         $dbconn->execute($sql);
     }
     if ($amount > 0) {
         $sql = "INSERT INTO ph_sku_reach_record(sku,purchaseId,amount,totalAmount,note,addtime,partnerName) VALUES \n\t\t\t\t('{$sku}','{$purchaseId}',{$remain},{$totalAmount},'{$note}',{$now},'{$partnerName}')";
         write_log("inStock_new.txt", $sql);
         $dbconn->execute($sql);
     }
     return json_encode($data);
 }
Beispiel #4
0
 public function addSkuReach()
 {
     global $dbconn;
     $orderArr = $_POST["orderArr"];
     $orderArr = json_decode($orderArr, true);
     $now = time();
     $sql = "INSERT INTO ph_sku_reach_record(sku,purchaseId, amount, totalAmount,tallymanId,note,addtime,partnerName,unOrderId) VALUES ";
     $sqlarr = array();
     $rollback = false;
     $purchaseOrder = new PurchaseOrderAct();
     foreach ($orderArr as $orderItem) {
         $sku = $orderItem["sku"];
         $amount = $orderItem["amount"];
         $unOrderId = $orderItem["orderid"];
         $user = getUserIdBySku($sku);
         $purchaseId = $user["purchaseId"];
         $partnerName = getPartnerBySku($sku);
         $tallymanId = $orderItem["tallymanId"];
         $onWayNum = $purchaseOrder->checkSkuOnWayNum($sku);
         //在途数量
         //$tallyAmount 	= $this->getTallySkuNum($sku); //已经点货的数量
         //$nowUnReach 	= $onWayNum - $tallyAmount;
         $unSkuNum = $amount - $onWayNum;
         $note = "当时的在途数量是{$onWayNum}个,总共到货数量{$amount}个,异常到货数量{$unSkuNum}个";
         $sqlarr[] = " ('{$sku}','{$purchaseId}',{$unSkuNum},{$amount},'{$tallymanId}','{$note}',{$now},'{$partnerName}',{$unOrderId}) ";
     }
     $sqlStr = implode(",", $sqlarr);
     $sql .= $sqlStr;
     if ($dbconn->execute($sql)) {
         $rtn["msg"] = "添加数据成功";
         $rtn["errCode"] = 0;
     } else {
         $rtn["msg"] = "添加数据成功";
         $rtn["errCode"] = 0;
     }
     return json_encode($rtn);
 }