From 755219dbd76514ae2977a8e7b64aa29ec87a2df0 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Wed, 22 Jun 2022 22:13:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E3=80=81=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=AF=BB=E5=8F=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hljapi/config/route.php | 19 +++ app/hljapi/controller/AccessToken.php | 39 ++++++ app/hljapi/controller/Common.php | 170 ++++++++++++++++++++++++++ app/hljapi/controller/Order.php | 95 ++++++++++++++ app/hljapi/controller/Product.php | 95 ++++++++++++++ app/hljapi/index.html | 0 app/service/OrderService.php | 143 +++++++++++++++------- app/service/PluginsService.php | 2 +- 8 files changed, 516 insertions(+), 47 deletions(-) create mode 100644 app/hljapi/config/route.php create mode 100644 app/hljapi/controller/AccessToken.php create mode 100644 app/hljapi/controller/Common.php create mode 100644 app/hljapi/controller/Order.php create mode 100644 app/hljapi/controller/Product.php create mode 100644 app/hljapi/index.html diff --git a/app/hljapi/config/route.php b/app/hljapi/config/route.php new file mode 100644 index 000000000..e7b10631f --- /dev/null +++ b/app/hljapi/config/route.php @@ -0,0 +1,19 @@ + MyFileConfig('home_seo_url_html_suffix', '', 'html', true), +]; +?> \ No newline at end of file diff --git a/app/hljapi/controller/AccessToken.php b/app/hljapi/controller/AccessToken.php new file mode 100644 index 000000000..9f5f11c5b --- /dev/null +++ b/app/hljapi/controller/AccessToken.php @@ -0,0 +1,39 @@ +GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } +} +?> \ No newline at end of file diff --git a/app/hljapi/controller/Common.php b/app/hljapi/controller/Common.php new file mode 100644 index 000000000..0baac3216 --- /dev/null +++ b/app/hljapi/controller/Common.php @@ -0,0 +1,170 @@ +data_post = input('post.'); + $this->data_get = input('get.'); + $this->data_request = input(); + + // 系统运行开始 + SystemService::SystemBegin($this->data_request); + + // 系统初始化 + $this->SystemInit(); + + // 公共数据初始化 + $this->CommonInit(); + } + + /** + * 析构函数 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-03-18 + * @desc description + */ + public function __destruct() + { + // 系统运行结束 + SystemService::SystemEnd($this->data_request); + } + + /** + * 系统初始化 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-07 + * @desc description + */ + private function SystemInit() + { + // 配置信息初始化 + ConfigService::ConfigInit(); + } + + /** + * 公共数据初始化 + * @author Devil + * @blog http://gong.gg/ + * @version 0.0.1 + * @datetime 2017-03-09T11:43:48+0800 + */ + private function CommonInit() + { + // 当前系统操作名称 + $this->module_name = RequestModule(); + $this->controller_name = RequestController(); + $this->action_name = RequestAction(); + + // 当前插件操作名称, 兼容插件模块名称 + if(empty($this->data_request['pluginsname'])) + { + $this->plugins_module_name = ''; + $this->plugins_controller_name = ''; + $this->plugins_action_name = ''; + } else { + $this->plugins_module_name = $this->data_request['pluginsname']; + $this->plugins_controller_name = empty($this->data_request['pluginscontrol']) ? 'index' : $this->data_request['pluginscontrol']; + $this->plugins_action_name = empty($this->data_request['pluginsaction']) ? 'index' : $this->data_request['pluginsaction']; + } + + // 分页信息 + $this->page = max(1, isset($this->data_request['page']) ? intval($this->data_request['page']) : 1); + $this->page_size = 10; + } + + /** + * 空方法响应 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-11-30 + * @desc description + * @param [string] $method [方法名称] + * @param [array] $args [参数] + */ + public function __call($method, $args) + { + return ApiService::ApiDataReturn('{"success":false,"resultMsg":"'.$method.'非法访问'.'","resultCode":"07","result":""}'); + } + + /** + * 获取类属性数据 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-06-07 + * @desc description + */ + public function GetClassVars() + { + $data = []; + $vers = get_class_vars(get_class()); + foreach($vers as $k=>$v) + { + if(property_exists($this, $k)) + { + $data[$k] = $this->$k; + } + } + return $data; + } +} +?> \ No newline at end of file diff --git a/app/hljapi/controller/Order.php b/app/hljapi/controller/Order.php new file mode 100644 index 000000000..5889ee643 --- /dev/null +++ b/app/hljapi/controller/Order.php @@ -0,0 +1,95 @@ +GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 确认预占订单 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function confirmPreOrder() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'order', 'confirm', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 取消预占订单 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function cancelPreOrder() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'order', 'cancel', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 确认收货 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function confirmReceipt() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'order', 'collect', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 订单物流查询 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function getOrderLogisticsInfo() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'order', 'express', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } +} +?> \ No newline at end of file diff --git a/app/hljapi/controller/Product.php b/app/hljapi/controller/Product.php new file mode 100644 index 000000000..4137dd7ed --- /dev/null +++ b/app/hljapi/controller/Product.php @@ -0,0 +1,95 @@ +GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 商品库存查询 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function getStock() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'goods', 'inventory', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 商品可售查询 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function saleCheck() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'goods', 'issales', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 商品上下架通知 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function shelfUpdateNotice() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'goods', 'shelves', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } + + /** + * 商品是否支持货到付款 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-01-02 + * @desc description + */ + public function checkIsCod() + { + $ret = PluginsService::PluginsControlCall('govpurheilongjiang', 'goods', 'iscod', 'api', $this->GetClassVars()); + return ApiService::ApiDataReturn($ret['data']); + } +} +?> \ No newline at end of file diff --git a/app/hljapi/index.html b/app/hljapi/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/app/service/OrderService.php b/app/service/OrderService.php index 14214be4f..91abd5453 100755 --- a/app/service/OrderService.php +++ b/app/service/OrderService.php @@ -1226,6 +1226,15 @@ class OrderService $result = []; if(!empty($data)) { + // 订单列表钩子-前面 + $hook_name = 'plugins_service_order_list_handle_begin'; + MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => &$params, + 'data' => &$data, + ]); + // 字段列表 $keys = ArrayKeys($data); $order_ids = array_column($data, 'id'); @@ -1280,6 +1289,9 @@ class OrderService // 订单地址 $address_data = self::OrderAddressData($order_ids); + // 订单详情 + $detail = ($is_items == 1) ? self::OrderItemList($data, $is_orderaftersale) : []; + // 循环处理数据 foreach($data as &$v) { @@ -1405,13 +1417,10 @@ class OrderService $v['extension_data'] = empty($v['extension_data']) ? null : json_decode($v['extension_data'], true); // 订单详情 - if($is_items == 1) + if($is_items == 1 && !empty($detail) && array_key_exists($v['id'], $detail)) { - $items = self::OrderItemList($v['id'], $v['order_model'], $v['status'], $v['pay_status'], $is_orderaftersale); - $v['items'] = $items; - $v['items_count'] = count($items); - - // 描述 + $v['items'] = $detail[$v['id']]; + $v['items_count'] = count($v['items']); $v['describe'] = '共'.$v['buy_number_count'].'件 合计:'.$v['currency_data']['currency_symbol'].$v['total_price'].'元'; } @@ -1442,6 +1451,15 @@ class OrderService return $ret; } } + + // 订单列表钩子-后面 + $hook_name = 'plugins_service_order_list_handle_end'; + MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => &$params, + 'data' => &$data, + ]); } return DataReturn('success', 0, $data); @@ -1530,66 +1548,99 @@ class OrderService * @author Devil * @blog http://gong.gg/ * @version 1.0.0 - * @date 2020-05-15 + * @date 2022-06-22 * @desc description - * @param [int] $order_id [订单 id] - * @param [int] $order_model [订单模式] - * @param [int] $status [订单状态] - * @param [int] $pay_status [支付状态] - * @param [int] $is_orderaftersale [是否读取订单售后(0否, 1是)] + * @param [array] $order [订单信息] + * @param [int] $is_orderaftersale [是否读取订单售后(0否, 1是)] */ - public static function OrderItemList($order_id, $order_model, $status, $pay_status, $is_orderaftersale = 0) + public static function OrderItemList($order, $is_orderaftersale = 0) { - $data = Db::name('OrderDetail')->where(['order_id'=>$order_id])->select()->toArray(); + $result = []; + $order = array_column($order, null, 'id'); + $order_ids = array_keys($order); + $data = Db::name('OrderDetail')->where(['order_id'=>$order_ids])->select()->toArray(); if(!empty($data)) { + // 订单详情自增id + $order_detail_ids = array_column($data, 'id'); + // 虚拟商品取货码 - $fictitious_value_list = Db::name('OrderFictitiousValue')->where(['order_detail_id'=>array_column($data, 'id')])->column('value', 'order_detail_id'); + $fictitious_value_list = Db::name('OrderFictitiousValue')->where(['order_detail_id'=>$order_detail_ids])->column('value', 'order_detail_id'); + + // 是否获取最新一条售后信息 + $orderaftersale = []; + if($is_orderaftersale == 1) + { + $temp_aftersale = Db::name('OrderAftersale')->where(['order_detail_id'=>$order_detail_ids])->order('id desc')->select()->toArray(); + if(!empty($temp_aftersale)) + { + foreach($temp_aftersale as $av) + { + if(!array_key_exists($av['order_detail_id'], $orderaftersale)) + { + $orderaftersale[$av['order_detail_id']] = $av; + } + } + } + } // 商品处理 $res = GoodsService::GoodsDataHandle($data, ['data_key_field'=>'goods_id']); $data = $res['data']; - foreach($data as &$vs) + foreach($data as $vs) { - // 避免订单商品价格被处理,强制使用原始内容 - if(!empty($vs['price_container'])) + // 当前商品订单信息 + if(array_key_exists($vs['order_id'], $order)) { - $vs['price'] = $vs['price_container']['price']; - $vs['original_price'] = $vs['price_container']['original_price']; - } + // 当前商品详情主订单信息 + $ov = $order[$vs['order_id']]; - // 规格 - $vs['spec_text'] = null; - if(!empty($vs['spec'])) - { - $vs['spec'] = json_decode($vs['spec'], true); - if(!empty($vs['spec']) && is_array($vs['spec'])) + // 避免订单商品价格被处理,强制使用原始内容 + if(!empty($vs['price_container'])) { - $vs['spec_text'] = implode(',', array_map(function($spec) - { - return $spec['type'].':'.$spec['value']; - }, $vs['spec'])); + $vs['price'] = $vs['price_container']['price']; + $vs['original_price'] = $vs['price_container']['original_price']; } - } else { - $vs['spec'] = null; - } - // 虚拟销售商品 - 虚拟信息处理 - if($order_model == 3 && $pay_status == 1 && in_array($status, [3,4])) - { - $vs['fictitious_goods_value'] = (!empty($fictitious_value_list) && is_array($fictitious_value_list) && array_key_exists($vs['id'], $fictitious_value_list)) ? $fictitious_value_list[$vs['id']] : ''; - } + // 规格 + $vs['spec_text'] = null; + if(!empty($vs['spec'])) + { + $vs['spec'] = json_decode($vs['spec'], true); + if(!empty($vs['spec']) && is_array($vs['spec'])) + { + $vs['spec_text'] = implode(',', array_map(function($spec) + { + return $spec['type'].':'.$spec['value']; + }, $vs['spec'])); + } + } else { + $vs['spec'] = null; + } - // 是否获取最新一条售后信息 - if($is_orderaftersale == 1) - { - $orderaftersale = Db::name('OrderAftersale')->where(['order_detail_id'=>$vs['id']])->order('id desc')->find(); - $vs['orderaftersale'] = $orderaftersale; - $vs['orderaftersale_btn_text'] = self::OrderAftersaleStatusBtnText($status, $orderaftersale); + // 虚拟销售商品 - 虚拟信息处理 + if($ov['order_model'] == 3 && $ov['pay_status'] == 1 && in_array($ov['status'], [3,4])) + { + $vs['fictitious_goods_value'] = (!empty($fictitious_value_list) && is_array($fictitious_value_list) && array_key_exists($vs['id'], $fictitious_value_list)) ? $fictitious_value_list[$vs['id']] : ''; + } + + // 是否获取最新一条售后信息 + if($is_orderaftersale == 1 && !empty($orderaftersale) && array_key_exists($vs['id'], $orderaftersale)) + { + $vs['orderaftersale'] = $orderaftersale[$vs['id']]; + $vs['orderaftersale_btn_text'] = self::OrderAftersaleStatusBtnText($ov['status'], $vs['orderaftersale']); + } + + // 加入分组 + if(!array_key_exists($vs['order_id'], $result)) + { + $result[$vs['order_id']] = []; + } + $result[$vs['order_id']][] = $vs; } } } - return $data; + return $result; } /** diff --git a/app/service/PluginsService.php b/app/service/PluginsService.php index 995658687..38e837b0f 100755 --- a/app/service/PluginsService.php +++ b/app/service/PluginsService.php @@ -40,7 +40,7 @@ class PluginsService { // 从缓存获取数据、数据不存在则从数据库读取 $data = ($is_cache === true) ? self::PluginsCacheData($plugins) : []; - if($data === null || !$is_cache) + if(empty($data) || !$is_cache) { // 获取数据 $ret = self::PluginsField($plugins, 'data');