lqmac 9 months ago
parent 0e14f43821
commit 12d1c47acb
  1. 57
      app/admin/controller/Category.php
  2. 9
      app/admin/controller/Store.php
  3. 33
      app/common/model/Channel.php
  4. 12
      app/common/model/Goods.php

@ -14,6 +14,7 @@ namespace app\admin\controller;
use think\response\Json;
use app\store\model\Category as CategoryModel;
use think\facade\Db;
/**
* 商品分类
@ -85,4 +86,60 @@ class Category extends Controller
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function copyCategory(int $new_store_id){
$store_id = 0;
$model = new CategoryModel;
$list = $model->getList(['store_id' =>$store_id]);
if (!$list) {
return;
}
foreach ($list as $value) {
$value = $value->toArray();
$value['store_id'] = $new_store_id;
$value['create_time'] = time();
$value['update_time'] = time();
$temp = $value;
unset($temp['children']);
unset($temp['image']);
unset($temp['category_id']);
$firstid = Db::table('yoshop_category')->insertGetId($temp);
if (!isset($value['children']) || !$value['children']) {
continue;
}
foreach ($value['children'] as $value1) {
$value1 = $value1->toArray();
$value1['parent_id'] = $firstid;
$value1['store_id'] = $new_store_id;
$value1['create_time'] = time();
$value1['update_time'] = time();
$temp1 = $value1;
unset($temp1['children']);
unset($temp1['image']);
unset($temp1['category_id']);
$secondid = Db::table('yoshop_category')->insertGetId($temp1);
if (!isset($value1['children']) || !$value1['children']) {
continue;
}
foreach ($value1['children'] as $value2) {
$value2 = $value2->toArray();
$value2['parent_id'] = $secondid;
$value2['store_id'] = $new_store_id;
$value2['create_time'] = time();
$value2['update_time'] = time();
$temp2 = $value2;
unset($temp2['children']);
unset($temp2['image']);
unset($temp2['category_id']);
Db::table('yoshop_category')->insertGetId($temp2);
}
}
}
return $this->renderSuccess($list);
}
}

@ -16,7 +16,7 @@ use think\response\Json;
use app\admin\model\Store as StoreModel;
use app\admin\model\store\SyncTask;
use app\admin\service\store\User as StoreUserService;
use app\common\model\Channel;
/**
* 商城管理
* Class Store
@ -162,7 +162,12 @@ class Store extends Controller
*/
public function platformList(): Json
{
$platformList = config('app.platformList');
$list = Channel::where('status', 1)->select();
$platformList = [];
foreach ($list as $key => $value) {
$platformList[$value['code']] = $value['name'];
}
//$platformList = config('app.platformList');
return $this->renderSuccess($platformList);
}
/**

@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
/**
* 文章模型
* Class Article
* @package app\common\model
*/
class Channel extends BaseModel
{
// 定义表名
protected $name = 'channel';
// 定义主键
protected $pk = 'id';
}

@ -25,7 +25,7 @@ use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
use think\Paginator;
use app\common\model\Channel;
/**
* 商品模型
* Class Goods
@ -78,7 +78,7 @@ class Goods extends BaseModel
*/
public function getContentAttr($value): string
{
return htmlspecialchars_decode($value);
return $value ? htmlspecialchars_decode($value) : "";
}
/**
@ -343,8 +343,10 @@ class Goods extends BaseModel
if ($list->isEmpty()) {
return $list;
}
// 遍历商品列表整理数据
foreach ($list as &$goods) {
$goods = $this->setGoodsData($goods, $callback);
}
@ -359,10 +361,12 @@ class Goods extends BaseModel
*/
protected function setGoodsData($goodsInfo, callable $callback = null)
{
// 商品图片列表
$channel = Channel::where('code', $goodsInfo['channel'])->find();
$goodsInfo['channel_name'] = $channel['name'] ?? "";
$goodsInfo['goods_images'] = helper::getArrayColumn($goodsInfo['images'], 'file');
// 商品主图
$goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
$goodsInfo['goods_image'] = $goodsInfo['goods_images'] ? current($goodsInfo['goods_images'])['preview_url'] : "";
// 商品销量(实际显示=初始虚拟销量+实际销量)
$goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual'];
// //商品价格判断

Loading…
Cancel
Save