|
@@ -9,6 +9,105 @@ use think\facade\Validate;
|
|
|
class Report extends Base
|
|
|
{
|
|
|
|
|
|
+ //产品价格和产品导出
|
|
|
+ public function exportGood()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->only(['date', 'platform_id', 'status'], 'post', 'trim');
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'date|筛选时间' => 'require|date',
|
|
|
+ 'platform_id|筛选平台ID' => 'require|number|gt:0',
|
|
|
+ 'status|状态' => 'require|number|between:1,8',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!$val->check($param)) return error_show(1004, $val->getError());
|
|
|
+
|
|
|
+ $where_ladder = [['gl.is_del', '=', 0]];
|
|
|
+ $where_good = [['g.is_del', '=', 0]];
|
|
|
+ if (!empty($param['date'])) {
|
|
|
+ $where_ladder[] = ['gl.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']];
|
|
|
+ $where_good[] = ['g.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']];
|
|
|
+ }
|
|
|
+ if (!empty($param['platform_id'])) {
|
|
|
+ $where_ladder[] = ['gp.platform_code', '=', $param['platform_id']];
|
|
|
+ $where_good[] = ['gp.platform_code', '=', $param['platform_id']];
|
|
|
+ }
|
|
|
+ if (!empty($param['status'])) {
|
|
|
+ $where_ladder[] = ['g.status', '=', $param['status']];
|
|
|
+ $where_good[] = ['g.status', '=', $param['status']];
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ //产品价格
|
|
|
+ $rs_ladder = Db::name('good_ladder')
|
|
|
+ ->alias('gl')
|
|
|
+ ->field('g.good_name 商品名称,gl.market_price 市场价,gl.origin_rate 税率,g.moq 起订量,gl.sale_price 售价,gl.skuCode 商品编码,gl.cost_fee 工艺费,gl.market_platform 对比平台')
|
|
|
+ ->where($where_ladder)
|
|
|
+ ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
|
|
|
+ ->leftJoin('good g', 'g.spuCode=gp.spuCode AND g.is_del=0')
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if (!empty($rs_ladder)) {
|
|
|
+ $data[] = [
|
|
|
+ 'head' => array_keys($rs_ladder[0]),
|
|
|
+ 'list' => $rs_ladder,
|
|
|
+ 'filename' => '产品价格' . date('YmdHis'),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ //产品
|
|
|
+ $rs_temp_good = Db::name('good')
|
|
|
+ ->alias('g')
|
|
|
+ ->field('"" 一级分类,"" 二级分类, g.cat_id 三级分类,g.good_name 商品名称,g.good_type 商品类型,g.brand_id 商品品牌,\'\' 型号,g.origin_place 产地,g.good_unit 计量单位,g.weight 重量g,\'\' 响应时间,g.lead_time 供货周期,g.good_size 商品尺寸,g.packing_size 装箱尺寸,g.packing_way 包装方式,g.packing_spec 装箱规格,g.packing_list 包装清单,g.delivery_place 发货地,g.delivery_day 物流时间,gp.skuCode 商品编码,g.spuCode')
|
|
|
+ ->where($where_good)
|
|
|
+ ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0')
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $all_good_type = [1 => '定制商品', 2 => '常规商品'];
|
|
|
+ $all_brand = Db::name('brand')->whereIn('id', array_column($rs_temp_good, '商品品牌'))->where('is_del', 0)->column('brand_name', 'id');
|
|
|
+ $all_cat = Db::name('cat')
|
|
|
+ ->alias('c3')
|
|
|
+ ->whereIn('c3.id', array_column($rs_temp_good, '三级分类'))
|
|
|
+ ->where('c3.is_del', 0)
|
|
|
+ ->leftJoin('cat c2', 'c2.id=c3.pid AND c2.is_del=0')
|
|
|
+ ->leftJoin('cat c1', 'c1.id=c2.pid AND c1.is_del=0')
|
|
|
+ ->column('c3.cat_name cat_name_3,c2.cat_name cat_name_2,c1.cat_name cat_name_1', 'c3.id');
|
|
|
+
|
|
|
+ $all_unit = Db::name('unit')->whereIn('id', array_column($rs_temp_good, '计量单位'))->where('is_del', 0)->column('unit', 'id');
|
|
|
+
|
|
|
+ foreach ($rs_temp_good as &$value) {
|
|
|
+ $value['商品品牌'] = isset($all_brand[$value['商品品牌']]) ? $all_brand[$value['商品品牌']] : '';
|
|
|
+ $value['商品类型'] = isset($all_good_type[$value['商品类型']]) ? $all_good_type[$value['商品类型']] : '';
|
|
|
+ $value['一级分类'] = isset($all_cat[$value['三级分类']]['cat_name_1']) ? $all_cat[$value['三级分类']]['cat_name_1'] : '';
|
|
|
+ $value['二级分类'] = isset($all_cat[$value['三级分类']]['cat_name_2']) ? $all_cat[$value['三级分类']]['cat_name_2'] : '';
|
|
|
+ $value['三级分类'] = isset($all_cat[$value['三级分类']]['cat_name_3']) ? $all_cat[$value['三级分类']]['cat_name_3'] : '';
|
|
|
+
|
|
|
+ $temp = explode(',', $value['产地']);
|
|
|
+ $value['产地'] = GetAddr(json_encode(['provice_code' => $temp[0], 'city_code' => $temp[1], 'area_code' => $temp[2]]));
|
|
|
+ $value['计量单位'] = isset($all_unit[$value['计量单位']]) ? $all_unit[$value['计量单位']] : '';
|
|
|
+ $temp_2 = explode(',', $value['发货地']);
|
|
|
+ $value['发货地'] = GetAddr(json_encode(['provice_code' => $temp_2[0], 'city_code' => $temp_2[1], 'area_code' => $temp_2[2]]));
|
|
|
+
|
|
|
+ unset($value['spuCode']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($rs_temp_good)) {
|
|
|
+ $data[] = [
|
|
|
+ 'head' => array_keys($rs_temp_good[0]),
|
|
|
+ 'list' => $rs_temp_good,
|
|
|
+ 'filename' => '产品' . date('YmdHis'),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($data)) return error_show(1005, '没有可供导出的数据');
|
|
|
+ else excelSaveBatch($data);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//【一、采购日报表】1.咨询单总数
|
|
|
public function zixunTotal()
|
|
|
{
|