From 2ae2ea87e14b5b35220bd7e32a1c24491e99a478 Mon Sep 17 00:00:00 2001 From: youda Date: Sun, 27 Apr 2025 15:19:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Config.php | 44 +++++++++++ app/admin/controller/Finance.php | 40 +++++++--- app/admin/controller/Order.php | 85 ++++++++++++++++++++- app/admin/route/app.php | 10 ++- app/admin/view/Finance/recharge_list.html | 16 ++-- app/admin/view/Order/send_order.html | 2 + app/admin/view/Order/send_order_detail.html | 25 +++++- app/admin/view/Profit/add.html | 2 + app/admin/view/Profit/edit.html | 2 + app/admin/view/Public/footer.html | 2 +- app/api/controller/Notify.php | 10 ++- app/common/model/WxpayLog.php | 61 +++++++++++++++ route/app.php | 4 +- 13 files changed, 273 insertions(+), 30 deletions(-) diff --git a/app/admin/controller/Config.php b/app/admin/controller/Config.php index 62f218a..baea861 100755 --- a/app/admin/controller/Config.php +++ b/app/admin/controller/Config.php @@ -6,6 +6,7 @@ use app\common\server\RedisHelper; use \think\facade\Request; use \think\facade\View; use think\facade\Db; +use think\Response; class Config extends Base @@ -241,6 +242,49 @@ class Config extends Base } } + /** + * 返回动态生成的JavaScript + * @return Response + */ + public function dynamicJs() + { + // 解决跨域问题 + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET'); + + // 获取需要的配置数据 + $config = getConfig('systemconfig'); + + // 构建JavaScript内容 + $jsContent = "// 动态生成的JS文件\n"; + $jsContent .= "const siteConfig = " . json_encode($config, JSON_UNESCAPED_UNICODE) . ";\n"; + $jsContent .= "console.log('配置已加载');\n"; + + // 创建响应并设置Content-Type + return Response::create($jsContent) + ->contentType('application/javascript') + ->header(['Content-Type' => 'application/javascript']); + } + + /** + * 直接输出JS内容的备用方法 + */ + public function getJs() + { + // 解决跨域问题 + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET'); + header('Content-Type: application/javascript'); + + // 获取需要的配置数据 + $config = getConfig('systemconfig'); + + // 直接输出JS内容 + echo "// 动态生成的JS文件\n"; + echo "const siteConfig = " . json_encode($config, JSON_UNESCAPED_UNICODE) . ";\n"; + echo "console.log('配置已加载');\n"; + exit; + } } diff --git a/app/admin/controller/Finance.php b/app/admin/controller/Finance.php index 6e59e76..27162bb 100755 --- a/app/admin/controller/Finance.php +++ b/app/admin/controller/Finance.php @@ -289,8 +289,9 @@ class Finance extends Base $mobile = trim(input('get.mobile')); $pay_time = trim(input('get.pay_time')); $whe = []; - // $whe[] = ['status', '=', 2]; + if ($user_id) { + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -306,25 +307,28 @@ class Finance extends Base } $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)]; } - $data = WxpayLog::getList($whe, '*', 'id desc', $this->page); + + // 从profit_pay表获取充值记录,而不是从WxpayLog表 + $data = \app\common\model\ProfitPay::getList($whe, '*', 'id desc', $this->page); $total_money = 0; + foreach ($data['list'] as &$value) { - $content = json_decode($value['content'], true); - - $value['money'] = $content['total_fee'] / 100; - - $total_money += $value['money']; - $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find(); + $total_money += $value['change_money']; + + $user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find(); if ($user_info != null) { $value['nickname'] = $user_info['nickname']; $value['headimg'] = $user_info['headimg']; $value['mobile'] = $user_info['mobile']; + $value['uid'] = $user_info['uid'] ?: $value['user_id']; } else { - $value['nickname'] =''; + $value['nickname'] = ''; $value['headimg'] = ''; $value['mobile'] = ''; + $value['uid'] = ''; } } + View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); @@ -397,4 +401,22 @@ class Finance extends Base View::assign('total_money', $total_money); return View::fetch("Finance/infinite_list"); } + + /** + * 数据迁移:从WxpayLog迁移到ProfitPay + */ + public function migrate_payment_logs() + { + $page = input('page/d', 1); + $limit = input('limit/d', 100); + $offset = ($page - 1) * $limit; + + $result = \app\common\model\WxpayLog::migrateToNewTable($limit, $offset); + + if ($result['status'] == 1) { + return $this->renderSuccess($result['message'], $result); + } else { + return $this->renderError($result['message']); + } + } } diff --git a/app/admin/controller/Order.php b/app/admin/controller/Order.php index 3eb62ae..7266b38 100755 --- a/app/admin/controller/Order.php +++ b/app/admin/controller/Order.php @@ -510,10 +510,13 @@ class Order extends Base if ($info['freight'] > 0) { $wxServer = new \app\common\server\WechatRefund($this->app); $refund_res = $wxServer->OrderRefund($info); - Db::name('wxpay_log')->insert([ - 'order_no' => 'QX_' . $info['send_num'], - 'content' => json_encode($refund_res['msg']), - 'type' => 2, + Db::name('profit_pay')->insert([ + 'user_id' => $info['user_id'], + 'order_num' => 'QX_' . $info['send_num'], + 'change_money' => -$info['freight'], + 'content' => '背包发货退款', + 'pay_type' => 1, + 'addtime' => time(), ]); // if ($refund_res['status'] == 0) { // return $this->renderError($refund_res['msg']); @@ -917,4 +920,78 @@ class Order extends Base return View::fetch('Order/unpaid_order'); } + /** + * 删除发货订单中的单个商品 + */ + public function delete_order_item() + { + $id = request()->param('id/d', 0); + $send_num = request()->param('send_num', ''); + + // 查找商品记录 + $orderItem = OrderList::where('id', '=', $id) + ->where('send_num', '=', $send_num) + ->find(); + + if (!$orderItem) { + return $this->renderError('商品不存在或参数错误'); + } + + // 获取订单信息 + $orderInfo = OrderListSend::where('send_num', '=', $send_num)->find(); + if (!$orderInfo) { + return $this->renderError('订单不存在'); + } + + Db::startTrans(); + try { + // 更新商品状态 + $orderItem->send_num = NULL; + $orderItem->status = 0; + $orderItem->choice_time = 0; + $orderItem->fh_status = 0; + $orderItem->save(); + + // 检查订单中是否还有其他商品 + $remainingItems = OrderList::where('send_num', '=', $send_num)->count(); + + // 如果没有其他商品,取消整个订单 + if ($remainingItems <= 1) { // 1表示当前要删除的商品 + // 如果订单有运费且已支付,需要处理退款 + if ($orderInfo['freight'] > 0 && $orderInfo['status'] > 0) { + $wxServer = new \app\common\server\WechatRefund($this->app); + $refund_res = $wxServer->OrderRefund($orderInfo); + + // 记录退款 + Db::name('profit_pay')->insert([ + 'user_id' => $orderInfo['user_id'], + 'order_num' => 'QX_' . $orderInfo['send_num'], + 'change_money' => -$orderInfo['freight'], + 'content' => '背包发货退款(商品删除)', + 'pay_type' => 1, + 'addtime' => time(), + ]); + } + + // 更新订单状态为取消 + OrderListSend::where('id', '=', $orderInfo['id'])->update([ + 'status' => 4, + 'cancel_time' => time(), + 'admin_id' => $this->admin_id, + ]); + } else { + // 更新订单中的商品数量 + OrderListSend::where('id', '=', $orderInfo['id'])->update([ + 'count' => $remainingItems - 1 // 减去当前要删除的商品 + ]); + } + + Db::commit(); + return $this->renderSuccess('商品已成功从订单中删除'); + } catch (\Exception $e) { + Db::rollback(); + return $this->renderError('删除失败:' . $e->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 7183b04..4bb1129 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -222,6 +222,7 @@ Route::rule('recovery_order_daochu', 'Order/recovery_order_daochu'); Route::rule('send_order_daochu', 'Order/send_order_daochu'); Route::rule('send_order_dandufahuo', 'Order/send_order_dandufahuo'); Route::rule('unpaid_order', 'Order/unpaid_order'); +Route::rule('delete_order_item', 'Order/delete_order_item'); #============================ @@ -434,4 +435,11 @@ Route::rule('statistics_exportProfit', 'Statistics/exportProfit', 'GET'); // 盒子下架日志相关路由 Route::post('goods_offshelf_read', 'GoodsOffshelfController/read'); -Route::get('goods_offshelf_unread_count', 'GoodsOffshelfController/getUnreadCount'); \ No newline at end of file +Route::get('goods_offshelf_unread_count', 'GoodsOffshelfController/getUnreadCount'); + + +#============================ +# dynamicJs +#============================ +Route::get('dynamicJs.js', 'Config/dynamicJs')->ext('js'); + \ No newline at end of file diff --git a/app/admin/view/Finance/recharge_list.html b/app/admin/view/Finance/recharge_list.html index d3ed32f..969241b 100755 --- a/app/admin/view/Finance/recharge_list.html +++ b/app/admin/view/Finance/recharge_list.html @@ -38,7 +38,9 @@ 用户信息 订单号 - 充值数量 + 充值金额 + 支付类型 + 支付描述 支付时间 @@ -49,14 +51,16 @@
-

UID:{$vo['user_id']}

+

UID:{$vo['uid'] ? $vo['uid'] : $vo['user_id']}

{$vo['mobile']}

{$vo['nickname']}

- {$vo['order_no']} - {$vo['money']} + {$vo['order_num']} + {$vo['change_money']} + {$vo['pay_type'] == 1 ? '微信支付' : '支付宝支付'} + {$vo['content']} {$vo['addtime']|date="Y-m-d H:i:s"} {/volist} @@ -86,10 +90,6 @@ ,format: 'yyyy-MM-dd' }) }); - - - - diff --git a/app/admin/view/Order/send_order.html b/app/admin/view/Order/send_order.html index 5873a62..040df71 100755 --- a/app/admin/view/Order/send_order.html +++ b/app/admin/view/Order/send_order.html @@ -119,6 +119,8 @@ {if $vo.status lt 4} 查看详情 + {/if} + {if $vo['status'] eq 1 || $vo['status'] eq 2} 取消发货 {/if} diff --git a/app/admin/view/Order/send_order_detail.html b/app/admin/view/Order/send_order_detail.html index b6b0735..2c25249 100755 --- a/app/admin/view/Order/send_order_detail.html +++ b/app/admin/view/Order/send_order_detail.html @@ -112,17 +112,21 @@ {if $info['status'] eq 2 && $vo['fh_status'] eq 0} - 发货 {/if} {if $info['status'] eq 2 && $vo['fh_status'] eq 1} - 取消发货 {/if} {if $info['status'] eq 2} 修改备注 {/if} + {if $info['status'] eq 2 && $vo['fh_status'] eq 0} + 移除商品 + {/if} @@ -269,6 +273,23 @@ // }); } + //删除单个商品 + function deleteItem(id, send_num) { + layer.confirm('确定要从订单中移除商品此商品吗?', { + btn: ['确定','取消'] //按钮 + }, function(){ + var url = "{:url('/admin/delete_order_item')}"; + $.post(url, {"id": id, "send_num": send_num}, function(data) { + if(data.status == 1) { + layer.msg('移除成功', {icon: 1, time: 1000}, function(){ + location.reload(); + }); + } else { + layer.msg(data.msg, {icon: 2, anim: 6, time: 1000}); + } + }); + }); + } diff --git a/app/admin/view/Profit/add.html b/app/admin/view/Profit/add.html index 708ba35..42d8978 100755 --- a/app/admin/view/Profit/add.html +++ b/app/admin/view/Profit/add.html @@ -23,6 +23,8 @@ + + diff --git a/app/admin/view/Profit/edit.html b/app/admin/view/Profit/edit.html index dc386ea..0c78c7b 100755 --- a/app/admin/view/Profit/edit.html +++ b/app/admin/view/Profit/edit.html @@ -24,6 +24,8 @@ + + diff --git a/app/admin/view/Public/footer.html b/app/admin/view/Public/footer.html index 5e569c3..0812a32 100755 --- a/app/admin/view/Public/footer.html +++ b/app/admin/view/Public/footer.html @@ -1,6 +1,6 @@ - + diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index 43b97c2..fab8407 100755 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -198,11 +198,13 @@ class Notify extends Base if ($data['return_code'] == 'SUCCESS' && $data['result_code'] == 'SUCCESS') { $user = User::where('openid', $data['openid'])->find(); try { - Db::name('wxpay_log')->insert([ - 'order_no' => $data['out_trade_no'], - 'content' => json_encode($data), - 'type' => 1, + // 使用profit_pay表记录支付信息,而不是wxpay_log表 + Db::name('profit_pay')->insert([ 'user_id' => $user['id'], + 'order_num' => $data['out_trade_no'], + 'change_money' => isset($data['total_fee']) ? ($data['total_fee'] / 100) : 0, + 'content' => $data['attach'] ? $data['attach'] : '微信支付', + 'pay_type' => 1, // 1微信 2支付宝 'addtime' => time(), ]); } catch (\Throwable $e) { diff --git a/app/common/model/WxpayLog.php b/app/common/model/WxpayLog.php index fdfa07c..8803765 100755 --- a/app/common/model/WxpayLog.php +++ b/app/common/model/WxpayLog.php @@ -25,4 +25,65 @@ class WxpayLog extends Base $data['page']=$page; return $data; } + + /** + * 迁移旧数据到ProfitPay表 + * 将WxpayLog表中的旧数据迁移到profit_pay表 + * @param int $limit 每次处理的数据量 + * @param int $offset 起始偏移量 + * @return array 处理结果 + */ + public static function migrateToNewTable($limit = 100, $offset = 0) + { + try { + // 获取旧表数据 + $oldRecords = self::limit($limit)->offset($offset)->order('id asc')->select(); + $total = count($oldRecords); + $success = 0; + $failed = 0; + $detail = []; + + // 处理每条记录 + foreach ($oldRecords as $record) { + try { + // 解析content字段中的json数据 + $content = json_decode($record['content'], true); + $change_money = isset($content['total_fee']) ? ($content['total_fee'] / 100) : 0; + + // 检查记录是否已经存在 + $exists = ProfitPay::where('order_num', $record['order_no'])->find(); + if ($exists) { + $detail[] = "订单 {$record['order_no']} 已存在于新表中,跳过"; + continue; + } + + // 插入到新表 + ProfitPay::insert([ + 'user_id' => $record['user_id'], + 'order_num' => $record['order_no'], + 'change_money' => $change_money, + 'content' => isset($content['attach']) ? $content['attach'] : '微信支付', + 'pay_type' => $record['channel'] == 2 ? 2 : 1, // 1微信 2支付宝 + 'addtime' => $record['addtime'], + ]); + + $success++; + } catch (\Exception $e) { + $failed++; + $detail[] = "处理订单 {$record['order_no']} 失败: " . $e->getMessage(); + } + } + + return [ + 'status' => 1, + 'message' => "迁移完成:共处理 {$total} 条记录,成功 {$success} 条,失败 {$failed} 条", + 'detail' => $detail + ]; + } catch (\Exception $e) { + return [ + 'status' => 0, + 'message' => "迁移过程发生错误: " . $e->getMessage() + ]; + } + } } \ No newline at end of file diff --git a/route/app.php b/route/app.php index 6a232c6..33ca415 100755 --- a/route/app.php +++ b/route/app.php @@ -30,4 +30,6 @@ Route::get('baji', function () { Route::get('baji1', function () { // return 'hello'; return view('baji'); -}); \ No newline at end of file +}); + + \ No newline at end of file