isUpdateBasicCache) { return false; } $sql = "SELECT c.title as categoryName,b.*,d.title as brandName FROM qianniao_goods_basic_" . $this->onlineEnterpriseId . " as b LEFT JOIN qianniao_goods_category_" . $this->onlineEnterpriseId . " as c ON c.id=b.categoryId LEFT JOIN qianniao_goods_brand_" . $this->onlineEnterpriseId . " as d ON b.brandId=d.id WHERE b.id = " . $this->objectId; $goodsBasicResult = $this->objDGoodsBasic->query($sql); if ($goodsBasicResult === false) { file_put_contents('/www/wwwroot/logs/api.junhailan.com/BasicAndSkuCache_error.log', date('Y-m-d H:i:s') . '错误|sql: ' . $this->objDGoodsBasic->error() . PHP_EOL, FILE_APPEND); return false; } if (!empty($goodsBasicResult)) { $this->objGoodsBasicRelevant->deleteBasicKeyById($this->objectId); //组装缓存数据 $goodsBasicResult = (array)$goodsBasicResult; $cacheMap = array_shift($goodsBasicResult); $cacheResult = $this->objGoodsBasicRelevant->cacheBasicIdRelationName($cacheMap, $this->objectId); if (!$cacheResult->isSuccess()) { //缓存写入失败 file_put_contents('/www/wwwroot/logs/api.junhailan.com/BasicAndSkuCache_error.log', date('Y-m-d H:i:s') . '错误|cache缓存失败,基础资料id:' . $this->objectId . PHP_EOL, FILE_APPEND); return false; } } return true; } /** * @param array $data * @return array */ public static function cacheMappers(array $data) { $map = []; if (empty($data)) { return $map; } $map = [ 'id' => $data['id'], 'title' => $data['title'], 'images' => $data['images'], 'condition' => $data['condition'], 'code' => $data['code'], 'categoryId' => $data['categoryId'], 'categoryName' => $data['categoryName'], 'categoryPath' => $data['categoryPath'], 'expireTime' => $data['expireTime'], 'brandId' => $data['brandId'], 'brandName' => $data['brandName'], 'describe' => $data['describe'], 'description' => $data['description'], 'noSalesShop' => $data['noSalesShop'], 'extends' => $data['extends'], 'createTime' => $data['createTime'], 'addUserId' => $data['addUserId'], 'salesManId' => $data['salesManId'], 'specGroup' => $data['specGroup'], 'specType' => $data['specType'] ]; return $map; } public function cacheSku() { if (!$this->isUpdateSku) { return false; } $skuResult = $this->objDSku->select(['id' => array_values(array_unique($this->updateSku))]); if ($skuResult === false) { file_put_contents('/www/wwwroot/logs/api.junhailan.com/BasicAndSkuCache_error.log', date('Y-m-d H:i:s') . '错误原因|sql: ' . $this->objDSku->error() . PHP_EOL, FILE_APPEND); return true; } foreach ($skuResult as $sku) { $cacheMap = self::cacheMappersSku($sku); $this->objSkuCache->delSku($sku['id']); $cacheRes = $this->objSkuCache->cacheSku($sku['id'], $cacheMap); if (!$cacheRes->isSuccess()) { file_put_contents('/www/wwwroot/logs/api.junhailan.com/BasicAndSkuCache_error.log', date('Y-m-d H:i:s') . '缓存失败|error: ' . $sku['id'] . PHP_EOL, FILE_APPEND); return false; } } return true; } /** * @param array $data * @return array */ public static function cacheMappersSku(array $data) { $map = []; if (empty($data)) { return $map; } $map = [ 'id' => $data['id'], 'unitId' => $data['unitId'], 'unitName' => $data['unitName'], 'isMaster' => $data['isMaster'], 'conversion' => $data['conversion'], 'specImage' => $data['specImage'], 'specData' => $data['specData'], 'specGroupHash' => $data['specGroupHash'], 'barCode' => $data['barCode'], 'goodsId' => $data['goodsId'] ]; return $map; } }