admin商品管理添加导出
This commit is contained in:
parent
534b110cee
commit
749a3901af
@ -20,26 +20,21 @@
|
||||
|
||||
namespace app\admin\controller\goods;
|
||||
|
||||
use app\admin\logic\goods\CategoryLogic as MallCategoryLogic;
|
||||
use app\admin\logic\goods\ColumnLogic;
|
||||
use app\admin\logic\goods\GoodsLogic;
|
||||
use app\admin\validate\goods\GoodsValidate;
|
||||
use app\common\basics\AdminBase;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\model\Freight;
|
||||
use app\common\model\goods\Goods as GoodsModel;
|
||||
use app\common\model\goods\GoodsBrand;
|
||||
use app\common\model\goods\GoodsItem;
|
||||
use app\common\model\goods\GoodsUnit;
|
||||
use app\common\model\Freight;
|
||||
use app\common\model\goods\Supplier;
|
||||
use app\common\model\goods\Goods as GoodsModel;
|
||||
use app\common\server\JsonServer;
|
||||
use app\admin\logic\goods\CategoryLogic as MallCategoryLogic;
|
||||
use app\admin\logic\goods\GoodsLogic;
|
||||
use app\admin\logic\goods\ColumnLogic;
|
||||
use app\shop\logic\goods\CategoryLogic as ShopCategoryLogic;
|
||||
use think\exception\ValidateException;
|
||||
use app\admin\validate\goods\GoodsValidate;
|
||||
use weixin\Getgzopenid;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderGoods;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\model\goods\Goodscontact;
|
||||
|
||||
/**
|
||||
* 商品管理
|
||||
@ -64,7 +59,7 @@ class Goods extends AdminBase
|
||||
'statistics' => $statistics,
|
||||
'cate_list' => $cate_list,
|
||||
'column_list' => $column_list,
|
||||
'goods_type' => GoodsEnum::getTypeDesc()
|
||||
'goods_type' => GoodsEnum::getTypeDesc()
|
||||
]);
|
||||
}
|
||||
|
||||
@ -85,7 +80,8 @@ class Goods extends AdminBase
|
||||
'info' => json_encode(GoodsLogic::info($goods_id), JSON_UNESCAPED_UNICODE)
|
||||
]);
|
||||
}
|
||||
function curlPost($url,$data)
|
||||
|
||||
function curlPost($url, $data)
|
||||
{
|
||||
$ch = curl_init();
|
||||
$params[CURLOPT_URL] = $url; //请求url地址
|
||||
@ -100,6 +96,7 @@ class Goods extends AdminBase
|
||||
curl_close($ch); //关闭连接
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 违规重审
|
||||
*/
|
||||
@ -139,18 +136,18 @@ class Goods extends AdminBase
|
||||
}
|
||||
$result = GoodsLogic::setInfo($params);
|
||||
if ($result) {
|
||||
$goods_item_msg = GoodsItem::where("goods_id",$params['goods_id'])->select();
|
||||
foreach($goods_item_msg as $key=>$value){
|
||||
if($key==0){
|
||||
$d['wholesale_price'] = round($value['wh_price']*(100+$params['wholesale_percent'])/100,2);
|
||||
$d['purchase_price'] = round($value['pu_price']*(100+$params['purchase_percent'])/100,2);
|
||||
$d['issuing_price'] = round($value['is_price']*(100+$params['issuing_percent'])/100,2);
|
||||
$goods_msg = \app\common\model\goods\Goods::where("id",$params['goods_id'])->update($d);
|
||||
$goods_item_msg = GoodsItem::where("goods_id", $params['goods_id'])->select();
|
||||
foreach ($goods_item_msg as $key => $value) {
|
||||
if ($key == 0) {
|
||||
$d['wholesale_price'] = round($value['wh_price'] * (100 + $params['wholesale_percent']) / 100, 2);
|
||||
$d['purchase_price'] = round($value['pu_price'] * (100 + $params['purchase_percent']) / 100, 2);
|
||||
$d['issuing_price'] = round($value['is_price'] * (100 + $params['issuing_percent']) / 100, 2);
|
||||
$goods_msg = \app\common\model\goods\Goods::where("id", $params['goods_id'])->update($d);
|
||||
}
|
||||
$da['wholesale_pce'] = round($value['wh_price']*(100+$params['wholesale_percent'])/100,2);
|
||||
$da['purchase_price'] = round($value['pu_price']*(100+$params['purchase_percent'])/100,2);
|
||||
$da['issuing_price'] = round($value['is_price']*(100+$params['issuing_percent'])/100,2);
|
||||
GoodsItem::where("id",$value['id'])->update($da);
|
||||
$da['wholesale_pce'] = round($value['wh_price'] * (100 + $params['wholesale_percent']) / 100, 2);
|
||||
$da['purchase_price'] = round($value['pu_price'] * (100 + $params['purchase_percent']) / 100, 2);
|
||||
$da['issuing_price'] = round($value['is_price'] * (100 + $params['issuing_percent']) / 100, 2);
|
||||
GoodsItem::where("id", $value['id'])->update($da);
|
||||
}
|
||||
return JsonServer::success('设置成功');
|
||||
}
|
||||
@ -256,4 +253,16 @@ class Goods extends AdminBase
|
||||
'ids' => $ids
|
||||
]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
|
||||
$result = GoodsLogic::exportData($ids);
|
||||
if(false === $result) {
|
||||
return JsonServer::error(GoodsLogic::getError() ?: '导出失败');
|
||||
}
|
||||
|
||||
return JsonServer::success('', $result);
|
||||
}
|
||||
}
|
||||
@ -30,6 +30,8 @@ use app\common\model\goods\GoodsItem;
|
||||
use app\common\model\goods\GoodsSpec;
|
||||
use app\common\model\goods\GoodsSpecValue;
|
||||
use app\common\model\goods\Supplier;
|
||||
use app\common\server\ExportExcelServer;
|
||||
use app\common\server\ExportGoodsExcelServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Db;
|
||||
use app\common\model\seckill\SeckillGoods;
|
||||
@ -393,4 +395,77 @@ class GoodsLogic extends Logic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function exportData($ids)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['status', '=', GoodsEnum::STATUS_SHELVES],
|
||||
['del', '=', GoodsEnum::DEL_NORMAL],
|
||||
['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK],
|
||||
['stock','exp', Db::raw('>=stock_warn')]
|
||||
];
|
||||
|
||||
$order = [
|
||||
'sort' => 'asc',
|
||||
'id' => 'desc'
|
||||
];
|
||||
|
||||
|
||||
if ($ids) {
|
||||
$lists = Goods::where($where)
|
||||
->whereIn('id', $ids)
|
||||
->with('goods_item')
|
||||
->order($order)
|
||||
->select()
|
||||
->toArray();
|
||||
} else {
|
||||
$lists = Goods::where($where)
|
||||
->with('goods_item')
|
||||
->order($order)
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$title = [
|
||||
'name' => '商品名称',
|
||||
'spec_value_str' => '规格',
|
||||
'market_price' => '市场价',
|
||||
'price' => '价格',
|
||||
'chengben_price' => '成本价',
|
||||
'pifa_price' => '批发价',
|
||||
'purchase_price' => '集采价',
|
||||
'issuing_price' => '代发价',
|
||||
];
|
||||
|
||||
$data = array();
|
||||
foreach ($lists as $key => $item) {
|
||||
if ($item['goods_item']) {
|
||||
$count_goods_item = count($item['goods_item']);
|
||||
foreach ($item['goods_item'] as $key2 => $items) {
|
||||
$data[] = array(
|
||||
'name' => ($count_goods_item > 1 && $key2 > 0) ? '-' : $item['name'],
|
||||
'spec_value_str' => $items['spec_value_str'],
|
||||
'market_price' => $items['market_price'],
|
||||
'price' => $items['price'],
|
||||
'chengben_price' => $items['chengben_price'],
|
||||
'pifa_price' => $items['wholesale_pce'],
|
||||
'purchase_price' => $items['purchase_price'],
|
||||
'issuing_price' => $items['issuing_price'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$export = new ExportExcelServer();
|
||||
$export->setFileName('商品列表');
|
||||
$result = $export->createExcel($title, $data);
|
||||
return ['url' => $result];
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,6 +70,7 @@
|
||||
<div class="layui-inline">
|
||||
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">查询</button>
|
||||
<button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</button>
|
||||
<button class="layui-btn layui-btn-sm layuiadmin-btn-ad layui-btn-primary " lay-submit lay-filter="data-export">导出</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -165,6 +166,26 @@
|
||||
updateTabNumber();
|
||||
});
|
||||
|
||||
//导出数据
|
||||
form.on('submit(data-export)', function(){
|
||||
var checkStatus = table.checkStatus('goods-lists');
|
||||
var checkData = checkStatus.data;
|
||||
var ids = [];
|
||||
// 取出选中的行ID
|
||||
checkData.forEach(function (item) {
|
||||
ids.push(parseInt(item['id']));
|
||||
});
|
||||
like.ajax({
|
||||
url: '{:url("goods.goods/export")}'
|
||||
,data: {ids}
|
||||
, type: 'post'
|
||||
, success: function (res) {
|
||||
if (res.code == 1) {
|
||||
window.location.href = res.data.url;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.layui-btn.layuiadmin-btn-goods').on('click', function(){
|
||||
var type = $(this).data('type');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user