Exemplo n.º 1
0
 public function secondComfirm()
 {
     error_reporting(-1);
     global $dbConn;
     $dataArr = $_POST['data'];
     $orderIdArr = array();
     $skuOrder = new PurchaseOrderAct();
     $tallyObj = new SkuAct();
     foreach ($dataArr as $item) {
         $onWayNum = $skuOrder->checkSkuOnWayNum($item['sku']);
         $tallyNum = $tallyObj->getTallySkuNum($item['sku']);
         //$nowNum = $onWayNum - $tallyNum;
         $nowNum = $onWayNum;
         if ($nowNum >= $item['qty']) {
             //var_dump($onWayNum,$item['qty'],$item['id']);
             //if($onWayNum >= $item['qty']){
             $orderIdArr[] = $item['unorderid'];
             $tallyObj->tallySkuRecord($item['sku'], $item['qty'], 1);
             $sql = "UPDATE `ph_sku_reach_record` SET status=2 where id={$item['id']}";
             $dbConn->execute($sql);
         }
     }
     $rtn = $this->setTallyIsUse($orderIdArr);
     $rtn = json_decode($rtn, true);
     if ($rtn['errCode'] == 0) {
         return 1;
     } else {
         return 0;
     }
 }
Exemplo n.º 2
0
 public function addUnStock()
 {
     global $dbconn;
     $sku = $_REQUEST["sku"];
     $amount = $_REQUEST["amount"];
     $sql = "select a.count ,a.stockqty,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.status=3 \n\t\t\t\tand a.sku='{$sku}'\n\t\t\t\torder by b.aduittime ASC\n\t\t\t";
     //查找在途订单sku 未到货的数量
     $sql = $dbconn->execute($sql);
     $skuInfoArr = $dbconn->getResultArray($sql);
     $now = time();
     $flag = array();
     $skuObj = new SkuAct();
     $skuObj->tallySkuRecord($sku, $amount, 2);
     foreach ($skuInfoArr as $item) {
         if ($amount <= 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},ungoodqty=ungoodqty+{$nowNeedAmount},reach_time={$now} where id={$item['detail_id']}";
         $sql = "update ph_order_detail set ungoodqty=ungoodqty+{$nowNeedAmount},reach_time={$now} where id={$item['detail_id']}";
         if ($dbconn->execute($sql)) {
             //写入批次到货记录表
             if ($nowNeedAmount > 0) {
                 $sql = "INSERT INTO `ph_order_arrive_log`(`ordersn`, `sku`, `amount`, `arrive_time`) VALUES ('{$item['recordnumber']}','{$item['sku']}',{$nowNeedAmount},{$now})";
                 $dbconn->execute($sql);
             }
             $this->checkOrderFinish($item["id"]);
         } else {
             //如果入库不成功
             $flag[] = 0;
         }
     }
     if (in_array(0, $flag)) {
         //插入数据不成功
         $data["errorCode"] = 500;
         $data["msg"] = "部分数据插入失败";
     } else {
         $data["errorCode"] = 0;
         $data["msg"] = "success";
     }
     return json_encode($data);
 }