lqmac 6 months ago
parent d0f4feff3f
commit b714489a3f
  1. 16
      app/admin/controller/Store.php
  2. 2
      app/api/model/PaymentTemplate.php
  3. 42
      app/common.php
  4. 3
      app/common/model/Goods.php
  5. 7
      app/job/service/goods/GoodsStoreImport.php
  6. 12
      app/store/controller/Goods.php
  7. 28
      app/store/model/Goods.php
  8. 4
      config/allowapi.php

@ -358,8 +358,20 @@ class Store extends Controller
return $this->renderSuccess('操作成功');
}
/**
* 多商户初始化
* [merchant description]
* @param int $storeId [description]
* @return [type] [description]
*/
public function merchant(int $storeId): Json
{
$model = StoreModel::detail($storeId);
if ($model->store_version == 1) {
$model->addMerchantRoleAndMenu((int)$storeId);
}
return $this->renderSuccess();
}

@ -43,6 +43,6 @@ class PaymentTemplate extends PaymentTemplateModel
*/
public static function findByWechatpaySerial(string $serial)
{
return static::get(['method' => PaymentMethodEnum::WECHAT, 'wechatpay_serial' => $serial]);
return static::get(['method' => PaymentMethodEnum::WECHAT, 'wechatpay_serial' => $serial,'is_delete' => 0]);
}
}

@ -26,6 +26,7 @@ use think\exception\HttpResponseException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use think\facade\Db;
/**
* 打印调试函数 html
@ -621,11 +622,46 @@ function getGoodsCostAndProfitAndProfitRate($net_price, $cost_price, $rate){
function getJdGoodsBySku($skus){
$sku = implode(",", $skus);
$url = "http://47.98.251.206:8811/api/skus/info?skus=".$sku;
$res = httpRequest($url, "GET", null, [], false, 30);
return $res;
}
$data = httpRequest($url, "GET", null, [], false, 30);
if ($data['code'] != 0 || !$data['data']) {
return [];
}
$data = $data['data'];
foreach ($data as &$item) {
$content = "";
if (isset($item['infoImages']) && $item['infoImages']) {
foreach ($item['infoImages'] as $value) {
if (strpos($value, "http") !== false) {
$content .= '<p><img src="' . $value . '"/></p>';
} else {
if (strpos($value, "//") !== false) {
$content .= '<p><img src="' . "https:".$value . '"/></p>';
} else {
$content .= '<p><img src="' . "https://".$value . '"/></p>';
}
}
}
$item['content'] = $content;
}
$goods_images = [];
//写入主图到数据库
if ($item['mainImages']) {
foreach ($item['mainImages'] as $image) {
$goods_images[] = [
'preview_url' => $image,
'file_id' => 0,
];
}
}
$item['goods_images'] = $goods_images;
}
$data = array_column($data, null, "skuId");
return $data;
}

@ -582,6 +582,9 @@ class Goods extends BaseModel
if (isset($param['merchant_id']) && $param['merchant_id'] !== '') {
$filter[] = ['goods.merchant_id', '=', $params['merchant_id']];
}
if (isset($param['is_jd_remove']) && $param['is_jd_remove'] !== '') {
$filter[] = ['goods.is_jd_remove', '=', $params['is_jd_remove']];
}
// 实例化新查询对象
return $query->where($filter);

@ -99,7 +99,7 @@ class GoodsStoreImport extends BaseService
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batch(array $list, int $recordId, int $storeId, int $merchantId): bool
public function batch(array $list, int $recordId, int $storeId, int $merchantId = 0): bool
{
$service = new \app\job\service\goods\Collector();
foreach ($list as $item) {
@ -109,7 +109,7 @@ class GoodsStoreImport extends BaseService
$this->successCount++;
continue;
}
$data = $this->createData($item, $storeId);
$data = $this->createData($item, $storeId, $merchantId);
$ret = $service->single($item['D'], $data, $storeId);
if ($ret == false) {
continue;
@ -202,7 +202,7 @@ class GoodsStoreImport extends BaseService
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function createData(array $original, int $storeId): array
public function createData(array $original, int $storeId, int $merchantId = 0): array
{
//批量导入销售区域处理
$region = [];
@ -272,6 +272,7 @@ class GoodsStoreImport extends BaseService
'goods_type' => 10,//实物
'goods_status' => 10,//上架
'store_id' => $storeId,
'merchant_id' => $merchantId,
//'sale_areas' => $arr ? implode("、", $arr) : "",
'region' => $region ? json_encode($region, JSON_UNESCAPED_UNICODE) : "",
'region_text' => $region_text ? json_encode(array_values($region_text), JSON_UNESCAPED_UNICODE) : "",

@ -285,7 +285,19 @@ class Goods extends Controller
return $this->renderError($model->getError() ?: '操作失败');
}
/**
* 商品抓取
* [collector description]
* @return [type] [description]
*/
public function collector(string $sku): Json{
$res = getJdGoodsBySku([$sku], 10048, 0, true);
// $collector = new \app\job\service\goods\Collector;
// $url = "https://item.jd.com/{$sku}.html";
// $res1 = $collector->collector($url, 10048);
return $this->renderSuccess($res[$sku] ?? []);
}

@ -26,6 +26,8 @@ use app\common\enum\goods\SpecType as GoodsSpecTypeEnum;
use app\common\enum\goods\Status as GoodsStatusEnum;
use cores\exception\BaseException;
use app\common\model\Region;
use think\facade\Db;
/**
* 商品模型
* Class Goods
@ -321,12 +323,36 @@ class Goods extends GoodsModel
}
$data['alone_grade_equity'] = $aloneGradeEquity;
//兼容分类前端传参不一致问题
$categoryIds = $data['categoryIds'];
if ($categoryIds && isset($categoryIds[0]['value'])) {
$categoryIds = array_column($categoryIds, 'value');
}
$data['categoryIds'] = $this->dealCategory($categoryIds);
//兼容图片前端传参不一致问题
$imagesIds = $data['imagesIds'];
if ($imagesIds && isset($imagesIds[0]['file_id'])) {
$images = [];
foreach ($imagesIds as $value) {
if ($value['file_id'] > 0) {
$images[] = $value['file_id'];
continue;
}
$inImage = [
'file_path' => $value['image'],
'store_id' => self::$storeId,
'merchant_id' => $data['merchant_id'] ?? 0,
'storage' => "external",
'create_time' => time(),
'update_time' => time(),
];
$file_id = Db::name('upload_file')->insertGetId($inImage);
$images[] = $file_id;
}
$data['imagesIds'] = $images;
}
return $data;
}

@ -2,4 +2,8 @@
return [
"/store/platformList",
"/setting.printer/all",
"/merchant/list",
"/goods/export",
"/goods/collector",
"/goods/import",
];
Loading…
Cancel
Save