onlineUserId = $onlineUserId; $this->onlineEnterpriseId = $onlineEnterpriseId; $this->objDPurchaseOutGoods = new DPurchaseOutGoods('stock'); $this->objDPurchaseOutGoods->setTable($this->objDPurchaseOutGoods->get_Table() . '_' . $this->onlineEnterpriseId); } /** * 添加采购商品信息 * @param $params * @return ResultWrapper */ public function addPurchaseGoods($params) { $dbResult = $this->objDPurchaseOutGoods->insert($params,true); if ($dbResult === false) { $this->objDPurchaseOutGoods->rollBack(); return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * @param $params * @param $purchaseId * @param $deleteArray * @return ResultWrapper */ public function editPurchaseOutGoods($params,$purchaseId, $deleteArray) { foreach ($params as $key => $val) { if (isset($val['id'])) { $id = $val['id']; unset($val['id']); $dbResult = $this->objDPurchaseOutGoods->update($val, $id); if($dbResult === false){ return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror); } } else { $val['purchaseOutId'] = $purchaseId; $insert[] = $val; } } if(!empty($deleteArray)){ $dbResult = $this->objDPurchaseOutGoods->update(['deleteStatus' => StatusCode::$delete], ['id' => $deleteArray]); if($dbResult === false){ return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror); } } if (!empty($insert)) { $dbResult = $this->objDPurchaseOutGoods->insert($insert, true); if ($dbResult === false) { return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror); } } return ResultWrapper::success(true); } /** * 通过采购退货单id获取采购单下的商品 * @param $ids * @return ResultWrapper */ public function getGoodsByPurchaseIds($ids) { $dbResult = $this->objDPurchaseOutGoods->select(['purchaseId'=>$ids]); if ($dbResult === false) { $this->objDPurchaseOutGoods->rollBack(); return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror); } return ResultWrapper::success(self::formatJson($dbResult)); } /** * @param $data * @return mixed */ public function formatJson($data) { if (isset($data['id'])) { $data['unit'] = empty($data['unit']) ? '' : json_decode($data['unit'], true); return $data; } foreach ($data as &$v) { $v['unit'] = empty($v['unit']) ? '' : json_decode($v['unit'],true); } return $data; } }