diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php
index 942e7091..06e1d165 100644
--- a/app/admin/controller/Store.php
+++ b/app/admin/controller/Store.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();
+ }
diff --git a/app/api/model/PaymentTemplate.php b/app/api/model/PaymentTemplate.php
index e30977d7..95864be0 100644
--- a/app/api/model/PaymentTemplate.php
+++ b/app/api/model/PaymentTemplate.php
@@ -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]);
}
}
diff --git a/app/common.php b/app/common.php
index 7533cac2..9020079b 100644
--- a/app/common.php
+++ b/app/common.php
@@ -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 .= '
![](' . $value . ')
';
+ } else {
+ if (strpos($value, "//") !== false) {
+ $content .= '![](' . )
';
+ } else {
+ $content .= '![](' . )
';
+ }
+
+ }
+
+ }
+ $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;
+}
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 0d37639d..ebbf173b 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -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);
diff --git a/app/job/service/goods/GoodsStoreImport.php b/app/job/service/goods/GoodsStoreImport.php
index af041165..0e65135f 100644
--- a/app/job/service/goods/GoodsStoreImport.php
+++ b/app/job/service/goods/GoodsStoreImport.php
@@ -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) : "",
diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php
index 4c913518..02b6116e 100644
--- a/app/store/controller/Goods.php
+++ b/app/store/controller/Goods.php
@@ -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] ?? []);
+ }
diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php
index c3e6d527..58ded193 100644
--- a/app/store/model/Goods.php
+++ b/app/store/model/Goods.php
@@ -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,13 +323,37 @@ 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;
}
diff --git a/config/allowapi.php b/config/allowapi.php
index eb5dfe08..ead52108 100644
--- a/config/allowapi.php
+++ b/config/allowapi.php
@@ -2,4 +2,8 @@
return [
"/store/platformList",
"/setting.printer/all",
+ "/merchant/list",
+ "/goods/export",
+ "/goods/collector",
+ "/goods/import",
];
\ No newline at end of file