123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\admin\controller\client;
- use app\controller\Curd;
- use app\model\ClientFavorite;
- use app\model\ClientPoints;
- use support\Request;
- use support\Response;
- class PointsController extends Curd
- {
- public function __construct()
- {
- $this->model = new ClientPoints();
- }
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $order = $request->get('order', 'desc');
- $field = $field ?? 'client_points_addtimes';
- if (!empty($request->get('member_mobile'))) {
- $where['member.member_mobile'] = ['like', $request->get('member_mobile')];
- }
- if (!empty($request->get('order_id'))) {
- $where['order.order_id'] = ['like', $request->get('order_id')];
- }
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- protected function doSelect(array $where, string $field = null, string $order = 'desc')
- {
- $model = $this->model->leftJoin('member', 'member.member_id', '=', 'client_points.join_client_points_member_id')
- ->leftJoin('member_info', 'member_info.join_info_member_id', '=', 'client_points.join_client_points_member_id')
- ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'client_points.join_client_points_member_id')
- ->leftJoin('order', 'order.order_id', '=', 'client_points.join_client_points_order_id')
- ->select('member.member_id', 'member.member_mobile','member_info.member_info_nickname','member_cert.member_cert_name', 'order.order_id', 'order.order_name', 'client_points.*');
- foreach ($where as $column => $value) {
- if (is_array($value)) {
- if ($value[0] === 'like' || $value[0] === 'not like') {
- $model = $model->where($column, $value[0], "%$value[1]%");
- } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
- $model = $model->where($column, $value[0], $value[1]);
- } elseif ($value[0] == 'in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereIn($column, $valArr);
- } elseif ($value[0] == 'not in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereNotIn($column, $valArr);
- } elseif ($value[0] == 'null') {
- $model = $model->whereNull($column);
- } elseif ($value[0] == 'not null') {
- $model = $model->whereNotNull($column);
- } elseif ($value[0] !== '' || $value[1] !== '') {
- $model = $model->whereBetween($column, $value);
- }
- } else {
- $model = $model->where($column, $value);
- }
- }
- if ($field) {
- $model = $model->orderBy($field, $order);
- }
- return $model;
- }
- }
|