user_name; $mobile = $this->mobile; $start_time = $this->start_time; $end_time = $this->end_time; $status = $this->status; $query = StoreOperations::find()->alias('so') ->leftJoin(['su' => SaasUser::tableName()], 'su.id = so.saas_id') ->where(['su.is_delete' => 0, 'so.is_delete' => 0]); if ($user_name) { $query->andWhere(['LIKE', 'su.name', $user_name]); } if ($mobile) { $query->andWhere(['LIKE', 'su.mobile', $mobile]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'so.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'so.created_at', $end_time]); } if (isset($status) && $status >= 0) { $query->andWhere(['so.status' => $status]); } $query->select('so.id, su.name, su.mobile, su.avatar, so.status, so.created_at, so.remark')->orderBy('so.id desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['status'] = (int)$item['status']; if (!empty($item['created_at'])) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); } } return [ 'code' => 0, 'msg' => '获取成功', 'data' => $list ]; } public function save() { try { $status = $this->status; $saas_id = $this->saas_id; $remark = $this->remark; $saas_user = SaasUser::findOne($saas_id); if (!$saas_user) { throw new \Exception('联盟用户查询失败'); } $storeOperations = StoreOperations::findOne(['saas_id' => $saas_id, 'is_delete' => 0]); if ($storeOperations) { throw new \Exception('运营人员已存在'); } $storeOperations = new StoreOperations(); $storeOperations->saas_id = $saas_id; $storeOperations->remark = $remark; $storeOperations->status = $status; if (!$storeOperations->save()) { throw new \Exception(json_encode($storeOperations->errors, JSON_UNESCAPED_UNICODE)); } return [ 'code' => 0, 'msg' => '添加成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function setStatus() { try { $id = explode(',', $this->id); $status = $this->status; if (empty($id)) { throw new \Exception('参数错误'); } //修改状态 if (in_array($status, [0, 1])) { StoreOperations::updateAll(['status' => $status], ['id' => $id]); } else { //删除 StoreOperations::updateAll(['is_delete' => 1], ['id' => $id]); } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }