329 lines
16 KiB
PHP
329 lines
16 KiB
PHP
<?php
|
||
|
||
namespace addon\supply\shop\controller;
|
||
|
||
use addon\ali1688\model\Template as TemplateModel;
|
||
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
|
||
use addon\supply\model\AppApi as AppModel;
|
||
use addon\supply\model\goods\Goods;
|
||
use addon\supply\model\goods\Goods as GoodsModel;
|
||
use addon\supply\model\Supplier as SupplierModel;
|
||
use addon\supply\model\CloudApi;
|
||
use addon\supply\model\goods\GoodsWarehousing;
|
||
use addon\supply\model\SupplyGoodsCategory as GoodsCategory;
|
||
use app\model\express\Config as ExpressConfig;
|
||
use app\model\express\ExpressTemplate as ExpressTemplateModel;
|
||
use app\model\goods\GoodsAttribute as GoodsAttributeModel;
|
||
use app\model\goods\GoodsBrand as GoodsBrandModel;
|
||
use app\model\goods\GoodsCategory as GoodsCategoryModel;
|
||
use app\model\goods\GoodsCommunityQrCode;
|
||
use app\model\goods\GoodsLabel as GoodsLabelModel;
|
||
use app\model\goods\GoodsService as GoodsServiceModel;
|
||
use app\model\web\Config as ConfigModel;
|
||
use app\shop\controller\BaseShop;
|
||
use addon\form\model\Form;
|
||
|
||
class Supplygoods extends BaseShop
|
||
{
|
||
public function lists()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$condition = array(
|
||
['site_id', '=', $this->site_id]
|
||
);
|
||
$page = input('page', 1);
|
||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||
$list = model('supply_goods')->pageList($condition, '*', 'create_time desc', $page, $page_size);
|
||
return $list;
|
||
} else {
|
||
$this->forthMenu();
|
||
return $this->fetch("supply_goods/lists");
|
||
}
|
||
}
|
||
|
||
/***
|
||
* 代发入库
|
||
* @return void
|
||
*/
|
||
public function putIn()
|
||
{
|
||
$productID = input("productID");// 产品id
|
||
$cloud_id = input("cloud_id", '');// 云仓id
|
||
$price_template = input('template_id', 0);
|
||
if (request()->isAjax()) {
|
||
$category_id = input("category_id", 0);// 分类id
|
||
$category_json = json_encode($category_id);//分类字符串
|
||
$category_id = ',' . implode(',', $category_id) . ',';
|
||
$goods_id = input("goods_id", 0);// 商品id
|
||
$data = [
|
||
'goods_id' => $goods_id,// 商品id
|
||
'goods_name' => input("goods_name", ""),// 商品名称,
|
||
'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id,
|
||
'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称,
|
||
'is_limit' => input("is_limit", "0"),// 商品是否限购,
|
||
'limit_type' => input("limit_type", "1"),// 商品限购类型,
|
||
'site_id' => $this->site_id,
|
||
'category_id' => $category_id,
|
||
'category_json' => $category_json,
|
||
'goods_image' => input("goods_image", ""),// 商品主图路径
|
||
'goods_content' => input("goods_content", ""),// 商品详情
|
||
'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架)
|
||
'price' => input("price", 0),// 商品价格(取第一个sku)
|
||
'market_price' => input("market_price", 0),// 市场价格(取第一个sku)
|
||
'cost_price' => input("cost_price", 0),// 成本价(取第一个sku)
|
||
'sku_no' => input("sku_no", ""),// 商品sku编码
|
||
'weight' => input("weight", ""),// 重量
|
||
'volume' => input("volume", ""),// 体积
|
||
'goods_stock' => input("goods_stock", 0),// 商品库存(总和)
|
||
'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警
|
||
'is_free_shipping' => input("is_free_shipping", 1),// 是否免邮
|
||
'shipping_template' => input("shipping_template", 0),// 指定运费模板
|
||
'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式
|
||
'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式
|
||
'introduction' => input("introduction", ""),// 促销语
|
||
'keywords' => input("keywords", ""),// 关键词
|
||
'unit' => input("unit", ""),// 单位
|
||
'sort' => input("sort", 0),// 排序,
|
||
'video_url' => input("video_url", ""),// 视频
|
||
'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据
|
||
'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合
|
||
'label_id' => input("label_id", ''),// 商品分组id
|
||
'brand_id' => input("brand_id", 0),//品牌id
|
||
'virtual_sale' => input("virtual_sale", 0),// 虚拟销量
|
||
'max_buy' => input("max_buy", 0),// 限购
|
||
'min_buy' => input("min_buy", 0),// 起售
|
||
'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
|
||
'timer_on' => strtotime(input('timer_on', 0)),//定时上架
|
||
'timer_off' => strtotime(input('timer_off', 0)),//定时下架
|
||
'spec_type_status' => input('spec_type_status', 0),
|
||
'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
|
||
'qr_id' => input('qr_id', 0),//社群二维码id
|
||
'sale_show' => input('sale_show', 0),//
|
||
'stock_show' => input('stock_show', 0),//
|
||
'market_price_show' => input('market_price_show', 0),//
|
||
'barrage_show' => input('barrage_show', 0),//
|
||
'template_id' => input('template_id', 0),//商品海报id
|
||
'form_id' => input('form_id', 0),
|
||
'support_trade_type' => input('support_trade_type', ''),
|
||
'sale_channel' => input('sale_channel', 'all'),
|
||
'sale_store' => input('sale_store', 'all'),
|
||
'is_unify_pirce' => input('is_unify_pirce', '1'),
|
||
'is_zmxx' => input('is_zmxx', 0),
|
||
'cat_id' => input('cat_id', ''),
|
||
'channel_type' => input('channel_type', 'own'),
|
||
'cloud_id' => $cloud_id,
|
||
];
|
||
$goodsModel = new GoodsWarehousing();
|
||
if ($goods_id) {
|
||
$data['site_id'] = $this->site_id;
|
||
$goods_image = explode(',', $data['goods_image']);
|
||
$goods_sku_data = json_decode($data['goods_sku_data'], true);
|
||
$sku_image = array_column($goods_sku_data, 'sku_image');
|
||
$goods_images = array_unique(array_merge($goods_image, $sku_image));
|
||
$goodsModel->GooodsImgCheck($data['site_id'], $goods_images);//验证图片上传
|
||
$res = (new \app\model\goods\Goods())->editGoods($data);
|
||
return $res;
|
||
} else {
|
||
return $goodsModel->addGoods($data, $this->site_id, $productID, $price_template, $cloud_id);
|
||
}
|
||
}
|
||
$goods_model = new GoodsModel();
|
||
if ($cloud_id > 0) {//云仓
|
||
$cloud_model = new CloudApi($cloud_id);
|
||
$getGoodsInfo = $cloud_model->getGoodsInfo($productID)['data'][0];
|
||
$getGoodsInfo['productID'] = $productID;
|
||
$cloud_info = $cloud_model->getConfig();
|
||
$category_name = $getGoodsInfo['category_name'];
|
||
$goods_info = $goods_model->generateGoodsInfo($this->site_id, $getGoodsInfo, $price_template, $cloud_info);
|
||
} else {
|
||
$goods_info = $goods_model->editGetGoodsInfo([['goods_id', '=', $productID]]);
|
||
$goods_info = $goods_info['data'];
|
||
$goods_sku_list = $goods_model->getGoodsSkuList([['goods_id', '=', $productID]], "sku_id,sku_name,sku_no,sku_spec_format,price,price_json,goods_class,market_price,stock,weight,volume,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default,goods_supplier_format");
|
||
$goods_sku_list = $goods_sku_list['data'];
|
||
$goods_info['sku_list'] = $goods_sku_list;
|
||
$goods_info['productID'] = $productID;
|
||
$goods_info = $goods_model->generateGoodsInfo($this->site_id, $goods_info, $price_template);
|
||
$category_name = $goods_info['category_name'];
|
||
}
|
||
$this->assign("cloud_id", $cloud_id);
|
||
$this->assign("goods_info", $goods_info);
|
||
//获取一级商品分类
|
||
$goods_category_model = new GoodsCategoryModel();
|
||
$condition = [
|
||
['pid', '=', 0],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')['data'];
|
||
$this->assign("goods_category_list", $goods_category_list);
|
||
//获取运费模板
|
||
$express_template_model = new ExpressTemplateModel();
|
||
$express_template_list = $express_template_model->getExpressTemplateList([['site_id', "=", $this->site_id]], 'template_id,template_name', 'is_default desc')['data'];
|
||
if (empty($express_template_list)) {
|
||
return $this->error("请设置运费模板");
|
||
}
|
||
$this->assign("express_template_list", $express_template_list);
|
||
//获取商品类型
|
||
$goods_attr_model = new GoodsAttributeModel();
|
||
$attr_class_list = $goods_attr_model->getAttrClassList([['site_id', '=', $this->site_id]], 'class_id,class_name')['data'];
|
||
$this->assign("attr_class_list", $attr_class_list);
|
||
// 商品服务
|
||
$goods_service_model = new GoodsServiceModel();
|
||
$service_list = $goods_service_model->getServiceList([['site_id', '=', $this->site_id]], 'id,service_name,icon')['data'];
|
||
$this->assign("service_list", $service_list);
|
||
|
||
// 商品分组
|
||
$goods_label_model = new GoodsLabelModel();
|
||
$label_list = $goods_label_model->getLabelList([['site_id', '=', $this->site_id]], 'id,label_name', 'sort asc')['data'];
|
||
$this->assign("label_list", $label_list);
|
||
|
||
//商品默认排序值
|
||
$config_model = new ConfigModel();
|
||
$sort_config = $config_model->getGoodsSort($this->site_id, $this->app_module);
|
||
$sort_config = $sort_config['data']['value'];
|
||
$this->assign("sort_config", $sort_config);
|
||
|
||
//获取品牌
|
||
$goods_brand_model = new GoodsBrandModel();
|
||
$brand_list = $goods_brand_model->getBrandList([['site_id', '=', $this->site_id]], "brand_id, brand_name")['data'];
|
||
$this->assign("brand_list", $brand_list);
|
||
|
||
//获取商品海报
|
||
$poster_template_model = new PosterTemplateModel();
|
||
$poster_list = $poster_template_model->getPosterTemplateList([['site_id', '=', $this->site_id], ['template_status', '=', 1]], 'template_id,poster_name,site_id');
|
||
$this->assign('poster_list', $poster_list['data']);
|
||
|
||
$this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
|
||
//获取社群二维码
|
||
$goods_community_model = new GoodsCommunityQrCode();
|
||
$goods_community_qr_list = $goods_community_model->getQrList([['site_id', '=', $this->site_id], ['qr_state', '=', 1]], 'qr_id,qr_name,site_id');
|
||
$this->assign('goods_community_qr_list', $goods_community_qr_list['data']);
|
||
$form_is_exit = addon_is_exit('form', $this->site_id);
|
||
if ($form_is_exit) {
|
||
$form_list = (new Form())->getFormList([['site_id', '=', $this->site_id], ['form_type', '=', 'goods'], ['is_use', '=', 1]], 'id desc', 'id, form_name')['data'];
|
||
$this->assign('form_list', $form_list);
|
||
}
|
||
$this->assign('form_is_exit', $form_is_exit);
|
||
$express_type = (new ExpressConfig())->getEnabledExpressType($this->site_id);
|
||
$this->assign('express_type', $express_type);
|
||
$this->assign('all_goodsclass', event('GoodsClass'));
|
||
$this->assign('goods_class', (new \app\model\goods\Goods())->getGoodsClass());
|
||
$this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
|
||
$is_install_supply = addon_is_exit("supply");
|
||
if ($is_install_supply) {
|
||
$supplier_model = new SupplierModel();
|
||
$supplier_list = $supplier_model->getSupplyList([['supplier_site_id', '=', $this->site_id]], 'supplier_id,title', 'supplier_id desc')['data'];
|
||
$this->assign("supplier_list", $supplier_list);
|
||
}
|
||
$this->assign("is_install_supply", $is_install_supply);
|
||
$config = new \addon\aliapp\model\Config();
|
||
$config_info = $config->getAppConfig($this->site_id)['data']['value'];
|
||
$is_alipay_goods = 0;
|
||
if ($config_info) {
|
||
$is_alipay_goods = 1;
|
||
}
|
||
$this->assign("productID", $productID);
|
||
$this->assign("is_alipay_goods", $is_alipay_goods);
|
||
$this->assign("template_id", $price_template);
|
||
$this->assign('categoryName', $category_name);
|
||
return $this->fetch("goods/edit_goods", [], $this->replace);
|
||
}
|
||
|
||
|
||
public function putIns()
|
||
{
|
||
|
||
}
|
||
|
||
/**
|
||
* 选品广场
|
||
* @return void
|
||
*/
|
||
public function servicegoods()
|
||
{
|
||
$search['site_id'] = $this->site_id;
|
||
$template_list = (new TemplateModel($this->site_id))->getTemplateList($search);
|
||
$goods_category_model = new GoodsCategory();
|
||
$first_goods_category_list_result = $goods_category_model->getCategoryList([['pid', '=', 0]]);
|
||
$first_goods_category_list = $first_goods_category_list_result['data'] ?? [];
|
||
$condition = array(
|
||
['site_id', '=', $this->site_id],
|
||
['app_type', '=', 'access'],
|
||
);
|
||
$app_model = new AppModel();
|
||
$cloud_list = $app_model->getApiList($condition);
|
||
$this->assign('cloud_list', $cloud_list['data']);
|
||
$this->assign('category_list', $first_goods_category_list);
|
||
$this->assign('template_list', $template_list['data']['list']);
|
||
return $this->fetch('goods/servicegoods');
|
||
}
|
||
|
||
|
||
/***
|
||
* 获取商品列表
|
||
* @return array
|
||
* @throws \Exception
|
||
*/
|
||
public function getGoodsList()
|
||
{
|
||
$cloud_id = input('cloud_id', '');
|
||
$keyword = input('keyword');
|
||
$categoryId = input('categoryId');
|
||
$page_index = input('pageNum', 1);
|
||
$page_size = input('pageSize', 10);
|
||
$priceStart = input('priceStart');
|
||
$priceEnd = input('priceEnd');
|
||
$channel_type = input('channel_type', 'own');
|
||
$where=[
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
if ($cloud_id) {
|
||
$cloud_model = new CloudApi($cloud_id);
|
||
$data = [
|
||
'cloud_id' => $channel_type,
|
||
'keyword' => $keyword,
|
||
'categoryId' => $categoryId,
|
||
'page' => $page_index,
|
||
'pageSize' => $page_size,
|
||
'priceStart' => $priceStart,
|
||
'priceEnd' => $priceEnd
|
||
];
|
||
$goodsList = $cloud_model->getGoodsList($data);
|
||
$goods_ids = array_column($goodsList['data']['list'], 'goods_id');
|
||
$where[] = ['cloud_id', '=', $cloud_id];
|
||
} else {
|
||
$goodsModel = new Goods();
|
||
$where = [
|
||
[
|
||
'goods_name', 'like', "%{$keyword}%"
|
||
],
|
||
['goods_state', '=', 1]
|
||
];
|
||
if ($priceStart) {
|
||
$where[] = ['min_price', '>=', $priceStart];
|
||
}
|
||
if ($priceEnd) {
|
||
$where[] = ['max_price', '<=', $priceEnd];
|
||
}
|
||
if ($categoryId) {
|
||
$where[] = ['category_id', 'like', "%{$categoryId}%"];
|
||
}
|
||
$field = 'goods_id,goods_name as title,min_price as minPrice,max_price as maxPrice,goods_image as imgUrl';
|
||
$goodsList = $goodsModel->getGoodsPageList($where, $page_index, $page_size, 'create_time desc', $field);
|
||
$goods_ids = array_column($goodsList['data']['list'], 'goods_id');
|
||
}
|
||
$where[]=['open_offer_id', 'in', $goods_ids];
|
||
$supply = model('supply_goods_warehousing')->getColumn($where, 'open_offer_id', 'open_offer_id');
|
||
foreach ($goodsList['data']['list'] as $k => &$v) {
|
||
$v['imgUrl'] = explode(',', $v['imgUrl'])[0];
|
||
$v['salesCnt90d'] = '';
|
||
$v['serviceList'] = [];
|
||
if (isset($supply[$v['goods_id']])) {
|
||
$v['is_warehousing'] = 1;
|
||
} else {
|
||
$v['is_warehousing'] = 0;
|
||
}
|
||
}
|
||
return $goodsList;
|
||
}
|
||
}
|