|
|
|
@ -18,6 +18,14 @@ use cores\exception\BaseException; |
|
|
|
|
use app\store\model\Goods as GoodsModel; |
|
|
|
|
use app\store\model\goods\Import as ImportModel; |
|
|
|
|
use app\common\model\GoodsCategoryRel; |
|
|
|
|
use app\common\model\Category; |
|
|
|
|
use app\job\controller\goods\StoreGoodsOffline as StoreGoodsOfflineJob; |
|
|
|
|
use app\job\controller\goods\StoreGoodsOnline as StoreGoodsOnlineJob; |
|
|
|
|
use app\job\controller\goods\StoreGoodsDelete as StoreGoodsDeleteJob; |
|
|
|
|
use app\common\service\Jd; |
|
|
|
|
use app\common\model\wxapp\Setting as WxappSettingModel; |
|
|
|
|
use EasyWeChat\Factory; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 商品管理控制器 |
|
|
|
|
* Class Goods |
|
|
|
@ -197,6 +205,24 @@ class Goods extends Controller |
|
|
|
|
if (!$model->setIsPool($goodsIds, $state)) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
} |
|
|
|
|
// 分批每次导入20条 |
|
|
|
|
$limit = 20; |
|
|
|
|
// 根据商品总数量计算需要的队列任务数量 |
|
|
|
|
$jobCount = \count($goodsIds) / $limit; |
|
|
|
|
// 逐次发布队列任务 |
|
|
|
|
for ($i = 0; $i < $jobCount; $i++) { |
|
|
|
|
$data = array_slice($goodsIds, $i * $limit, $limit); |
|
|
|
|
if ($state == 2) { |
|
|
|
|
StoreGoodsOfflineJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
} elseif ($state == 1) { |
|
|
|
|
StoreGoodsOnlineJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
@ -211,6 +237,24 @@ class Goods extends Controller |
|
|
|
|
if (!$model->setStatus($goodsIds, $state)) { |
|
|
|
|
return $this->renderError($model->getError() ?: '操作失败'); |
|
|
|
|
} |
|
|
|
|
// 分批每次导入20条 |
|
|
|
|
$limit = 20; |
|
|
|
|
// 根据商品总数量计算需要的队列任务数量 |
|
|
|
|
$jobCount = \count($goodsIds) / $limit; |
|
|
|
|
// 逐次发布队列任务 |
|
|
|
|
for ($i = 0; $i < $jobCount; $i++) { |
|
|
|
|
$data = array_slice($goodsIds, $i * $limit, $limit); |
|
|
|
|
if ($state == false) { |
|
|
|
|
StoreGoodsOfflineJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
} elseif ($state == true) { |
|
|
|
|
StoreGoodsOnlineJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('操作成功'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
@ -341,12 +385,27 @@ class Goods extends Controller |
|
|
|
|
} |
|
|
|
|
$cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); |
|
|
|
|
$value['category_id'] = $cates ? implode(",", array_column($cates, "category_id")) : ""; |
|
|
|
|
$region_text = $value['region_text'] ? json_decode($value['region_text'], true) : []; |
|
|
|
|
$str = ""; |
|
|
|
|
$link = ";"; |
|
|
|
|
$replace = "、"; |
|
|
|
|
if ($region_text) { |
|
|
|
|
foreach ($region_text as $key => $val) { |
|
|
|
|
if (!$val['citys']) { |
|
|
|
|
$str .= $val['name'].$link; |
|
|
|
|
} else { |
|
|
|
|
foreach ($val['citys'] as $key => $va) { |
|
|
|
|
$str .= $val['name']."-".$va['name'].$link; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$value['region_text'] = str_replace(";", $replace, rtrim($str, $link)) ; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// echo "<pre>"; |
|
|
|
|
// print_r($data); |
|
|
|
|
// exit(); |
|
|
|
|
$titles = [ |
|
|
|
|
['goods_id'=>'系统编码(禁止修改)'], |
|
|
|
|
['goods_name'=>'标题'], |
|
|
|
@ -364,11 +423,113 @@ class Goods extends Controller |
|
|
|
|
// ['stock_total'=>'库存量'], |
|
|
|
|
['remark'=>'下单须知'], |
|
|
|
|
['is_use_jd_stock'=>'是否使用京东库存(是填1 否填0)'], |
|
|
|
|
['region_text'=>'销售区域'], |
|
|
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']); |
|
|
|
|
} |
|
|
|
|
//文案导出 |
|
|
|
|
public function copyExport(){ |
|
|
|
|
ini_set('memory_limit', '2024M'); |
|
|
|
|
set_time_limit(0); |
|
|
|
|
$model = new GoodsModel; |
|
|
|
|
$params = $this->request->param(); |
|
|
|
|
$params['store_id'] = $this->storeId; |
|
|
|
|
$perSize = 10000; |
|
|
|
|
$params['page'] = 1; |
|
|
|
|
if ($this->merchantId) { |
|
|
|
|
$params['merchantId'] = $this->merchantId; |
|
|
|
|
} |
|
|
|
|
//$params['channels'] = ['zy']; |
|
|
|
|
// echo "<pre>"; |
|
|
|
|
// print_r($params); |
|
|
|
|
//exit(); |
|
|
|
|
$data = $model->getAdminListExport($params, $perSize)->toArray(); |
|
|
|
|
// echo "<pre>"; |
|
|
|
|
// print_r($data['data']); |
|
|
|
|
// exit(); |
|
|
|
|
$jd = new Jd(); |
|
|
|
|
$store_id = GoodsModel::$storeId; |
|
|
|
|
$wxConfig = WxappSettingModel::getConfigBasic($store_id); |
|
|
|
|
$config = [ |
|
|
|
|
'app_id' => $wxConfig['app_id'], |
|
|
|
|
'secret' => $wxConfig['app_secret'], |
|
|
|
|
'response_type' => 'array',// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 |
|
|
|
|
'log' => [ |
|
|
|
|
'level' => 'debug', |
|
|
|
|
'file' => app()->getRuntimePath().'wechat.log', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
$app = Factory::miniProgram($config); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($data['data']) { |
|
|
|
|
foreach ($data['data'] as &$value) { |
|
|
|
|
//小程序短链 |
|
|
|
|
$data1 = $app->short_link->getShortLink("pages/goods/detail?refereeId=0&goodsId=".$value['goods_id'], "", true); |
|
|
|
|
$value['applet_short_url'] = ""; |
|
|
|
|
if ($data1['errcode'] == 0) { |
|
|
|
|
$value['applet_short_url'] = $data1['link']; |
|
|
|
|
} |
|
|
|
|
//京东短链 |
|
|
|
|
$value['jd_short_url'] = $jd->getJdShortLink($value['goods_no']); |
|
|
|
|
$value['h5_url'] = "https://www.royaum.com.cn/mobile/#/pages/goods/detail?goodsId=".$value['goods_id']."&storeId=".$store_id; |
|
|
|
|
//分类 |
|
|
|
|
$value['category_3'] = "无"; |
|
|
|
|
$value['category_4'] = "无"; |
|
|
|
|
$value['membership_price'] = $value['goods_price_min']; |
|
|
|
|
$cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); |
|
|
|
|
if ($cates) { |
|
|
|
|
$cateList = Category::whereIn('category_id', array_column($cates, 'category_id'))->whereIn('level',[3,4])->order("level asc")->select()->toArray(); |
|
|
|
|
|
|
|
|
|
$value['category_3'] = $cateList[0]['name'] ?? "无"; |
|
|
|
|
$value['category_4'] = $cateList[1]['name'] ?? "无"; |
|
|
|
|
//会员价 |
|
|
|
|
$value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//销售区域 |
|
|
|
|
$region_text = $value['region_text'] ? json_decode($value['region_text'], true) : []; |
|
|
|
|
$str = ""; |
|
|
|
|
$link = ";"; |
|
|
|
|
$replace = "、"; |
|
|
|
|
if ($region_text) { |
|
|
|
|
foreach ($region_text as $key => $val) { |
|
|
|
|
if (!$val['citys']) { |
|
|
|
|
$str .= $val['name'].$link; |
|
|
|
|
} else { |
|
|
|
|
foreach ($val['citys'] as $key => $va) { |
|
|
|
|
$str .= $val['name']."-".$va['name'].$link; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$value['region_text'] = $str ? str_replace(";", $replace, rtrim($str, $link)) : "全国"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// echo "<pre>"; |
|
|
|
|
// print_r($data); |
|
|
|
|
// exit(); |
|
|
|
|
$titles = [ |
|
|
|
|
['goods_id'=>'系统编码'], |
|
|
|
|
['category_3'=>'三级分类'], |
|
|
|
|
['category_4'=>'四级分类'], |
|
|
|
|
['goods_name'=>'标题'], |
|
|
|
|
['cmmdty_model'=>'型号'], |
|
|
|
|
['membership_price'=>'推广价'], |
|
|
|
|
['goods_price_min'=>'市场价'], |
|
|
|
|
['jd_short_url'=>'同款链接'], |
|
|
|
|
['applet_short_url'=>'小程序链接'], |
|
|
|
|
['h5_url'=>'H5链接'], |
|
|
|
|
['region_text'=>'销售区域'], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']); |
|
|
|
|
} |
|
|
|
|
public function import(){ |
|
|
|
|
// 新增记录 |
|
|
|
|
$model = new ImportModel; |
|
|
|
|