From 58f9061565f242976265635210cae7fed366bb26 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 16 Feb 2025 18:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/Order.php | 2 +- .../src/controller/Sender.php | 117 +++++++++++++ .../src/controller/api/auth/Order.php | 16 +- .../src/model/PointsMallOrder.php | 12 +- .../src/model/PointsMallOrderSender.php | 4 + .../src/view/order/index.html | 54 +----- .../src/view/sender/delivery_form.html | 78 +++++++++ .../src/view/sender/index.html | 160 ++++++++++++++++++ .../src/view/sender/index_search.html | 111 ++++++++++++ 9 files changed, 491 insertions(+), 63 deletions(-) create mode 100644 plugs/think-plugs-points-mall/src/controller/Sender.php create mode 100644 plugs/think-plugs-points-mall/src/view/sender/delivery_form.html create mode 100644 plugs/think-plugs-points-mall/src/view/sender/index.html create mode 100644 plugs/think-plugs-points-mall/src/view/sender/index_search.html diff --git a/plugs/think-plugs-points-mall/src/controller/Order.php b/plugs/think-plugs-points-mall/src/controller/Order.php index 051ff2a..bdb4654 100644 --- a/plugs/think-plugs-points-mall/src/controller/Order.php +++ b/plugs/think-plugs-points-mall/src/controller/Order.php @@ -32,7 +32,7 @@ class Order extends Controller } }, function (QueryHelper $query) { - $query->with(['user', 'from', 'items', 'address']); + $query->with(['user', 'items', 'address']); $query->equal('status,refund_status')->like('order_no'); $query->dateBetween('create_time,payment_time,cancel_time,delivery_type'); diff --git a/plugs/think-plugs-points-mall/src/controller/Sender.php b/plugs/think-plugs-points-mall/src/controller/Sender.php new file mode 100644 index 0000000..d486f9c --- /dev/null +++ b/plugs/think-plugs-points-mall/src/controller/Sender.php @@ -0,0 +1,117 @@ +type = trim(input('type', 'ta'), 't'); + PointsMallOrderSender::mQuery()->layTable(function () { + $this->title = '订单发货管理'; + $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 'ta' => 0]; + $this->address = sysdata('plugin.wemall.address'); + // 订单状态统计 + $order = PointsMallOrder::mk()->whereIn('status', $this->oStatus)->where(['delivery_type' => 1]); + $query = PointsMallOrderSender::mk()->whereRaw("order_no in {$order->field('order_no')->buildSql()}"); + foreach ($query->fieldRaw('status,count(1) total')->group('status')->cursor() as $vo) { + $this->total["ta"] += $vo['total']; + $this->total["t{$vo['status']}"] = $vo['total']; + } + }, function (QueryHelper $query) { + $query->with(['user', 'main']); + $query->like('user_name|user_phone#user_name,region_prov|region_city|region_area|region_addr#address'); + $query->dateBetween('create_time,express_time')->equal('status')->like('express_code,order_no'); + + // 用户搜索查询 + $db = PluginAccountBind::mQuery()->like('phone|nickname#user_keys')->db(); + if ($db->getOptions('where')) $query->whereRaw("unid in {$db->field('id')->buildSql()}"); + + // 订单搜索查询 + $db = PointsMallOrder::mk()->whereIn('status', $this->oStatus)->where(['delivery_type' => 1]); + $query->whereRaw("order_no in {$db->field('order_no')->buildSql()}"); + + // 列表选项卡状态 + if (is_numeric($this->type)) { + $query->where(['status' => $this->type]); + } + }); + } + + /** + * 快递发货地址 + * @auth true + * @throws \think\admin\Exception + */ + public function config() + { + if ($this->request->isGet()) { + $this->vo = sysdata('plugin.wemall.address'); + $this->fetch(); + } else { + sysdata('plugin.wemall.address', $this->request->post()); + $this->success('地址保存成功!'); + } + } + + /** + * 修改快递管理 + * @auth true + */ + public function delivery() + { + PointsMallOrderSender::mForm('delivery_form', 'order_no'); + } + + /** + * 快递表单处理 + * @param array $vo + */ + protected function _delivery_form_filter(array &$vo) + { + if ($this->request->isGet()) { + $map = ['code' => $vo['delivery_code'], 'status' => 1, 'deleted' => 0]; + } elseif ($this->request->isPost()) { + $map = ['order_no' => $vo['order_no']]; + $order = PointsMallOrder::mk()->where($map)->findOrEmpty(); + if ($order->isEmpty()) $this->error('订单查询异常,请稍候再试!'); + + // 追加表单数据 + $vo['status'] = 2; +// $vo['company_name'] = ""; + $vo['express_time'] = $vo['express_time'] ?? date('Y-m-d H:i:s'); + + $vo['region_prov'] = $vo['form_prov'] ?? ''; + $vo['region_city'] = $vo['form_city'] ?? ''; + $vo['region_area'] = $vo['form_area'] ?? ''; + + // 更新订单发货状态 + if ($order['status'] === 4) $order->save(['status' => 5]); + } + } +} \ No newline at end of file diff --git a/plugs/think-plugs-points-mall/src/controller/api/auth/Order.php b/plugs/think-plugs-points-mall/src/controller/api/auth/Order.php index 5e08832..ce02b6c 100644 --- a/plugs/think-plugs-points-mall/src/controller/api/auth/Order.php +++ b/plugs/think-plugs-points-mall/src/controller/api/auth/Order.php @@ -2,6 +2,7 @@ namespace plugin\points_mall\controller\api\auth; +use app\wechat\service\PaymentService; use plugin\points_mall\controller\api\Auth; use plugin\points_mall\model\PointsMallAddress; use plugin\points_mall\model\PointsMallGoods; @@ -101,8 +102,8 @@ class Order extends Auth $order['amount_cost'] = array_sum(array_column($items, 'total_price_cost')); $order['amount_goods'] = array_sum(array_column($items, 'total_price_selling')); // 折扣后的金额 - $order['amount_discount'] = array_sum(array_column($items, 'discount_amount')); - $order['amount_reduct'] = $order['amount_goods']; + $order['amount_discount'] = array_sum(array_column($items, 'total_price_cost')); + $order['amount_reduct'] = 0; // 统计订单金额 $order['amount_real'] = round($order['amount_discount'] - $order['amount_reduct'], 2); $order['amount_total'] = $order['amount_goods']; @@ -355,7 +356,7 @@ class Order extends Auth empty($data['order_ps']) || $order->save(['order_ps' => $data['order_ps']]); // 无需支付,直接完成订单 - if (floatval($orderAmount = $order->getAttr('amount_real')) <= 0) { + if (floatval($orderAmount = $order->getAttr('amount_total')) <= 0) { $order->save(['status' => 4]); $this->success('已支付成功!', []); } @@ -394,12 +395,12 @@ class Order extends Auth // $response = Payment::mk(payment::INTEGRAL)->create($this->account, $data['order_no'], '账号积分抵扣', $orderAmount, $data['integral']); // if (($leaveAmount = Payment::leaveAmount($data['order_no'], $orderAmount)) <= 0) $this->success('已完成支付!', $response->toArray()); // } - $userPoint = UserPointService::getUserPoint($this->unid); - if ($userPoint['point'] < $leaveAmount) { + $userPoint = UserPointService::getUserPoint($this->usid); + if ($userPoint < $leaveAmount) { $this->error("积分不足!"); } else { $order->save(['status' => 4]); - UserPointService::addUserPoint($this->unid, -$leaveAmount, '积分购买商品抵扣'); + UserPointService::addUserPoint($this->usid, -$leaveAmount, '积分购买商品抵扣'); $this->success('积分抵扣成功!', []); } @@ -456,7 +457,6 @@ class Order extends Auth ]; if ($order->save($data) && UserOrderService::stock($order->getAttr('order_no'))) { // 触发订单取消事件 - Payment::refund($order->getAttr('order_no')); $this->app->event->trigger('PluginWemallOrderCancel', $order); // 返回处理成功数据 $this->success('取消成功!'); @@ -584,7 +584,7 @@ class Order extends Auth */ private function getOrderModel(): PointsMallOrder { - $map = $this->_vali(['unid.value' => $this->unid, 'order_no.require' => '单号不能为空']); + $map = $this->_vali(['unid.value' => $this->usid, 'order_no.require' => '单号不能为空']); $order = PointsMallOrder::mk()->where($map)->findOrEmpty(); if ($order->isEmpty()) $this->error('读取订单失败!'); return $order; diff --git a/plugs/think-plugs-points-mall/src/model/PointsMallOrder.php b/plugs/think-plugs-points-mall/src/model/PointsMallOrder.php index 0ad321a..d02b8f0 100644 --- a/plugs/think-plugs-points-mall/src/model/PointsMallOrder.php +++ b/plugs/think-plugs-points-mall/src/model/PointsMallOrder.php @@ -2,18 +2,16 @@ namespace plugin\points_mall\model; +use plugin\account\model\PluginAccountBind; use plugin\account\model\PluginAccountUser; use think\admin\Model; class PointsMallOrder extends Model { - /** - * 关联推荐用户 - * @return \think\model\relation\HasOne - */ - public function from() + + public function user() { - return $this->hasOne(PluginAccountUser::class, 'id', 'puid1'); + return $this->hasOne(PluginAccountBind::class, 'id', 'unid'); } /** @@ -51,7 +49,7 @@ class PointsMallOrder extends Model */ public function address() { - return $this->hasOne(PointsMallAddress::class, 'id', 'address_id'); + return $this->hasOne(PointsMallOrderSender::class, 'order_no', 'order_no'); } public function sender() { diff --git a/plugs/think-plugs-points-mall/src/model/PointsMallOrderSender.php b/plugs/think-plugs-points-mall/src/model/PointsMallOrderSender.php index bde96fc..31b1e4f 100644 --- a/plugs/think-plugs-points-mall/src/model/PointsMallOrderSender.php +++ b/plugs/think-plugs-points-mall/src/model/PointsMallOrderSender.php @@ -2,11 +2,15 @@ namespace plugin\points_mall\model; +use plugin\account\model\PluginAccountBind; use think\admin\Model; class PointsMallOrderSender extends Model { + public function user() { + return $this->hasOne(PluginAccountBind::class, 'id', 'unid'); + } /** * 关联订单数据 * @return \think\model\relation\HasOne diff --git a/plugs/think-plugs-points-mall/src/view/order/index.html b/plugs/think-plugs-points-mall/src/view/order/index.html index 3505c88..f27a8a3 100644 --- a/plugs/think-plugs-points-mall/src/view/order/index.html +++ b/plugs/think-plugs-points-mall/src/view/order/index.html @@ -54,61 +54,21 @@ return laytpl("