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 @@
UID:{$vo['user_id']}
+UID:{$vo['uid'] ? $vo['uid'] : $vo['user_id']}
{$vo['mobile']}
{$vo['nickname']}