'商城ID', 'mobile' => '订单编号', 'user_name' => '用户名称', 'order_no' => '订单编号', 'start_time' => '', 'end_time' => '', ]; } /** * 列表 */ public function getIntegralList() { $store_id = $this->store_id; $mobile = $this->mobile; $start_time = $this->start_time; $end_time = $this->end_time; $user_name = $this->user_name; $query = IntegralAppreciationUser::find()->alias('iu') ->leftJoin(['u' => User::tableName()], 'iu.user_id = u.id') ->where(['iu.store_id' => $store_id]); if ($mobile) { $query->andWhere(['like', 'u.binding', $mobile]); } if ($user_name) { $query->andWhere(['like', 'u.nickname', $user_name]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'iu.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'iu.created_at', $end_time]); } $query->orderBy('iu.id DESC') ->select('iu.id, iu.integral total_integral, u.binding mobile, u.avatar_url avatar, u.nickname, iu.created_at'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); } return [ 'code' => 0, 'msg' => '', 'data' => $list ]; } /** * 积分明细 */ public function getIntegralDetail() { $id = $this->id; $type = $this->type; $query = IntegralAppreciationUserIntegralLog::find()->where(['integral_user_id' => $id]); if (isset($type) && in_array($type, [IntegralAppreciationUserIntegralLog::TYPE_INCOME, IntegralAppreciationUserIntegralLog::TYPE_EXPEND])) { $query->andWhere(['type' => $type]); } $start_time = $this->start_time; $end_time = $this->end_time; if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'created_at', $end_time]); } $query->orderBy('id desc')->select('id, amount, type, source_type, desc, created_at'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['type'] = intval($item['type']); $item['source_type'] = intval($item['source_type']); $item['source_type_text'] = IntegralAppreciationUserIntegralLog::$source_type_desc[$item['source_type']]; } return [ 'code' => 0, 'msg' => '', 'data' => $list ]; } public function getAmountList() { $store_id = $this->store_id; $mobile = $this->mobile; $order_no = $this->order_no; $start_time = $this->start_time; $end_time = $this->end_time; $user_name = $this->user_name; $query = IntegralAppreciationPoolSub::find()->alias('ps') ->leftJoin(['u' => User::tableName()], 'ps.user_id = u.id') ->leftJoin(['o' => Order::tableName()], 'ps.order_id = o.id AND ps.reflux_type = ' . IntegralAppreciationPoolSub::REFLUX_TYPE_ORDER) ->where(['ps.store_id' => $store_id]); // ->andWhere(['>', 'ps.amount', '0']); if ($mobile) { $query->andWhere(['like', 'u.binding', $mobile]); } if ($user_name) { $query->andWhere(['like', 'u.nickname', $user_name]); } if ($order_no) { $query->andWhere(['like', 'o.order_no', $order_no]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'ps.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'ps.created_at', $end_time]); } $query->orderBy('ps.id DESC') ->select('ps.id, ps.amount, ps.order_id, o.order_no, ps.reflux_type, ps.created_at, u.binding mobile, u.avatar_url avatar, u.nickname, o.order_no'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['reflux_type'] = intval($item['reflux_type']); if ($item['reflux_type'] === IntegralAppreciationPoolSub::REFLUX_TYPE_WITHDRAW) { $item['order_no'] = $item['order_id']; } $item['reflux_type_text'] = IntegralAppreciationPoolSub::$reflux_type_text[$item['reflux_type']]; } return [ 'code' => 0, 'msg' => '', 'data' => $list ]; } public function totalAmount() { $store_id = $this->store_id; $pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]); // $total_integral = IntegralAppreciationUser::find()->where(['store_id' => $store_id])->sum('integral') ?: 0; return [ 'code' => 0, 'msg' => '', 'data' => [ 'amount' => $pool->amount ?? '0.00', 'total_integral' => $pool->total_integral ?? '0.00', 'integral_price' => $pool->integral_price ?? '0.00', ] ]; } }