From f8887f7431ee9778b26a88322b326f1cebf3339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Thu, 11 Mar 2021 18:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/api/Goods.php | 2 +- app/data/controller/api/auth/Order.php | 5 ++--- app/data/service/GoodsService.php | 11 +++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/data/controller/api/Goods.php b/app/data/controller/api/Goods.php index 2f33fc9ff..306e4b704 100644 --- a/app/data/controller/api/Goods.php +++ b/app/data/controller/api/Goods.php @@ -21,7 +21,7 @@ class Goods extends Controller */ public function getCate() { - $this->success('获取分类成功', GoodsService::instance()->getCateList()); + $this->success('获取分类成功', GoodsService::instance()->getCateTree()); } /** diff --git a/app/data/controller/api/auth/Order.php b/app/data/controller/api/auth/Order.php index 856075f4f..a34d9a619 100644 --- a/app/data/controller/api/auth/Order.php +++ b/app/data/controller/api/auth/Order.php @@ -289,13 +289,12 @@ class Order extends Auth $openid = ''; if (in_array($this->type, [UserService::APITYPE_WXAPP, UserService::APITYPE_WECHAT])) { $openid = $this->user[UserService::TYPES[$this->type]['auth']] ?? ''; - // if (empty($openid)) $this->error("发起支付失败"); + if (empty($openid)) $this->error("发起支付失败"); } // 返回订单数据及支付发起参数 $type = $order['amount_real'] <= 0 ? 'empty' : $data['payment_code']; $param = PaymentService::instance($type)->create($openid, $order['order_no'], $order['amount_real'], '商城订单支付', '', $data['payment_back'], $data['payment_image']); - $order = $this->app->db->name('ShopOrder')->where($map)->find() ?: new \stdClass(); - $this->success('获取支付参数', ['order' => $order, 'param' => $param]); + $this->success('获取支付参数', ['order' => $this->app->db->name('ShopOrder')->where($map)->find() ?: new \stdClass(), 'param' => $param]); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $exception) { diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index 0012b20a6..ed089554d 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -57,21 +57,16 @@ class GoodsService extends Service /** * 获取分类数据 - * @param string $type 操作函数 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function getCateList(string $type = 'arr2tree'): array + public function getCateTree(): array { $map = ['deleted' => 0, 'status' => 1]; $query = $this->app->db->name('ShopGoodsCate')->where($map)->order('sort desc,id desc'); - $cates = DataExtend::$type($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); - if ($type === 'arr2table') foreach ($cates as &$vo) { - $vo['sat'] = $vo['spt'] !== $this->getCateLevel() - 1 ? 'disabled' : ''; - } - return $cates; + return DataExtend::arr2tree($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); } /** @@ -133,7 +128,7 @@ class GoodsService extends Service foreach ($cates as $cate) if (in_array($cate['id'], $vo['cateids'])) $vo['cateinfo'] = $cate; [$vo['slider'], $vo['specs'], $vo['items']] = [str2arr($vo['slider'], '|'), json_decode($vo['data_specs'], true), []]; foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item; - if ($simple) unset($vo['marks'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs']); + if ($simple) unset($vo['marks'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs'], $vo['cateinfo']['parent']); } return $data; }