From 9e44c450c7452be7861b756895909de15a200b0c Mon Sep 17 00:00:00 2001 From: lqmac Date: Mon, 29 Apr 2024 23:11:56 +0800 Subject: [PATCH] 1 --- app/admin/controller/Goods.php | 15 +++++++++- app/api/controller/Dealer.php | 7 +++-- app/api/controller/Goods.php | 15 ++++++++-- app/common/model/Goods.php | 3 ++ app/store/controller/Goods.php | 43 +++++++++++++++++++++++++++ app/store/controller/order/Refund.php | 4 ++- app/store/model/Goods.php | 11 +++++++ app/store/model/Order.php | 1 + 8 files changed, 93 insertions(+), 6 deletions(-) diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 096fde45..288c1f18 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -201,7 +201,20 @@ class Goods extends Controller } return $this->renderSuccess('操作成功'); } - + /** + * 修改商品状态(上下架) + * @param array $goodsIds 商品id集 + * @param bool $state 为true表示上架 + * @return Json + */ + public function jingpin(array $goodsIds, int $is_jingpin): Json + { + $model = new GoodsModel; + if (!$model->setIsJingpin($goodsIds, $is_jingpin)) { + return $this->renderError($model->getError() ?: '操作失败'); + } + return $this->renderSuccess('操作成功'); + } /** * 修改商品状态(上下架) * @param array $goodsIds 商品id集 diff --git a/app/api/controller/Dealer.php b/app/api/controller/Dealer.php index 04732554..a49659df 100644 --- a/app/api/controller/Dealer.php +++ b/app/api/controller/Dealer.php @@ -61,8 +61,11 @@ class Dealer extends Controller */ public function center(): Json { - $dealer = isset($this->dealer) ? $this->dealer->toArray() : null; - + $dealer = $this->dealer; + if (!$dealer) { + return $this->renderError('您没有购买分销会员'); + } + $dealer = $dealer->toArray(); $dealer['update_time'] = date("Y-m-d", strtotime($dealer['update_time'])); // 获取用户头像 diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 05984a13..ece47feb 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -86,9 +86,20 @@ class Goods extends Controller foreach ($params['list'] as $value) { $res = "无货"; $goods = GoodsModel::where('goods_id', $value['goods_id'])->find(); + //限制销售区域 + $city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); + if ($goods['region'] && !in_array($city->id, json_decode($goods['region']))) { + $data = [ + 'state' => "无货", + 'goods_name' => $goods['goods_name'], + 'goods_id' => $goods['goods_id'], + ]; + $return[] = $data; + continue; + } switch ($goods->channel) { case 'sn': - $city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); + //$city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); $district = Region::withoutGlobalScope()->where('name', $params['district'])->where('level', 3)->find(); $suning = new \app\common\service\Suning(); $goods->num = $param['num'] ?? 1; @@ -98,7 +109,7 @@ class Goods extends Controller break; case 'jd': $province = Region::withoutGlobalScope()->where('name', $params['province'])->where('level', 1)->find(); - $city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); + //$city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); $district = Region::withoutGlobalScope()->where('name', $params['district'])->where('level', 3)->find(); $jd = new \app\common\service\Jd(); $arr = []; diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 9365da66..a9b22960 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -469,6 +469,9 @@ class Goods extends BaseModel if (isset($param['is_pool']) && $param['is_pool'] !== '') { $filter[] = ['goods.is_pool', '=', $params['is_pool']]; } + if (isset($param['is_jingpin']) && $param['is_jingpin'] !== '') { + $filter[] = ['goods.is_jingpin', '=', $params['is_jingpin']]; + } if (isset($param['start_time']) && $param['start_time'] !== '') { $filter[] = ['goods.create_time', '>=', strtotime($params['start_time'])]; } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 9461d65a..162184a7 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -16,6 +16,7 @@ use think\db\exception\DbException; use think\response\Json; use cores\exception\BaseException; use app\store\model\Goods as GoodsModel; +use app\store\model\goods\Import as ImportModel; /** * 商品管理控制器 @@ -151,4 +152,46 @@ class Goods extends Controller } return $this->renderSuccess('删除成功'); } + public function export(){ + + $model = new GoodsModel; + $params = $this->request->param(); + $params['store_id'] = $this->storeId; + $perSize = 10000; + $params['page'] = 1; + $params['channels'] = ['zy']; + $data = $model->getAdminListExport($params, $perSize)->toArray(); + // echo "
";
+        // print_r($data);
+        // exit();
+        $titles = [
+            ['goods_id'=>'系统编码'],
+            ['goods_name'=>'标题'],
+            ['cmmdty_model'=>'型号'],
+            ['link'=>'该商品苏宁的链接'],
+            ['cost_price_min'=>'成本价'],
+            ['stock_total'=>'库存'],
+            ['link_other'=>'京东的价拖链接'],
+            ['goods_price_min'=>'前台价'],
+        ];
+        
+        downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']);
+    }
+
+    public function import(){
+        // 新增记录
+        $model = new ImportModel;
+        $params = $this->postData();
+        $params['channel'] = "zy";
+        if ($model->goodsUpdateBatch($params)) {
+            return $this->renderSuccess('已添加到导入任务中,请在历史导入记录中查看结果');
+        }
+        return $this->renderError($model->getError() ?: '操作失败');
+
+    }
+
+
+
+
+
 }
diff --git a/app/store/controller/order/Refund.php b/app/store/controller/order/Refund.php
index c6980447..34655b9f 100644
--- a/app/store/controller/order/Refund.php
+++ b/app/store/controller/order/Refund.php
@@ -43,9 +43,11 @@ class Refund extends Controller
     {
         // 售后单详情
         $model = new OrderRefundModel;
-        if (!$detail = $model->getDetail($orderRefundId)) {
+        $detail = $model->getDetail($orderRefundId);
+        if (!$detail) {
             return $this->renderError('未找到该售后单记录');
         }
+        $detail->refuse_desc = $detail->refuse_desc ? htmlspecialchars_decode($detail->refuse_desc) : "";
         return $this->renderSuccess(compact('detail'));
     }
 
diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php
index 35cec680..ee053e55 100644
--- a/app/store/model/Goods.php
+++ b/app/store/model/Goods.php
@@ -192,6 +192,17 @@ class Goods extends GoodsModel
         // 批量更新记录
         return static::updateBase(['is_sale' => $is_sale], [['goods_id', 'in', $goodsIds]]);
     }
+    /**
+     * 修改商品状态
+     * @param array $goodsIds 商品id集
+     * @param bool $state 为true表示上架
+     * @return bool|false
+     */
+    public function setIsJingpin(array $goodsIds, int $is_sale): bool
+    {
+        // 批量更新记录
+        return static::updateBase(['is_jingpin' => $is_sale], [['goods_id', 'in', $goodsIds]]);
+    }
     /**
      * 修改商品状态
      * @param array $goodsIds 商品id集
diff --git a/app/store/model/Order.php b/app/store/model/Order.php
index db7603aa..f6530e25 100644
--- a/app/store/model/Order.php
+++ b/app/store/model/Order.php
@@ -47,6 +47,7 @@ class Order extends OrderModel
             'extract_clerk',
             'trade',
         ]);
+        $order->merchant_remark = $order->merchant_remark ? htmlspecialchars_decode($order->merchant_remark) : "";
         // 附加数据
         static::related($order, ['user', 'address', 'express', 'extract']);
         return $order;