diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 417d0c84..b493c91f 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -23,7 +23,7 @@ use app\common\service\qrcode\Goods as GoodsPoster; use cores\exception\BaseException; use think\db\exception\DbException; use think\response\Json; - +use app\common\enum\goods\GoodsDeliveryTime; /** * 商品控制器 * Class Goods @@ -99,7 +99,7 @@ class Goods extends Controller 'state' => "无货", 'goods_name' => $goods['goods_name'], 'goods_id' => $goods['goods_id'], - 'promise_info' => "预计".(GoodsDeliveryTime::data()[$goods['delivery_time']] ?? "72小时")."内发货", + 'promise_info' => "预计".(GoodsDeliveryTime::data()[$goods['delivery_time']]['name'] ?? "72小时")."内发货", ]; $return[] = $data; continue; diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 3b677e1c..fa4c09bc 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -17,7 +17,7 @@ use think\response\Json; use cores\exception\BaseException; use app\store\model\Goods as GoodsModel; use app\store\model\goods\Import as ImportModel; - +use app\common\model\GoodsCategoryRel; /** * 商品管理控制器 * Class Goods @@ -161,6 +161,15 @@ class Goods extends Controller $params['page'] = 1; $params['channels'] = ['zy']; $data = $model->getAdminListExport($params, $perSize)->toArray(); + // echo "
"; + // print_r($data['data']); + if ($data['data']) { + foreach ($data['data'] as &$value) { + $cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); + $value['category_id'] = $cates ? implode(",", array_column($cates, "category_id")) : ""; + } + } + // echo ""; // print_r($data); // exit(); @@ -168,15 +177,17 @@ class Goods extends Controller ['goods_id'=>'系统编码(禁止修改)'], ['goods_name'=>'标题'], ['cmmdty_model'=>'商品型号'], - ['goods_source'=>'商品来源(京东 苏宁 工厂 仓储 自采 填其中一项)'], + ['goods_source'=>'商品来源(JD:京东 SN:苏宁 GC:工厂 CC:仓储 ZC:自采 填其中一项)'], ['goods_no'=>'商品编码(电商平台同款编码)'], + ['category_id'=>'分类(填写1级到现有分类代码,中间用英文小写的逗号分开)'], ['delivery_time'=>'发货时效(0:24小时 1:48小时 3:72小时 4:7天内 5:15天内 6:30天内 7:45天内 填写其中一项)'], ['is_check'=>'是否审单(是填1 否填0)'], ['delivery_id'=>'运费模板ID'], - ['status'=>'商品状态 (下架填写0 上架填写1)'], + ['status'=>'商品状态 (下架填写20 上架填写10)'], ['cost_price_min'=>'成本价'], ['goods_price_min'=>'前台价'], ['stock_total'=>'库存量'], + // ['stock_total'=>'库存量'], ['remark'=>'下单须知'], ]; @@ -188,8 +199,8 @@ class Goods extends Controller $model = new ImportModel; $params = $this->postData(); $params['channel'] = "zy"; - if ($model->goodsUpdateBatch($params)) { - return $this->renderSuccess('已添加到导入任务中,请在历史导入记录中查看结果'); + if ($model->storeGoodsUpdateBatch($params)) { + return $this->renderSuccess('批量修改成功'); } return $this->renderError($model->getError() ?: '操作失败'); diff --git a/app/store/controller/Store.php b/app/store/controller/Store.php index 6b95f8f1..498f3c85 100644 --- a/app/store/controller/Store.php +++ b/app/store/controller/Store.php @@ -75,8 +75,8 @@ class Store extends Controller */ public function platformList(): Json { - //$list = Channel::withoutGlobalScope()->where('status', 1)->whereIn('code',['jd','sn','zy','xqtx'])->select(); - $list = Channel::withoutGlobalScope()->where('status', 1)->whereIn('code',['zy'])->select(); + $list = Channel::withoutGlobalScope()->where('status', 1)->whereIn('code',['jd','sn','zy','xqtx'])->select(); + //$list = Channel::withoutGlobalScope()->where('status', 1)->whereIn('code',['zy'])->select(); $platformList = []; foreach ($list as $key => $value) { $platformList[$value['code']] = $value['name']; diff --git a/app/store/model/OrderRefund.php b/app/store/model/OrderRefund.php index f443c0ab..4e1ed2da 100644 --- a/app/store/model/OrderRefund.php +++ b/app/store/model/OrderRefund.php @@ -204,7 +204,7 @@ class OrderRefund extends OrderRefundModel $this->save($data); // 同意售后申请, 记录退货地址 if ($data['audit_status'] == AuditStatusEnum::REVIEWED) { - (new OrderRefundAddress)->add((int)$this['order_refund_id'], (int)$data['address_id']); + (new OrderRefundAddress)->add((int)$this['order_refund_id'], (int)($data['address_id'] ?? 0)); } // 订单详情 $order = Order::detail($this['order_id']); diff --git a/app/store/model/goods/Import.php b/app/store/model/goods/Import.php index bb761ca8..15ef06a6 100644 --- a/app/store/model/goods/Import.php +++ b/app/store/model/goods/Import.php @@ -24,6 +24,9 @@ use app\common\library\helper; use app\common\library\phpoffice\ReadExecl; use app\common\model\goods\Import as ImportModel; use cores\exception\BaseException; +use app\common\model\Goods as GoodsModel; +use app\common\model\GoodsSku as GoodsSkuModel; +use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel; /** * 商品批量导入记录模型 @@ -165,7 +168,6 @@ class Import extends ImportModel $this->storeDispatchJob($execlData, $recordId); return true; } - /** * 执行批量更新 * @param array $form @@ -174,7 +176,7 @@ class Import extends ImportModel * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception */ - public function goodsUpdateBatch(array $form): bool + public function goodsUpdateBatch (array $form): bool { // 读取excel文件内容 $execlData = $this->readExecl(); @@ -208,6 +210,53 @@ class Import extends ImportModel $this->goodsUpdateJob($execlData, $recordId); return true; } + /** + * 执行批量更新 + * @param array $form + * @return bool + * @throws BaseException + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + */ + public function storeGoodsUpdateBatch(array $form): bool + { + // 读取excel文件内容 + $execlData = $this->readExecl(); + + // echo ""; + // print_r($execlData); + // exit(); + // 验证导入的商品数量是否合法 + $this->checkLimit($execlData); + + self::$storeId = $form['store_id'] ?? 0; + foreach ($execlData as $key => $value) { + $upData = [ + 'goods_name'=> $value['B'], + 'cmmdty_model'=> $value['C'], + 'goods_source'=> $value['D'], + 'goods_no'=> $value['E'], + 'delivery_time'=> $value['G'], + 'is_check'=> $value['H'], + 'delivery_id'=> $value['I'], + 'status'=> $value['J'], + 'cost_price_min'=> $value['K'], + 'goods_price_min'=> $value['L'], + 'goods_price_max'=> $value['L'], + 'line_price_min'=> $value['L'], + 'line_price_max'=> $value['L'], + 'stock_total'=> $value['M'], + 'remark'=> $value['N'], + ]; + // echo ""; + // print_r(explode(",", $value['F'])); + // exit(); + GoodsModel::where('goods_id', $value['A'])->update($upData); + GoodsSkuModel::where('goods_id', $value['A'])->update(['cost_price' => $value['K'], 'goods_price' => $value['L']]); + GoodsCategoryRelModel::updates((int)$value['A'], explode(",", $value['F'])); + } + return true; + } /** * 执行批量导入 * @param array $form