type; $mobile = $this->mobile; $status = $this->status; $store_id = $this->store_id; $start_time = $this->start_time; $end_time = $this->end_time; $user_name = $this->user_name; $query = IntegralAppreciationCommunity::find()->alias('c') ->leftJoin(['u' => User::tableName()], 'c.user_id = u.id') ->where(['c.store_id' => $store_id, 'c.is_delete' => 0]); if ($mobile) { $query->andWhere(['LIKE', 'c.mobile', $mobile]); } if ($user_name) { $query->andWhere(['LIKE', 'u.nickname', $user_name]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'c.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'c.created_at', $end_time]); } if (isset($type) && in_array($type, [IntegralAppreciationCommunity::TYPE_BUY, IntegralAppreciationCommunity::TYPE_SELL])) { $query->andWhere(['c.type' => $type]); } if (isset($status) && in_array($status, [IntegralAppreciationCommunity::STATUS_NO_APPLY, IntegralAppreciationCommunity::STATUS_APPLY, IntegralAppreciationCommunity::STATUS_REFUSE])) { $query->andWhere(['c.status' => $status]); } $query->orderBy('c.id DESC')->select('c.id, c.type, c.integral, c.mobile, c.created_at, u.nickname, u.avatar_url avatar, u.binding user_mobile, c.status'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['type'] = intval($item['type']); $item['status'] = intval($item['status']); $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['type_text'] = IntegralAppreciationCommunity::$typeArray[$item['type']]; $item['status_text'] = IntegralAppreciationCommunity::$statusArray[$item['status']]; } return [ 'code' => 0, 'msg' => 'success', 'data' => $pagination ]; } public function setStatus() { try { $ids = $this->ids; $status = $this->status; $ids = explode(',', $ids); if (!$ids) { throw new \Exception('请选择要删除的项'); } if (!in_array($status, [IntegralAppreciationCommunity::STATUS_APPLY, IntegralAppreciationCommunity::STATUS_REFUSE])) { throw new \Exception('状态错误'); } foreach ($ids as $id) { $community = IntegralAppreciationCommunity::findOne($id); if (intval($community->status) !== IntegralAppreciationCommunity::STATUS_NO_APPLY) { throw new \Exception('状态已经被修改'); } $community->status = $status; if (!$community->save()) { throw new \Exception(implode(',', $community->getFirstErrors())); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function del() { try { $ids = $this->ids; $ids = explode(',', $ids); if (!$ids) { throw new \Exception('请选择要删除的项'); } foreach ($ids as $id) { $goods = IntegralAppreciationCommunity::findOne($id); $goods->is_delete = 1; if (!$goods->save()) { throw new \Exception(implode(',', $goods->getFirstErrors())); } } return [ 'code' => 0, 'msg' => '删除成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }