diff --git a/app/api/controller/User.php b/app/api/controller/User.php index afd73588..df62aed0 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -83,11 +83,15 @@ class User extends Controller $userInfo['freeze_money'] = !empty($dealer_info->freeze_money) ? $dealer_info->freeze_money : 0; } $retailOrderList = RetailOrderModel::getRetailOrder($userInfo['user_id']); - if(!empty($retailOrderList)){ + $userInfo['retail'] = []; + if (empty($retailOrderList)) { + // 如果零售订单列表为空,设置用户信息中的零售状态为 1 $userInfo['retail'] = 1; - }else{ + } else { + // 如果零售订单列表不为空,设置用户信息中的零售状态为 0 $userInfo['retail'] = 0; } + return $this->renderSuccess(compact('userInfo')); } diff --git a/app/api/model/Retail.php b/app/api/model/Retail.php index 613ef99f..d40cc021 100644 --- a/app/api/model/Retail.php +++ b/app/api/model/Retail.php @@ -53,6 +53,10 @@ class Retail extends RetailModel $this->client = $client; return $this; } + public function getList(array $where) + { + return $this->where($where)->order('sort', 'asc')->select(); + } /** * 返回消息提示 diff --git a/app/store/controller/Retail.php b/app/store/controller/Retail.php index d1466370..652e8756 100644 --- a/app/store/controller/Retail.php +++ b/app/store/controller/Retail.php @@ -12,8 +12,10 @@ declare (strict_types=1); namespace app\store\controller; +use app\api\model\user\RetailOrder; use think\response\Json; use app\store\model\Retail as RetailModel; +use app\store\model\RetailOrder as RetailOrderModel; use function Symfony\Component\VarDumper\Dumper\esc; @@ -94,6 +96,12 @@ class Retail extends Controller return $this->renderError('删除失败'); } + public function getRetailOrder(): Json{ + $model = new RetailOrderModel(); + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + diff --git a/app/store/model/RetailOrder.php b/app/store/model/RetailOrder.php new file mode 100644 index 00000000..c65ea63e --- /dev/null +++ b/app/store/model/RetailOrder.php @@ -0,0 +1,78 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\RetailOrder as RetailOrderModel; + +class RetailOrder extends RetailOrderModel +{ + /** + * 获取订单列表 + * @param array $param + * @return \think\Paginator + */ + public function getList(array $param = []): \think\Paginator + { + // 设置查询条件 + $filter = $this->getFilter($param); + + // 获取列表数据 + $list = $this->alias('order') + ->field('order.*') + ->where($filter) + ->join('user', 'user.user_id = order.user_id') + ->order(['order.create_time' => 'desc']) + ->paginate($param['pageSize'] ?? 15); + // var_dump($list); + // exit(); + //return $list; + // 加载订单的关联数据 + return static::preload($list, ['user.avatar']); + } + + /** + * 设置查询条件 + * @param array $param + * @return array + */ + private function getFilter(array $param): array + { + // 设置默认的检索数据 + $params = $this->setQueryDefaultValue($param, [ + 'user_id' => 0, // 用户ID + 'search' => '', // 查询内容 + 'order_type' => 0, // 充值方式 + 'pay_method' => "", // 充值方式 + 'pay_status' => 0, // 支付状态 + 'betweenTime' => [] // 起止时间 + ]); + // 检索查询条件 + $filter = []; + // 用户ID + $params['user_id'] > 0 && $filter[] = ['order.user_id', '=', $params['user_id']]; + // 用户昵称/订单号 + !empty($params['search']) && $filter[] = ['order.order_no|user.nick_name', 'like', "%{$params['search']}%"]; + !empty($params['pay_method']) && $filter[] = ['order.pay_method', '=', $params['pay_method']]; + // 充值方式 + $params['order_type'] > 0 && $filter[] = ['order.order_type', '=', (int)$params['order_type']]; + // 支付状态 + $params['pay_status'] > 0 && $filter[] = ['order.pay_status', '=', (int)$params['pay_status']]; + // 起止时间 + if (!empty($params['pay_time'])) { + $times = between_time($params['pay_time']); + $filter[] = ['order.pay_time', '>=', $times['start_time']]; + $filter[] = ['order.pay_time', '<', $times['end_time'] + 86400]; + } + return $filter; + } +} \ No newline at end of file