request->param(); // 构建查询条件 $where = []; if (!empty($param['user_id'])) { $user_id = $this->convertUidToUserId($param['user_id']); $where[] = ['id', '=', intval($user_id)]; } if (!empty($param['mobile'])) { $where[] = ['mobile', 'like', "%{$param['mobile']}%"]; } if (!empty($param['nickname'])) { $where[] = ['nickname', 'like', "%{$param['nickname']}%"]; } if (!empty($param['last_login_ip'])) { $where[] = ['last_login_ip', '=', $param['last_login_ip']]; } if (!empty($param['addtime'])) { $times = explode(' - ', $param['addtime']); $where[] = ['addtime', 'between', [strtotime($times[0]), strtotime($times[1])]]; } if (!empty($param['pid'])) { $where[] = ['pid', '=', intval($param['pid'])]; } $field = '*'; $order = 'id desc'; $data = UserModel::getList($where, $field, $order, $this->page); foreach ($data['list'] as &$value) { $pid_info = UserModel::field('id,nickname,headimg,uid')->where(['id' => $value['pid']])->find(); $value['pid_info'] = $pid_info; #关联user_account $user_account = UserAccount::where(['user_id' => $value['id']])->field('last_login_ip1,last_login_ip,ip_adcode,ip_province,ip_city')->find(); // SELECT sum(goodslist_money) FROM order_list where user_id=4490 and status=0 $user_hegui = OrderList::where('user_id', '=', $value['id'])->where('status', '=', 0)->sum('goodslist_money'); //SELECT SUM(order_zhe_total) FROM `order` where `status`=1 and user_id=6153 $user_all_total = Order::where('user_id', '=', $value['id'])->where('status', '=', 1)->sum('order_zhe_total'); //SELECT *FROM `order` where `status`=1 and user_id=6153 and price>1 #微信支付 $user_weixin_total = Order::where('user_id', '=', $value['id'])->where('status', '=', 1)->where('price', '>', 1)->sum('price'); // SELECT sum(use_money) FROM `order` where `status`=1 and user_id=6153 # 余额支付 $user_use_money = Order::where('user_id', '=', $value['id'])->where('status', '=', 1)->sum('use_money'); //SELECT sum(use_integral) FROM `order` where `status`=1 and user_id=6153 #吧唧币抵扣 $user_use_integral = Order::where('user_id', '=', $value['id'])->where('status', '=', 1)->sum('use_integral'); // SELECT sum(goodslist_money) FROM `order_list` where `status`=1 and user_id=6153 # 回收货币 $user_goodslist_money = OrderList::where('user_id', '=', $value['id'])->where('status', '=', 1)->sum('goodslist_money'); // SELECT sum(goodslist_money) FROM `order_list` where `status`=2 and user_id=6153 # 发货价值 $user_goodslist_money2 = OrderList::where('user_id', '=', $value['id'])->where('status', '=', 2)->sum('goodslist_money'); //SELECT sum(goodslist_money) FROM order_list where user_id=4490 # 总出货价值 $user_goodslist_money3 = OrderList::where('user_id', '=', $value['id'])->sum('goodslist_money'); $last_login_ip = 0; if ($user_account) { if ($user_account['last_login_ip']) { if ($user_account['last_login_ip1']) { $last_login_ip = $user_account['last_login_ip1']; } else { $last_login_ip = long2ip($user_account['last_login_ip']); } } } if (empty($value['mobile'])) { $value['mobile'] = '未绑定'; } $value['user_hegui'] = $user_hegui; $value['user_all_total'] = $user_all_total; $value['user_weixin_total'] = $user_weixin_total; $value['user_use_money'] = $user_use_money; $value['user_use_integral'] = $user_use_integral; $value['user_goodslist_money'] = $user_goodslist_money; $value['user_goodslist_money2'] = $user_goodslist_money2; $value['user_goodslist_money3'] = $user_goodslist_money3; $value['last_login_ip'] = $last_login_ip; $value['ip_adcode'] = $user_account['ip_adcode']; $value['ip_province'] = $user_account['ip_province']; $value['ip_city'] = $user_account['ip_city']; } // 获取数据 $list = $data['list']; $count = $data['count']; return json([ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list ]); } /** * 资金变动 */ public function chongzhi() { $id = request()->param('id', ''); $type = request()->param('type', ''); $user_info = UserModel::find($id); if (!$user_info) { $this->renderError('请求参数错误'); } if (\request()->IsGet()) { if ($type == 1) { $money = $user_info['money']; } elseif ($type == 2) { $money = $user_info['integral']; } elseif ($type == 3) { $money = $user_info['score']; } else { $this->renderError('请求参数错误1'); } View::assign('id', $id); View::assign('type', $type); View::assign('money', $money); return View::fetch('User/chongzhi'); } else { $money = request()->param('money', ''); $type_is = request()->param('type_is', ''); if ($type_is != 1 && $type_is != 2) { $this->renderError('请求参数错误1'); } if (empty($money)) { return $this->renderError('请输入修改数量'); } Db::startTrans(); if ($type == 1) {#余额 if (RegMoney($money)) { return $this->renderError('修改数量不规范,最多保留两位小数'); } if ($type_is == 2) { if ($money > $user_info['money']) { return $this->renderError('账号余额扣除数量不足'); } $money = $money * -1; } $res[] = UserModel::changeMoney($id, $money, 1, '后台变动'); } elseif ($type == 2) {#吧唧币 if (RegInt($money)) { return $this->renderError('修改数量不规范,请输入大于0的整数'); } if ($type_is == 2) { if ($money > $user_info['integral']) { return $this->renderError('账号吧唧币扣除数量不足'); } $money = $money * -1; } $res[] = UserModel::changeIntegral($id, $money, 1, '后台变动'); } elseif ($type == 3) {#积分 if (RegInt($money)) { return $this->renderError('修改数量不规范,请输入大于0的整数'); } if ($type_is == 2) { if ($money > $user_info['score']) { return $this->renderError('账号积分扣除数量不足'); } $money = $money * -1; } $res[] = UserModel::changeScore($id, $money, 1, '后台变动'); } else { $this->renderError('请求参数错误2'); } if (resCheck($res)) { Db::commit(); return $this->renderSuccess("操作成功"); } else { Db::rollback(); return $this->renderError("操作失败"); } } } /** * 封号、解封处理 */ public function userdel(Request $request) { $id = request()->post('id/d', 0); $type = request()->post('type/d', 0); if ($type != 1 && $type != 2) { return $this->renderError('请求参数错误'); } $user = UserModel::getInfo(['id' => $id]); if (!$user) { return $this->err('数据不存在'); } $result = $user->save(["status" => $type]); if ($result) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /** * 封号、解封处理 */ public function usertest(Request $request) { // \think\facade\Filesystem::disk('public')-/ $id = request()->post('id/d', 0); $type = request()->post('type/d', 0); if ($type != 1 && $type != 0 && $type != 2) { return $this->renderError('请求参数错误'); } $user = UserModel::getInfo(['id' => $id]); if (!$user) { return $this->err('数据不存在'); } $result = $user->save(["istest" => $type]); if ($result) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /** * 清空手机号 */ public function usermobileclear(Request $request) { $id = request()->post('id/d', 0); $user = UserModel::getInfo(['id' => $id]); if (!$user) { return $this->err('数据不存在'); } $result = $user->save(["mobile" => '']); if ($result) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /** * 清空UID */ public function userUidClear(Request $request) { $id = request()->post('id/d', 0); $user = UserModel::getInfo(['id' => $id]); if (!$user) { return $this->err('数据不存在'); } $result = $user->save(["uid" => '']); if ($result) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /** * 清空微信登录数据 */ public function userwxclear(Request $request) { $id = request()->post('id/d', 0); $user = UserModel::getInfo(['id' => $id]); if (!$user) { return $this->err('数据不存在'); } $result = $user->save(["openid" => Str::random(32)]); $useraccount = UserAccount::getInfo(['user_id' => $id]); if ($useraccount != null) { $useraccount->save(['account_token' => '']); } if ($result) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /* ip转换 */ public function ipzh(Request $request) { $id = request()->post('id/d', 0); $user_account = UserAccount::where(['user_id' => $id])->field('last_login_ip1,ip_province,last_login_ip')->find(); if ($user_account) { if (empty($user_account['ip_province'])) { $last_login_ip = long2ip($user_account['last_login_ip']); //$last_login_ip = $user_account['last_login_ip1']; var_dump($last_login_ip); $url = "https://restapi.amap.com/v3/ip?key=6a46ad822120e393956e89d498e8c40b&ip=" . "$last_login_ip" . ""; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); $result = json_decode($result, true); var_dump($result); exit; if ($result['status'] == '1') { $res = UserAccount::where(['user_id' => $id])->update([ 'ip_adcode' => $result['adcode'], 'ip_province' => $result['province'], 'ip_city' => $result['city'] ]); } else { $res = false; } } } else { $res = false; } if ($res) { return $this->renderSuccess('操作成功'); } else { return $this->renderError('操作失败'); } } /** * 赠送卡牌查找 */ public function give_goodslist_info() { $card_no = request()->param('card_no', ''); $goodslist = GoodsList::where('card_no', '=', $card_no) ->find(); if (!$goodslist) { return $this->renderError('输入错误,未找到奖品信息'); } #验证是否赠送是卡册盒子 $good_info = Goods::field('id,type')->where('id', '=', $goodslist['goods_id'])->find(); if ($good_info['type'] != 4) { return $this->renderError('只可赠送卡册盒子'); } $data = [ 'title' => $goodslist['title'], 'imgurl' => imageUrl($goodslist['imgurl']), ]; return $this->renderSuccess('查找成功', $data); } /** * 赠送卡牌 */ public function give_goodslist() { $user_id = request()->param('id/d', 0); $user_info = UserModel::find($user_id); if (!$user_info) { $this->renderError('请求参数错误'); } if (request()->IsGet()) { View::assign('id', $user_id); return View::fetch('User/give_goodslist'); } else { $card_no = request()->param('card_no', ''); $num = request()->param('num/d', 0); $goodslist = GoodsList::where('card_no', '=', $card_no) ->find(); if (!$goodslist) { return $this->renderError('输入错误,未找到奖品信息'); } if (RegInt($num)) { return $this->renderError('数量输入错误,请输入大于0的整数'); } #验证是否赠送是卡册盒子 $good_info = Goods::field('id,type')->where('id', '=', $goodslist['goods_id'])->find(); if ($good_info['type'] != 4) { return $this->renderError('只可赠送卡册盒子'); } $save_prize = [ 'order_id' => 0, 'user_id' => $user_id, 'status' => 0,#0未操作 1选择兑换 2选择发货 'goods_id' => $goodslist['goods_id'], 'num' => 0, 'shang_id' => $goodslist['shang_id'], 'goodslist_id' => $goodslist['id'], 'goodslist_title' => $goodslist['title'], 'goodslist_imgurl' => $goodslist['imgurl'], 'goodslist_price' => $goodslist['price'], 'goodslist_money' => $goodslist['money'], 'goodslist_type' => $goodslist['goods_type'], 'goodslist_sale_time' => $goodslist['sale_time'], 'addtime' => time(), 'prize_code' => $goodslist['prize_code'], 'order_type' => 9, ]; $all_save_prize = []; for ($i = 0; $i < $num; $i++) { $all_save_prize[] = $save_prize; } $res = OrderList::insertAll($all_save_prize); if ($res) { return $this->renderSuccess("操作成功"); } else { return $this->renderError("操作失败"); } } } /** * 赠送 */ public function give_add(Request $request) { if (!$request->isPost()) { $w = []; $w[] = ['status', '=', 0]; $coupon = Coupon::getAllList($w, 'id,title,price,man_price,ttype'); View::assign('coupon', $coupon); $user_id = $request->param("user_id"); View::assign("user_id", $user_id); return View::fetch("User/give_add"); } else { $data = input('post.'); if (empty($data['give_id'])) { return $this->renderError("请选择赠送的物品"); } $coupon = Coupon::getInfo(['id' => $data['give_id']]); if (!$coupon || $coupon['status'] != 0) { return $this->renderError("优惠券不存在或者已下架"); } //赠送优惠卷 $data2 = []; for ($i = 0; $i < $data['num']; $i++) { $data2[$i]['title'] = $coupon['title']; $data2[$i]['price'] = $coupon['price']; $data2[$i]['man_price'] = $coupon['man_price']; $data2[$i]['end_time'] = $coupon['effective_day'] * 86400 + time(); $data2[$i]['addtime'] = time(); $data2[$i]['status'] = 0; $data2[$i]['user_id'] = $data['user_id']; $data2[$i]['coupon_id'] = $data['give_id']; $data2[$i]['state'] = $coupon['ttype']; } $dd = Db::name('coupon_receive')->insertAll($data2); if ($dd) { return $this->renderSuccess("赠送成功"); } else { return $this->renderError("赠送失败"); } } } /** * 用户盈亏 */ public function user_profit_loss() { $whe = []; $where = []; $addtime = trim(input('get.addtime')); $uid = trim(input('get.uid')); if (!empty($uid)) { $user_id = $this->convertUidToUserId($uid); $whe[] = ['id', '=', $user_id]; } if (!empty($addtime)) { $addtime = explode(' - ', $addtime); $start_time = strtotime($addtime[0]); $end_time = strtotime($addtime[1]) - 1; $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; } // else { // $start_time = strtotime(date('Y-m-d', time())); // $end_time = $start_time + 86399; // $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; // } $data = UserModel::getList($whe, 'id,nickname,headimg,money,uid', 'id desc', 20); $cz_money_total = 0; $wx_money_total = 0; $cz_yue_total = 0; $cz_integral_total = 0; $price_total = 0; $shang_money_total = 0; $fh_money_total = 0; $tx_money_total = 0; $profit_loss_total = 0; $money = 0; foreach ($data['list'] as $k => &$v) { #公式 (充值余额 + 吧唧币 + 微信支付 - 余额 - 背包赏品 $cz_money = ProfitMoney::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 1)->where('change_money', '>', 0)->where($where)->sum('change_money'); $wx_money = ProfitMoney::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 2)->where('change_money', '>', 0)->where($where)->sum('change_money'); $cz_yue = $cz_money + $wx_money; $cz_integral = ProfitIntegral::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 1)->where('change_money', '>', 0)->where($where)->sum('change_money'); $price = Order::field('price')->where('user_id', '=', $v['id'])->where('status', '=', 1)->where('price', '>', 0)->where($where)->sum('price'); $shang_money = OrderList::field('goodslist_money')->where('user_id', '=', $v['id'])->whereIn('status', [0])->where('goodslist_money', '>', 0)->where($where)->sum('goodslist_money'); $fh_money = OrderList::field('goodslist_money')->where('user_id', '=', $v['id'])->where('status', '=', 2)->where('goodslist_money', '>', 0)->where($where)->sum('goodslist_money'); $tx_money = ProfitMoney2::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 5)->where('change_money', '<', 0)->where($where)->sum('change_money'); $profit_loss = $cz_yue + $price - $v['money'] - $shang_money - $fh_money; $profit_loss = $profit_loss + $tx_money; $v['cz_money'] = $cz_yue; $v['wx_money'] = $wx_money; $v['cz_integral'] = $cz_integral; $v['price'] = $price; $v['shang_money'] = $shang_money; $v['fh_money'] = $fh_money; $v['tx_money'] = $tx_money; $v['profit_loss'] = $profit_loss; $cz_money_total += $cz_yue; $wx_money_total += $wx_money; $cz_yue_total += $cz_yue; $cz_integral_total += $cz_integral; $price_total += $price; $shang_money_total += $shang_money; $fh_money_total += $fh_money; $tx_money_total += $tx_money; $profit_loss_total += $profit_loss; $money += $v['money']; } $total_money[1]['cz_money_total'] = $cz_money_total; $total_money[1]['cz_integral_total'] = $cz_integral_total; // $total_money[1]['wx_money_total'] = $wx_money_total; $total_money[1]['price_total'] = $price_total; $total_money[1]['total_money'] = $money; // $total_money[1]['cz_yue_total'] = $cz_yue_total; $total_money[1]['shang_money_total'] = $shang_money_total; $total_money[1]['fh_money_total'] = $fh_money_total; $total_money[1]['tx_money_total'] = $tx_money_total; $total_money[1]['profit_loss_total'] = $profit_loss_total; View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); View::assign('total_money', $total_money); return View::fetch("User/user_profit_loss"); } /** * vip管理 */ public function vip() { $list = UserVip::order('id asc')->select(); View::assign('list', $list); View::assign('count', count($list)); return View::fetch("User/vip"); } /** * vip编辑 */ public function vip_edit(Request $request) { if (!$request->isPost()) { $id = request()->param('id/d', 0); $info = UserVip::where(['id' => $id])->find(); if (!$info) { return $this->renderError('请求参数错误'); } View::assign('info', $info); return View::fetch('User/vip_edit'); } else { $data = input('post.'); if (empty($data['id'])) { return $this->renderError('请求参数错误'); } $info = UserVip::where(['id' => $data['id']])->find(); if (!$info) { return $this->renderError('请求参数错误1'); } if (empty($data['title'])) { return $this->renderError('请输入vip名称'); } if (RegZero($data['condition'])) { return $this->renderError('升级消费设置错误,请设置整数'); } if (RegMoney($data['discount'])) { return $this->renderError('vip折扣设置错误,最多保留两位小数'); } // if (empty($data['imgurl'])) { // return $this->renderError('请上传图标'); // } $data['update_time'] = time(); unset($data['id']); $dd = $info->allowField([])->save($data); if ($dd) { return $this->renderSuccess('编辑成功'); } else { return $this->renderError('编辑失败'); } } } /** * 流水明细 *created by Admin at 2023/2/10 14:23 */ public function detailed_flow() { $whe = []; $where = []; // $addtime = trim(input('get.addtime')); $uid = trim(input('get.uid')); if (!empty($uid)) { // 将UID转换为用户ID $uid = $this->convertUidToUserId($uid); $whe[] = ['user_id', '=', $uid]; } // if (!empty($addtime)) { // $addtime = explode(' - ', $addtime); // $start_time = strtotime($addtime[0]); // $end_time = strtotime($addtime[1]) - 1; // $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; // } else { // $start_time = strtotime(date('Y-m-d', time())); // $end_time = $start_time + 86399; // $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; // } // $data = ProfitMoney::getList($whe, 'id,user_id,change_money,addtime', '', 20); $list = ProfitMoney::field('user_id,sum(change_money) as new_money') // ->whereIn('type',[]) ->group('user_id') ->order('new_money desc') ->paginate(20); $page = $list->render(); $data['list'] = $list->toArray()['data']; $data['count'] = $list->total(); $data['page'] = $page; $num = 1; foreach ($data['list'] as &$value) { // dd($value['user_id']); $user = \app\common\model\User::where('id', $value['user_id'])->find(); $value['nick_name'] = $user['nickname']; $value['headimg'] = $user['headimg']; $value['openid'] = $user['openid']; $value['uid'] = $user['uid'] ?: $user['id']; $value['num'] = $num; // $value['addtime'] =$user['addtime']; $num++; } // dd($data); View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); return View::fetch("User/detailed_flow"); } /** * 下级用户 *created by Admin at 2023/2/16 15:55 */ public function user_team(Request $request) { $id = $request->param('id'); // 将UID转换为用户ID $id = $this->convertUidToUserId($id); // dd($id); $list = \app\common\model\User::where('pid', $id)->paginate(20); $page = $list->render(); $data['list'] = $list->toArray()['data']; $data['count'] = $list->total(); $data['page'] = $page; foreach ($data['list'] as &$value) { $value['total'] = ProfitMoney::where('type', 5) ->where('user_id', $id) ->where('share_uid', $value['id']) ->sum('change_money'); // dd(); } // dd($data['list']); View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); return View::fetch("User/user_team"); } public function ip_list(Request $request) { $id = $request->param('id'); // 将UID转换为用户ID $id = $this->convertUidToUserId($id); // dd($id); $list = UserLoginIp::where('user_id', $id)->order('id desc')->paginate(20); $page = $list->render(); $data['list'] = $list->toArray()['data']; $data['count'] = $list->total(); $data['page'] = $page; // 获取用户UID $user = UserModel::where('id', $id)->find(); $uid = $user ? $user['uid'] : ''; foreach ($data['list'] as &$item) { $item['uid'] = $uid ?: $item['user_id']; } View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); return View::fetch("User/ip_list"); } public function user_invite(Request $request) { $whe = array(); $whe1 = array(); $user_id = trim(input('get.user_id')); if (!empty($user_id)) { // 将UID转换为用户ID $user_id = $this->convertUidToUserId($user_id); $whe[] = ['pid', '=', $user_id]; } $profit_date = trim(input('get.profit_date')); if (!empty($profit_date)) { $profit_date = explode(' - ', $profit_date); $start_time = strtotime($profit_date[0]); $end_time = strtotime($profit_date[1]); $whe1[] = ['addtime', 'BETWEEN', [intval($start_time), intval($end_time)]]; } //select * from ( SELECT pid,count(1) n FROM xinglanmh_shequt_test.`user` where pid>0 group by pid ) t where n>1 order by n desc LIMIT 10 $list = UserModel::where($whe)-> where('pid', '>', 0) ->field('pid, COUNT(1) as n') // 选取 pid 和 计数字段 ->group('pid') // ->having('n', '>', 1) // `having` 需要使用 `as` 取别名 ->order('n desc') ->limit(1000) // 添加限制条数 ->select(); $count = UserModel::where($whe)->where('pid', '>', 0) ->field('pid, COUNT(1) as n') // 选取 pid 和 计数字段 ->group('pid') ->count(); $data = array(); $index = 1; foreach ($list as $item) { $pid = $item['pid']; $user_info = UserModel::field('nickname,headimg,mobile,uid')->where('id', '=', $pid)->find(); if ($user_info != null) { $user_list = UserModel::field('id,nickname,addtime,mobile,uid')->where($whe1)->where('pid', '=', $pid)->order('addtime desc')->select(); $u_index = 1; $u_price = 0; $u_order = 0; $u_mobile_count = 0; foreach ($user_list as $user_item) { $user_item['adddate'] = date('Y-m-d H:i:s', $user_item['addtime']); $user_item['index'] = $u_index; $user_item_order = Order::where('user_id', '=', $user_item['id'])->where('status', '=', $user_item['id'])->count(); $user_item_price = Order::where('user_id', '=', $user_item['id'])->where('status', '=', $user_item['id'])->sum('price'); $user_item['user_item_order'] = $user_item_order; $user_item['user_item_price'] = $user_item_price; $u_index++; $u_price += $user_item_price; if ($user_item_order && $user_item_order > 0) { $u_order++; } if ($user_item['mobile'] && $user_item['mobile'] != "") { $u_mobile_count++; } } $data[] = [ 'index' => $index, 'user_id' => $pid, 'uid' => $user_info['uid'] ?: $pid, 'invitenumber' => $item['n'], 'nickname' => $user_info['nickname'], 'headimg' => imageUrl($user_info['headimg']), 'info' => $user_list, 'sum_order' => $u_order, 'sum_price' => $u_price, 'count_mobile' => $u_mobile_count, ]; $index++; } } View::assign('data', $data); View::assign('count', $count); return View::fetch("User/user_invite"); } /** * //用户列表页面表格操作一列增加查询用户盒柜,传入用户的id,点击显示一个弹出层,弹出层中有一个表格,这个弹出层有有查询条件(奖品状态(下拉框),奖品名称(输入框),盒子名称(输入框)),下面的sql语句是查询盒柜列表 * goodslist_title 奖品名称,goodslist_money 回收价格,goodslist_price 售价,shang_id 奖品等级,order_id 订单id,order_num 订单编号,goods_id 盒子id,good_title 盒子名称,status奖品状态 0盒柜中 1回收 2选择发货 *SELECT goodslist_title,goodslist_money, goodslist_price,goodslist_imgurl,shang_id,addtime,order_id,(select order_num from `order` where id=order_list.order_id) order_num,goods_id,(select title from goods where id=order_list.goods_id ) good_title,`status` FROM order_list where user_id=6153 order by`status` * 获取用户盒柜列表 */ public function user_box_list() { $param = $this->request->param(); $user_id = isset($param['user_id']) ? intval($param['user_id']) : 0; // 将UID转换为用户ID $user_id = $this->convertUidToUserId($user_id); if(empty($user_id)) { return json(['code' => 1, 'msg' => '参数错误', 'count' => 0, 'data' => []]); } $where = [['user_id', '=', $user_id]]; // 添加筛选条件 if (!empty($param['status'])) { $where[] = ['status', '=', $param['status']]; } if (!empty($param['goodslist_title'])) { $where[] = ['goodslist_title', 'like', "%{$param['goodslist_title']}%"]; } if (!empty($param['good_title'])) { // 通过goods表查询包含该名称的盒子ID $goods_ids = Db::name('goods')->where('title', 'like', "%{$param['good_title']}%")->column('id'); if (!empty($goods_ids)) { $where[] = ['goods_id', 'in', $goods_ids]; } else { // 如果没有找到匹配的盒子,返回空结果 return json(['code' => 0, 'msg' => '未找到匹配的盒子', 'count' => 0, 'data' => []]); } } // 添加获取时间查询条件 if (!empty($param['addtime'])) { $times = explode(' - ', $param['addtime']); $where[] = ['addtime', 'between', [strtotime($times[0]), strtotime($times[1])]]; } // 构建查询 - 添加了shang_title字段和发货状态字段 $query = Db::name('order_list') ->where($where) ->field('goodslist_title, goodslist_money, goodslist_price, goodslist_imgurl, shang_id, addtime, order_id, goods_id, status, fh_status, fh_remarks'); // 获取总数 $count = $query->count(); // 分页查询 $page = isset($param['page']) ? intval($param['page']) : 1; $limit = isset($param['limit']) ? intval($param['limit']) : 20; $list = $query->page($page, $limit) ->order('status, addtime desc') ->select() ->toArray(); // 处理订单编号、盒子名称和奖品类型 foreach ($list as &$item) { // 获取订单编号 $order = Db::name('order')->where('id', $item['order_id'])->value('order_num'); $item['order_num'] = $order ?: '无订单号'; // 获取盒子名称 $good = Db::name('goods')->where('id', $item['goods_id'])->value('title'); $item['good_title'] = $good ?: '未知盒子'; // 获取奖品类型名称 $shang = Db::name('shang')->where('id', $item['shang_id'])->value('title'); $item['shang_title'] = $shang ?: '未知类型'; // 处理发货状态,确保数据存在 if ($item['status'] == 2) { $item['fh_status'] = isset($item['fh_status']) ? intval($item['fh_status']) : 0; } else { $item['fh_status'] = null; $item['fh_remarks'] = null; } } return json([ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list ]); } /** * 用户盒柜页面 */ public function user_box() { $user_id = request()->param('id', 0); $nickname = request()->param('nickname', ''); // 将UID转换为用户ID $user_id = $this->convertUidToUserId($user_id); // 验证参数 if (empty($user_id)) { $this->renderError('参数错误'); } // 传递用户ID和昵称到模板 View::assign('user_id', $user_id); View::assign('nickname', $nickname); return View::fetch('User/user_box'); } /** * 用户订单页面 */ public function user_order() { $user_id = request()->param('id', 0); $nickname = request()->param('nickname', ''); // 将UID转换为用户ID $user_id = $this->convertUidToUserId($user_id); // 验证参数 if (empty($user_id)) { $this->renderError('参数错误'); } // 传递用户ID和昵称到模板 View::assign('user_id', $user_id); View::assign('nickname', $nickname); return View::fetch('User/user_order'); } /** * 获取用户订单列表 */ public function user_order_list() { $param = $this->request->param(); $user_id = isset($param['user_id']) ? intval($param['user_id']) : 0; // 将UID转换为用户ID $user_id = $this->convertUidToUserId($user_id); if(empty($user_id)) { return json(['code' => 1, 'msg' => '参数错误', 'count' => 0, 'data' => []]); } $where = [['user_id', '=', $user_id]]; // 添加筛选条件 if (isset($param['status']) && $param['status'] !== '') { $where[] = ['status', '=', $param['status']]; } if (!empty($param['goods_title'])) { $where[] = ['goods_title', 'like', "%{$param['goods_title']}%"]; } // 添加支付时间查询条件 if (!empty($param['pay_time'])) { $times = explode(' - ', $param['pay_time']); $where[] = ['pay_time', 'between', [strtotime($times[0]), strtotime($times[1])]]; } // 构建查询 $query = Db::name('order') ->where($where) ->field('id, order_num, order_total, order_zhe_total, price, use_money, use_integral, use_score, goods_id, goods_title, num, goods_price, addtime, pay_time, status'); // 获取总数 $count = $query->count(); // 分页查询 $page = isset($param['page']) ? intval($param['page']) : 1; $limit = isset($param['limit']) ? intval($param['limit']) : 20; $list = $query->page($page, $limit) ->order('id desc') ->select() ->toArray(); return json([ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list ]); } }