This commit is contained in:
2025-02-16 18:43:16 +08:00
parent 9e060aa95a
commit 58f9061565
9 changed files with 491 additions and 63 deletions

View File

@ -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');

View File

@ -0,0 +1,117 @@
<?php
namespace plugin\points_mall\controller;
use plugin\account\model\PluginAccountBind;
use plugin\points_mall\model\PointsMallOrder;
use plugin\points_mall\model\PointsMallOrderSender;
use think\admin\Controller;
use think\admin\helper\QueryHelper;
/**
* 订单发货管理
* @class Sender
* @package plugin\wemall\controller\shop
*/
class Sender extends Controller
{
/**
* 订单状态
* @var int[]
*/
private $oStatus = [4, 5, 6, 7];
/**
* 订单发货管理
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
$this->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]);
}
}
}

View File

@ -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;